Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing status: "See notice at end of class" date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class SEQ_STRING create make feature {NONE} -- Initialization make (n: INTEGER) is -- Allocate space for at least n characters. -- (from STRING) require -- from STRING non_negative_size: n >= 0 do count := 0 if n = 0 then area := empty_area else make_area (n + 1) end ensure -- from STRING empty_string: count = 0 area_allocated: capacity >= n end make_area (n: INTEGER) is -- Creates a special object for n entries. -- (from TO_SPECIAL) require -- from TO_SPECIAL non_negative_argument: n >= 0 do create area.make (n) ensure -- from TO_SPECIAL area_allocated: area /= void and then area.count = n end feature -- Initialization adapt (s: STRING): like Current is -- Object of a type conforming to the type of s, -- initialized with attributes from s -- (from STRING) do create Result.make (0) Result.string_share (s) end from_c (c_string: POINTER) is -- Reset contents of string from contents of c_string, -- a string created by some external C function. -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer local length: INTEGER do length := str_len (c_string) if capacity < length then make_area (length + 1) end; ($area).memory_copy (c_string, length) count := length ensure -- from STRING no_zero_byte: not has ('%U') end from_c_substring (c_string: POINTER; start_pos, end_pos: INTEGER) is -- Reset contents of string from substring of c_string, -- a string created by some external C function. -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer start_position_big_enough: start_pos >= 1 end_position_big_enough: start_pos <= end_pos + 1 local length: INTEGER do length := end_pos - start_pos + 1 if capacity < length then make_area (length + 1) end; ($area).memory_copy (c_string + (start_pos - 1), (end_pos - start_pos + 1)) count := length ensure -- from STRING valid_count: count = end_pos - start_pos + 1 end make_from_c (c_string: POINTER) is -- Initialize from contents of c_string, -- a string created by some external C function -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer local length: INTEGER do length := str_len (c_string) make_area (length + 1); ($area).memory_copy (c_string, length) count := length end make_from_string (s: STRING) is -- Initialize from the characters of s. -- (Useful in proper descendants of class STRING, -- to initialize a string-like object from a manifest string.) -- (from STRING) require -- from STRING string_exists: s /= void do area := s.area count := s.count ensure -- from STRING shared_implementation: shared_with (s) end remake (n: INTEGER) is obsolete "Use `make' instead" -- Allocate space for at least n characters. -- (from STRING) require -- from STRING non_negative_size: n >= 0 do count := 0 make (n) ensure -- from STRING empty_string: count = 0 area_allocated: capacity >= n end feature -- Access area: SPECIAL [CHARACTER] -- Special data zone -- (from TO_SPECIAL) current_item: CHARACTER is -- Current item require -- from TRAVERSABLE not_off: not off require -- from ACTIVE readable: readable do Result := item (index) end False_constant: STRING is "false" -- Constant string "false" -- (from STRING) fuzzy_index (other: STRING; start: INTEGER; fuzz: INTEGER): INTEGER is -- Position of first occurrence of other at or after start -- with 0..fuzz mismatches between the string and other. -- 0 if there are no fuzzy matches -- (from STRING) require -- from STRING other_exists: other /= void other_not_empty: not other.is_empty start_large_enough: start >= 1 start_small_enough: start <= count acceptable_fuzzy: fuzz <= other.count local a: ANY do a := other.area Result := str_str ($area, $a, count, other.count, start, fuzz) end has (c: CHARACTER): BOOLEAN is -- Does string include c? do if not is_empty then Result := (index_of (c, 1) /= 0) end ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end hash_code: INTEGER is -- Hash code value -- (from STRING) do Result := hashcode ($area, count) ensure -- from HASHABLE good_hash_value: Result >= 0 end index: INTEGER -- Index of current_item, if valid -- Valid values are between 1 and count (if count > 0). index_of (c: CHARACTER; start: INTEGER): INTEGER is -- Position of first occurrence of c at or after start; -- 0 if none. -- (from STRING) require -- from STRING start_large_enough: start >= 1 start_small_enough: start <= count + 1 local a: like area i, nb: INTEGER do nb := count if start <= nb then from i := start - 1 nb := nb - 1 a := area until i > nb or else a.item (i) = c loop i := i + 1 end if i <= nb then Result := i + 1 end end ensure -- from STRING correct_place: Result > 0 implies item (Result) = c end index_of_occurrence (c: CHARACTER; i: INTEGER): INTEGER is -- Index of i-th occurrence of c. -- 0 if none. require -- from LINEAR positive_occurrences: i > 0 local occur: INTEGER do if not is_empty then from Result := index_of (c, 1) if Result /= 0 then occur := 1 end until (Result = 0) or else (occur = i) loop if Result /= count then Result := index_of (c, Result + 1) if Result /= 0 then occur := occur + 1 end else Result := 0 end end end ensure -- from LINEAR non_negative_result: Result >= 0 ensure then index_value: (Result = 0) or item (Result) = c end item (i: INTEGER): CHARACTER is -- Character at position i -- Was declared in STRING as synonym of @. -- (from STRING) require -- from TABLE valid_key: valid_index (k) do Result := area.item (i - 1) end item_code (i: INTEGER): INTEGER is -- Numeric code of character at position i -- (from STRING) require -- from STRING index_small_enough: i <= count index_large_enough: i > 0 do Result := area.item (i - 1).code end last_index_of (c: CHARACTER; start_index_from_end: INTEGER): INTEGER is -- Position of last occurence of c. -- 0 if none -- (from STRING) require -- from STRING start_index_small_enough: start_index_from_end <= count start_index_large_enough: start_index_from_end >= 1 local a: like area i: INTEGER do from i := start_index_from_end - 1 a := area until i < 0 or else a.item (i) = c loop i := i - 1 end if i >= 0 then Result := i + 1 end ensure -- from STRING correct_place: Result > 0 implies item (Result) = c end off: BOOLEAN is -- Is there no current item? -- (from BILINEAR) do Result := before or after end search_after (c: CHARACTER) is -- Move cursor to first position -- (at or after current cursor position) -- where current_item and c are identical. do if not off then index := index_of (c, index) if index = 0 then index := count + 1 end end end search_before (c: CHARACTER) is -- Move cursor to greatest position at or before cursor -- where current_item and c are identical; -- go before if unsuccessful. local str: like Current do str := mirrored if not str.off then index := count + 1 - str.index_of (c, str.index) if index = count + 1 then index := 0 end end end search_string_after (s: STRING; fuzzy: INTEGER) is -- Move cursor to first position -- (at or after cursor position) where `substring -- (index, index + s.count)' and s are identical. -- Go after if unsuccessful. -- The 'fuzzy' parameter is the maximum allowed number -- of mismatches within the pattern. A 0 means an exact match. local s_area: ANY do if not off then s_area := s.area index := str_str ($area, $s_area, count, s.count, index, fuzzy) if index = 0 then index := count + 1 end end end search_string_before (s: STRING; fuzzy: INTEGER) is -- Move cursor to first position -- (at or before cursor position) where `substring -- (index, index + s.count)' and s are identical. -- Go before if unsuccessful. -- The 'fuzzy' parameter is the maximum allowed number -- of mismatches within the pattern. A 0 means an exact match. local s_mir_area, mir_area: ANY str_mirrored: like Current s_mirrored: STRING do if not off then str_mirrored := mirrored s_mirrored := s.mirrored s_mir_area := s_mirrored.area mir_area := str_mirrored.area index := count - str_str ($mir_area, $s_mir_area, count, s.count, str_mirrored.index, fuzzy) + 1 if index = count + 1 then index := 0 else index := index - s.count + 1 end end end shared_with (other: like Current): BOOLEAN is -- Does string share the text of other? -- (from STRING) do Result := (other /= void) and then (area = other.area) end substring_index (other: STRING; start: INTEGER): INTEGER is -- Position of first occurrence of other at or after start; -- 0 if none. -- (from STRING) require -- from STRING other_nonvoid: other /= void other_notempty: not other.is_empty start_large_enough: start >= 1 start_small_enough: start <= count local a: ANY do a := other.area Result := str_str ($area, $a, count, other.count, start, 0) ensure -- from STRING correct_place: Result > 0 implies substring (Result, Result + other.count - 1).is_equal (other) end True_constant: STRING is "true" -- Constant string "true" -- (from STRING) infix "@" (i: INTEGER): CHARACTER is -- Character at position i -- Was declared in STRING as synonym of item. -- (from STRING) require -- from TABLE valid_key: valid_index (k) do Result := area.item (i - 1) end feature {NONE} -- Access sequential_search (v: like current_item) is -- Move to first position (at or after current -- position) where item and v are equal. -- (Reference or object equality, -- based on object_comparison.) -- If no such position ensure that exhausted will be true. -- (from LINEAR) do if object_comparison and v /= void then from until exhausted or else (current_item /= void and then v.is_equal (current_item)) loop forth end else from until exhausted or else v = current_item loop forth end end ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, current_item) item_found: (not exhausted and not object_comparison) implies v = current_item end feature -- Measurement additional_space: INTEGER is -- Proposed number of additional items -- (from RESIZABLE) do Result := (capacity * growth_percentage // 100).max (minimal_increase) ensure -- from RESIZABLE at_least_one: Result >= 1 end capacity: INTEGER is -- Allocated space -- (from STRING) do Result := area.count - 1 end count: INTEGER -- Actual number of characters making up the string -- (from STRING) Growth_percentage: INTEGER is 50 -- Percentage by which structure will grow automatically -- (from RESIZABLE) index_set: INTEGER_INTERVAL is -- Range of acceptable indexes -- (from STRING) do create Result.make (1, count) ensure -- from INDEXABLE not_void: Result /= void ensure then -- from STRING Result.count = count end Minimal_increase: INTEGER is 5 -- Minimal number of additional items -- (from RESIZABLE) occurrences (c: CHARACTER): INTEGER is -- Number of times c appears in the string -- (from STRING) local counter, nb: INTEGER a: SPECIAL [CHARACTER] do from counter := 0 nb := count - 1 a := area until counter > nb loop if a.item (counter) = c then Result := Result + 1 end counter := counter + 1 end ensure -- from BAG non_negative_occurrences: Result >= 0 end feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Is string made of same character sequence as other -- (possibly with a different capacity)? -- (from STRING) require -- from ANY other_not_void: other /= void local o_area: like area do if other = Current then Result := True elseif count = other.count then o_area := other.area; Result := str_strict_cmp ($area, $o_area, count) = 0 end ensure -- from ANY symmetric: Result implies other.is_equal (Current) consistent: standard_is_equal (other) implies Result ensure then -- from COMPARABLE trichotomy: Result = (not (Current < other) and not (other < Current)) end max (other: like Current): like Current is -- The greater of current object and other -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current >= other then Result := Current else Result := other end ensure -- from COMPARABLE current_if_not_smaller: Current >= other implies Result = Current other_if_smaller: Current < other implies Result = other end min (other: like Current): like Current is -- The smaller of current object and other -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current <= other then Result := Current else Result := other end ensure -- from COMPARABLE current_if_not_greater: Current <= other implies Result = Current other_if_greater: Current > other implies Result = other end three_way_comparison (other: like Current): INTEGER is -- If current object equal to other, 0; -- if smaller, -1; if greater, 1 -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current < other then Result := - 1 elseif other < Current then Result := 1 end ensure -- from COMPARABLE equal_zero: (Result = 0) = is_equal (other) smaller_negative: (Result = - 1) = (Current < other) greater_positive: (Result = 1) = (Current > other) end infix "<" (other: like Current): BOOLEAN is -- Is string lexicographically lower than other? -- (from STRING) require -- from PART_COMPARABLE other_exists: other /= void local other_area: like area other_count: INTEGER current_count: INTEGER do other_area := other.area other_count := other.count current_count := count if other_count = current_count then Result := str_strict_cmp ($other_area, $area, other_count) > 0 else if current_count < other_count then Result := str_strict_cmp ($other_area, $area, current_count) >= 0 else Result := str_strict_cmp ($other_area, $area, other_count) > 0 end end ensure then -- from COMPARABLE asymmetric: Result implies not (other < Current) end infix "<=" (other: like Current): BOOLEAN is -- Is current object less than or equal to other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := not (other < Current) ensure then -- from COMPARABLE definition: Result = ((Current < other) or is_equal (other)) end infix ">" (other: like Current): BOOLEAN is -- Is current object greater than other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := other < Current ensure then -- from COMPARABLE definition: Result = (other < Current) end infix ">=" (other: like Current): BOOLEAN is -- Is current object greater than or equal to other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := not (Current < other) ensure then -- from COMPARABLE definition: Result = (other <= Current) end feature -- Status report after: BOOLEAN is -- Is there no valid cursor position to the right of cursor? do Result := index > count end before: BOOLEAN is -- Is there no valid cursor position to the left of cursor? do Result := index < 1 end Changeable_comparison_criterion: BOOLEAN is False -- (from STRING) empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end exhausted: BOOLEAN is -- Has structure been completely explored? -- (from LINEAR) do Result := off ensure -- from LINEAR exhausted_when_off: off implies Result end Extendible: BOOLEAN is True -- May new items be added? (Answer: yes.) -- (from STRING) full: BOOLEAN is -- Is structure full? -- (from BOUNDED) do Result := (count = capacity) end is_boolean: BOOLEAN is -- Does Current represent a BOOLEAN? -- (from STRING) local s: STRING do s := clone (Current) s.right_adjust s.left_adjust s.to_lower Result := s.is_equal (true_constant) or else s.is_equal (false_constant) end is_double: BOOLEAN is -- Does Current represent a DOUBLE? -- (from STRING) do Result := str_isd ($area, count) end is_empty: BOOLEAN is -- Is structure empty? -- (from FINITE) do Result := (count = 0) end is_hashable: BOOLEAN is -- May current object be hashed? -- (True if it is not its type's default.) -- (from HASHABLE) do Result := (Current /= default) ensure -- from HASHABLE ok_if_not_default: Result implies (Current /= default) end is_inserted (v: CHARACTER): BOOLEAN is -- Has v been inserted by the most recent insertion? -- (By default, the value returned is equivalent to calling -- `has (v)'. However, descendants might be able to provide more -- efficient implementations.) -- (from COLLECTION) do Result := has (v) end is_integer: BOOLEAN is -- Does Current represent an INTEGER? -- (from STRING) do Result := str_isi ($area, count) end is_real: BOOLEAN is -- Does Current represent a REAL? -- (from STRING) do Result := str_isr ($area, count) end object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) prunable: BOOLEAN is -- May items be removed? (Answer: yes.) -- (from STRING) do Result := True end readable: BOOLEAN is -- Is there a current item that may be read? -- (from SEQUENCE) do Result := not off end resizable: BOOLEAN is -- May capacity be changed? (Answer: yes.) -- (from RESIZABLE) do Result := True end valid_index (i: INTEGER): BOOLEAN is -- Is i within the bounds of the string? -- (from STRING) do Result := (i > 0) and (i <= count) ensure then -- from INDEXABLE only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper)) end writable: BOOLEAN is -- Is there a current item that may be modified? -- (from SEQUENCE) do Result := not off end feature -- Status setting compare_objects is -- Ensure that future search operations will use equal -- rather than = for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := True ensure -- from CONTAINER object_comparison end compare_references is -- Ensure that future search operations will use = -- rather than equal for comparing references. -- (from CONTAINER) require -- from CONTAINER changeable_comparison_criterion do object_comparison := False ensure -- from CONTAINER reference_comparison: not object_comparison end feature -- Cursor movement back is -- Move to previous position. require -- from BILINEAR not_before: not before do index := index - 1 end finish is -- Move to last position. do index := count end forth is -- Move to next position. require -- from LINEAR not_after: not after do index := index + 1 end search (v: like current_item) is -- Move to first position (at or after current -- position) where item and v are equal. -- If structure does not include v ensure that -- exhausted will be true. -- (Reference or object equality, -- based on object_comparison.) -- (from BILINEAR) do if before and not is_empty then forth end sequential_search (v) ensure -- from LINEAR object_found: (not exhausted and object_comparison) implies equal (v, current_item) item_found: (not exhausted and not object_comparison) implies v = current_item end start is -- Move to first position. do index := 1 end feature -- Element change append (s: STRING) is -- Append a copy of s at end. -- (from STRING) require -- from STRING argument_not_void: s /= void local new_size: INTEGER s_area: like area do new_size := s.count + count if new_size > capacity then resize (new_size + additional_space) end s_area := s.area; ($area + count).memory_copy ($s_area, s.count) count := new_size ensure -- from STRING new_count: count = old count + old s.count end append_boolean (b: BOOLEAN) is -- Append the string representation of b at end. -- (from STRING) do append (b.out) end append_character (c: CHARACTER) is -- Append c at end. -- Was declared in STRING as synonym of extend. -- (from STRING) local current_count: INTEGER do current_count := count if current_count = capacity then resize (current_count + additional_space) end area.put (c, current_count) count := current_count + 1 ensure then -- from STRING item_inserted: item (count) = c new_count: count = old count + 1 end append_double (d: DOUBLE) is -- Append the string representation of d at end. -- (from STRING) do append (d.out) end append_integer (i: INTEGER) is -- Append the string representation of i at end. -- (from STRING) do append (i.out) end append_real (r: REAL) is -- Append the string representation of r at end. -- (from STRING) do append (r.out) end append_string (s: STRING) is -- Append a copy of s, if not void, at end. -- (from STRING) do if s /= void then append (s) end end copy (other: like Current) is -- Reinitialize by copying the characters of other. -- (This is also used by clone.) -- (from STRING) require -- from ANY other_not_void: other /= void type_identity: same_type (other) local old_area: like area do if other /= Current then old_area := area standard_copy (other) if old_area = void or else old_area.count < area.count then area := standard_clone (area) else ($old_area).memory_copy ($area, count) area := old_area end end ensure -- from ANY is_equal: is_equal (other) ensure then -- from STRING new_result_count: count = other.count end extend (c: CHARACTER) is -- Append c at end. -- Was declared in STRING as synonym of append_character. -- (from STRING) require -- from COLLECTION extendible: extendible local current_count: INTEGER do current_count := count if current_count = capacity then resize (current_count + additional_space) end area.put (c, current_count) count := current_count + 1 ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from BAG one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1 ensure then -- from STRING item_inserted: item (count) = c new_count: count = old count + 1 end fill (other: CONTAINER [CHARACTER]) is -- Fill with as many items of other as possible. -- The representations of other and current structure -- need not be the same. -- (from COLLECTION) require -- from COLLECTION other_not_void: other /= void extendible local lin_rep: LINEAR [CHARACTER] do lin_rep := other.linear_representation from lin_rep.start until not extendible or else lin_rep.off loop extend (lin_rep.item) lin_rep.forth end end fill_blank is -- Fill with capacity blank characters. -- (from STRING) do fill_character (' ') ensure -- from STRING filled: full same_size: (count = capacity) and (capacity = old capacity) end fill_character (c: CHARACTER) is -- Fill with capacity characters all equal to c. -- (from STRING) do ($area).memory_set (c.code, capacity) count := capacity ensure -- from STRING filled: full same_size: (count = capacity) and (capacity = old capacity) end force (v: like current_item) is -- Add v to end. -- (from SEQUENCE) require -- from SEQUENCE extendible: extendible do extend (v) ensure then -- from SEQUENCE new_count: count = old count + 1 item_inserted: has (v) end head (n: INTEGER) is -- Remove all characters except for the first n; -- do nothing if n >= count. -- (from STRING) require -- from STRING non_negative_argument: n >= 0 do if n < count then count := n end ensure -- from STRING new_count: count = n.min (old count) end insert (s: STRING; i: INTEGER) is -- Add s to the left of position i in current string. -- (from STRING) require -- from STRING string_exists: s /= void index_small_enough: i <= count index_large_enough: i > 0 local new_size: INTEGER s_area: like area do new_size := s.count + count if new_size > capacity then resize (new_size + additional_space) end s_area := s.area str_insert ($area, $s_area, count, s.count, i) count := new_size ensure -- from STRING new_count: count = old count + s.count end left_adjust is -- Remove leading whitespace. -- (from STRING) do count := str_left ($area, count) ensure -- from STRING new_count: (count /= 0) implies ((item (1) /= ' ') and (item (1) /= '%T') and (item (1) /= '%R') and (item (1) /= '%N')) end string_precede (c: CHARACTER) is -- Add c at front. -- (from STRING) do if count = capacity then resize (count + additional_space) end str_cprepend ($area, c, count) count := count + 1 ensure -- from STRING new_count: count = old count + 1 end precede (c: CHARACTER) is -- Add c at front. do string_precede (c) index := index + 1 ensure new_index: index = old index + 1 end prepend (s: STRING) is -- Prepend a copy of s at front. require argument_not_void: s /= void do string_prepend (s) index := index + s.count ensure new_index: index = old index + s.count end string_prepend (s: STRING) is -- Prepend a copy of s at front. -- (from STRING) require -- from STRING argument_not_void: s /= void local new_size: INTEGER s_area: like area do new_size := count + s.count if new_size > capacity then resize (new_size + additional_space) end s_area := s.area str_insert ($area, $s_area, count, s.count, 1) count := new_size ensure -- from STRING new_count: count = old count + s.count end prepend_boolean (b: BOOLEAN) is -- Prepend the string representation of b at front. -- (from STRING) do string_prepend (b.out) end prepend_character (c: CHARACTER) is -- Prepend the string representation of c at front. -- (from STRING) do string_prepend (c.out) end prepend_double (d: DOUBLE) is -- Prepend the string representation of d at front. -- (from STRING) do string_prepend (d.out) end prepend_integer (i: INTEGER) is -- Prepend the string representation of i at front. -- (from STRING) do string_prepend (i.out) end prepend_real (r: REAL) is -- Prepend the string representation of r at front. -- (from STRING) do string_prepend (r.out) end prepend_string (s: STRING) is -- Prepend a copy of s, if not void, at front. -- (from STRING) do if s /= void then string_prepend (s) end end put (c: CHARACTER; i: INTEGER) is -- Replace character at position i by c. -- (from STRING) require -- from TABLE valid_key: valid_index (k) do area.put (c, i - 1) ensure then -- from INDEXABLE insertion_done: item (k) = v end replace (c: CHARACTER) is -- Replace current item by c. require -- from ACTIVE writable: writable do put (c, index) ensure -- from ACTIVE item_replaced: current_item = v end replace_blank is -- Replace all current characters with blanks. -- (from STRING) do replace_character (' ') ensure -- from STRING same_size: (count = old count) and (capacity = old capacity) end replace_character (c: CHARACTER) is -- Replace all current characters with characters all equal to c. -- (from STRING) do ($area).memory_set (c.code, count) ensure -- from STRING same_size: (count = old count) and (capacity = old capacity) end replace_substring (s: like Current; start_pos, end_pos: INTEGER) is -- Copy the characters of s to positions -- start_pos .. end_pos. -- (from STRING) require -- from STRING string_exists: s /= void index_small_enough: end_pos <= count order_respected: start_pos <= end_pos index_large_enough: start_pos > 0 local new_size, substring_size: INTEGER s_area: like area do substring_size := end_pos - start_pos + 1 new_size := s.count + count - substring_size if new_size > capacity then resize (new_size + additional_space) end s_area := s.area str_replace ($area, $s_area, count, s.count, start_pos, end_pos) count := new_size ensure -- from STRING new_count: count = old count + s.count - end_pos + start_pos - 1 end replace_substring_all (original, new: like Current) is -- Replace every occurence of original with new. -- (from STRING) require -- from STRING original_exists: original /= void new_exists: new /= void original_not_empty: not original.is_empty local change_pos: INTEGER do if not is_empty then from change_pos := substring_index (original, 1) until change_pos = 0 loop replace_substring (new, change_pos, change_pos + original.count - 1) if change_pos + new.count <= count then change_pos := substring_index (original, change_pos + new.count) else change_pos := 0 end end end end right_adjust is -- Remove trailing whitespace. -- (from STRING) do count := str_right ($area, count) ensure -- from STRING new_count: (count /= 0) implies ((item (count) /= ' ') and (item (count) /= '%T') and (item (count) /= '%R') and (item (count) /= '%N')) end set (t: like Current; n1, n2: INTEGER) is -- Set current string to substring of t from indices n1 -- to n2, or to empty string if no such substring. -- (from STRING) require -- from STRING argument_not_void: t /= void local s: STRING do s := t.substring (n1, n2) area := s.area count := s.count ensure -- from STRING is_substring: is_equal (t.substring (n1, n2)) end share (other: like Current) is -- Make string share the text of other. require argument_not_void: other /= void do string_share (other) index := other.index ensure shared_index: other.index = index end string_share (other: like Current) is -- Make current string share the text of other. -- Subsequent changes to the characters of current string -- will also affect other, and conversely. -- (from STRING) require -- from STRING argument_not_void: other /= void do area := other.area count := other.count ensure -- from STRING shared_count: other.count = count end subcopy (other: like Current; start_pos, end_pos, index_pos: INTEGER) is -- Copy characters of other within bounds start_pos and -- end_pos to current string starting at index index_pos. -- (from STRING) require -- from STRING other_not_void: other /= void valid_start_pos: other.valid_index (start_pos) valid_end_pos: other.valid_index (end_pos) valid_bounds: (start_pos <= end_pos) or (start_pos = end_pos + 1) valid_index_pos: valid_index (index_pos) enough_space: (count - index_pos) >= (end_pos - start_pos) local other_area: like area start0, end0, index0: INTEGER do other_area := other.area start0 := start_pos - 1 end0 := end_pos - 1 index0 := index_pos - 1 spsubcopy ($other_area, $area, start0, end0, index0) end tail (n: INTEGER) is -- Remove all characters except for the last n; -- do nothing if n >= count. -- (from STRING) require -- from STRING non_negative_argument: n >= 0 local i, j: INTEGER do if n < count then from j := (count - n) i := 0 until i = n loop area.put (area.item (j), i) i := i + 1 j := j + 1 end count := n end ensure -- from STRING new_count: count = n.min (old count) end infix "+" (s: STRING): STRING is -- Append a copy of 's' at the end of a copy of Current, -- Then return the Result. -- (from STRING) require -- from STRING argument_not_void: s /= void do create Result.make (count + s.count) Result.append_string (Current) Result.append_string (s) ensure -- from STRING result_exists: Result /= void new_count: Result.count = count + s.count end feature {NONE} -- Element change seq_append (s: SEQUENCE [CHARACTER]) is -- Append a copy of s. -- (from SEQUENCE) require -- from SEQUENCE argument_not_void: s /= void local l: like s do if s = Current then l := deep_clone (s) else l := s end from l.start until l.exhausted loop extend (l.item) l.forth end ensure -- from SEQUENCE new_count: count >= old count end sequence_put (v: like current_item) is -- Add v to end. -- (from SEQUENCE) require -- from COLLECTION extendible: extendible do extend (v) ensure -- from COLLECTION item_inserted: is_inserted (v) ensure then -- from SEQUENCE new_count: count = old count + 1 end set_area (other: like area) is -- Make other the new area -- (from TO_SPECIAL) do area := other end feature -- Removal clear_all is -- Reset all characters. -- (from STRING) do count := 0 ensure -- from STRING is_empty: count = 0 same_capacity: capacity = old capacity end prune (c: CHARACTER) is -- Remove first occurrence of c. require -- from COLLECTION prunable: prunable require else -- from STRING True local i: INTEGER do if count /= 0 then i := index_of (c, 1) if i /= 0 then remove (i) end end end prune_all (c: CHARACTER) is -- Remove all occurrences of c. -- (from STRING) require -- from COLLECTION prunable require else -- from STRING True do count := str_rmall ($area, c, count) ensure -- from COLLECTION no_more_occurrences: not has (v) ensure then -- from STRING changed_count: count = (old count) - (old occurrences (c)) end prune_all_leading (c: CHARACTER) is -- Remove all leading occurrences of c. -- (from STRING) do from until is_empty or else item (1) /= c loop remove (1) end end prune_all_trailing (c: CHARACTER) is -- Remove all trailing occurrences of c. -- (from STRING) do from until is_empty or else item (count) /= c loop remove (count) end end remove (i: INTEGER) is -- Remove i-th character. -- (from STRING) require -- from STRING index_small_enough: i <= count index_large_enough: i > 0 do str_rmchar ($area, count, i) count := count - 1 ensure -- from STRING new_count: count = old count - 1 end remove_current_item is -- Remove current item. require -- from ACTIVE prunable: prunable writable: writable do remove (index) end wipe_out is -- Clear out all characters. require -- from COLLECTION prunable do string_wipe_out index := 0 ensure -- from COLLECTION wiped_out: is_empty end string_wipe_out is -- Remove all characters. -- (from STRING) require -- from COLLECTION prunable do area := empty_area count := 0 ensure -- from COLLECTION wiped_out: is_empty ensure then -- from STRING is_empty: count = 0 empty_capacity: capacity = 0 end feature -- Resizing adapt_size is -- Adapt the size to accommodate count characters. -- (from STRING) do resize (count) end automatic_grow is -- Change the capacity to accommodate at least -- Growth_percentage more items. -- (from RESIZABLE) do grow (capacity + additional_space) ensure -- from RESIZABLE increased_capacity: capacity >= old capacity + old capacity * growth_percentage // 100 end grow (newsize: INTEGER) is -- Ensure that the capacity is at least newsize. -- (from STRING) require -- from RESIZABLE True require else -- from STRING new_size_non_negative: newsize >= 0 do if newsize > capacity then resize (newsize) end ensure -- from RESIZABLE new_capacity: capacity >= i end resize (newsize: INTEGER) is -- Rearrange string so that it can accommodate -- at least newsize characters. -- Do not lose any previously entered character. -- (from STRING) require -- from STRING new_size_non_negative: newsize >= 0 local area_count: INTEGER do area_count := area.count if newsize >= area_count then if area_count = 1 then make_area (newsize + 1) else area := str_resize ($area, newsize + 1) end end end feature -- Conversion center_justify is -- Center justify the string using -- the capacity as the width -- (from STRING) do str_cjustify ($area, count, capacity) end character_justify (pivot: CHARACTER; position: INTEGER) is -- Justify a string based on a pivot -- and the position it needs to be in -- the final string. -- This will grow the string if necessary -- to get the pivot in the correct place. -- (from STRING) require -- from STRING valid_position: position <= capacity positive_position: position >= 1 pivot_not_space: pivot /= ' ' not_empty: not is_empty do if index_of (pivot, 1) < position then from string_precede (' ') until index_of (pivot, 1) = position loop string_precede (' ') end elseif index_of (pivot, 1) > position then from remove (1) until index_of (pivot, 1) = position loop remove (1) end end from until count = capacity loop extend (' ') end end left_justify is -- Left justify the string using -- the capacity as the width -- (from STRING) do str_ljustify ($area, count, capacity) end linear_representation: LINEAR [CHARACTER] is -- Representation as a linear structure -- (from LINEAR) do Result := Current end string_mirror is -- Reverse the order of characters. -- "Hello world" -> "dlrow olleH". -- (from STRING) local a: like area c: CHARACTER i, j: INTEGER do if count > 0 then from i := count - 1 a := area until i <= j loop c := a.item (i) a.put (a.item (j), i) a.put (c, j) i := i - 1 j := j + 1 end end ensure -- from STRING same_count: count = old count end string_mirrored: like Current is -- Mirror image of string; -- result for "Hello world" is "dlrow olleH". -- (from STRING) do Result := clone (Current) if count > 0 then Result.string_mirror end ensure -- from STRING same_count: Result.count = count end right_justify is -- Right justify the string using -- the capacity as the width -- (from STRING) do str_rjustify ($area, count, capacity) end split (a_separator: CHARACTER): LINEAR [STRING] is -- Split on a_separator. -- Ignore separators in quotes. -- (from STRING) local al: ARRAYED_LIST [STRING] part: STRING i, j, c: INTEGER q: BOOLEAN p: CHARACTER do from c := count create al.make (c) i := 1 j := 0 until i > c loop j := index_of (a_separator, i) if j = 0 then j := c + 1 end part := substring (i, j - 1) if part.has ('"') then from j := i - 1 p := '%U' until j >= c or p = a_separator loop j := j + 1 p := item (j) if p = '"' and not (j > 1 and then item (j - 1) = '%%') then q := not q end if q and p = a_separator then p := '%U' end end part := substring (i, j - 1) part.replace_substring_all ("%%%%", "_#___PERCENT___#_") part.replace_substring_all ("%%%"", "_#___QUOTE___#_") part.replace_substring_all ("%"", "") part.replace_substring_all ("_#___PERCENT___#_", "%%") part.replace_substring_all ("_#___QUOTE___#_", "%"") part.prepend ("%"") part.append ("%"") end al.extend (part) i := j + 1 end Result := al check al.count = occurrences (a_separator) end ensure -- from STRING Result /= void end to_boolean: BOOLEAN is -- Boolean value; -- "True" yields True, "False" yields False -- (case-insensitive) -- (from STRING) require -- from STRING is_boolean: is_boolean local s: STRING do s := clone (Current) s.right_adjust s.left_adjust s.to_lower Result := s.is_equal (true_constant) end frozen to_c: ANY is -- A reference to a C form of current string. -- Useful only for interfacing with C software. -- (from STRING) do area.put ('%U', count) Result := area end to_double: DOUBLE is -- "Double" value; -- for example, when applied to "123.0", will yield 123.0 (double) -- (from STRING) require -- from STRING represents_a_double: is_double do Result := str_atod ($area, count) end to_integer: INTEGER is -- Integer value; -- for example, when applied to "123", will yield 123 -- (from STRING) require -- from STRING is_integer: is_integer do Result := str_atoi ($area, count) end to_lower is -- Convert to lower case. -- (from STRING) local i: INTEGER a: like area do from i := count - 1 a := area until i < 0 loop a.put (a.item (i).lower, i) i := i - 1 end end to_real: REAL is -- Real value; -- for example, when applied to "123.0", will yield 123.0 -- (from STRING) require -- from STRING represents_a_real: is_real do Result := str_ator ($area, count) end to_upper is -- Convert to upper case. -- (from STRING) local i: INTEGER a: like area do from i := count - 1 a := area until i < 0 loop a.put (a.item (i).upper, i) i := i - 1 end end feature -- Duplication mirror is -- Reverse the characters order. -- "Hello world" -> "dlrow olleH". -- The current position will be on the same item -- as before. do string_mirror index := count + 1 - index ensure same_count: count = old count mirrored_index: index = count - old index + 1 end mirrored: like Current is -- Current string read from right to left. -- The result string has the same capacity and the -- same current position (i.e. the cursor is pointing -- at the same item) do Result := string_mirrored if not after then from Result.start until Result.index = count - index + 1 loop Result.forth end end ensure mirrored_index: Result.index = count - index + 1 same_count: Result.count = count end multiply (n: INTEGER) is -- Duplicate a string within itself -- ("hello").multiply(3) => "hellohellohello" -- (from STRING) require -- from STRING meaningful_multiplier: n >= 1 local s: STRING i: INTEGER do s := clone (Current) grow (n * count) from i := n until i = 1 loop append (s) i := i - 1 end end substring (n1, n2: INTEGER): like Current is -- Copy of substring containing all characters at indices -- between n1 and n2 -- (from STRING) local other_area: like area do if (1 <= n1) and (n1 <= n2) and (n2 <= count) then create Result.make (n2 - n1 + 1) other_area := Result.area ($other_area).memory_copy ($area + (n1 - 1), n2 - n1 + 1) Result.set_count (n2 - n1 + 1) else create Result.make (0) end ensure -- from STRING new_result_count: Result.count = n2 - n1 + 1 or Result.count = 0 end feature {NONE} -- Inapplicable bag_put (v: CHARACTER) is -- (from TABLE) require -- from COLLECTION extendible: extendible do ensure -- from COLLECTION item_inserted: is_inserted (v) end go_to (r: CURSOR) is -- Go to position marked r. do end feature {STRING_HANDLER} -- Implementation frozen set_count (number: INTEGER) is -- Set count to number of characters. -- (from STRING) require -- from STRING valid_count: 0 <= number and number <= capacity do count := number ensure -- from STRING new_count: count = number end feature {STRING} -- Implementation c_p_i: INTEGER is obsolete "You now have to implement it yourself by inheriting from PLATFORM." -- Number of characters per INTEGER -- (from STRING) do end hashcode (c_string: POINTER; len: INTEGER): INTEGER is -- Hash code value of c_string -- (from STRING) external "C use %"eif_tools.h%"" end spsubcopy (source, target: POINTER; s, e, i: INTEGER) is -- Copy characters of source within bounds s -- and e to target starting at index i. -- (from STRING) external "C use %"eif_copy.h%"" end str_atod (c_string: POINTER; length: INTEGER): DOUBLE is -- Value of double in c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_DOUBLE use %"eif_str.h%"" end str_atoi (c_string: POINTER; length: INTEGER): INTEGER is -- Value of integer in c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_INTEGER use %"eif_str.h%"" end str_ator (c_string: POINTER; length: INTEGER): REAL is -- Value of real in c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_REAL use %"eif_str.h%"" end str_cjustify (c_string: POINTER; length, cap: INTEGER) is -- Center justify in a field of capacity -- the c_string of length length -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_cprepend (c_string: POINTER; c: CHARACTER; length: INTEGER) is -- Prepend c to c_string. -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_CHARACTER, EIF_INTEGER) use %"eif_str.h%"" end str_insert (c_string, other_string: POINTER; c_length, other_length, position: INTEGER) is -- Insert other_string into c_string at position. -- Insertion occurs at the left of position. -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_isd (c_string: POINTER; length: INTEGER): BOOLEAN is -- Is is a double? -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_BOOLEAN use %"eif_str.h%"" end str_isi (c_string: POINTER; length: INTEGER): BOOLEAN is -- Is is an integer? -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_BOOLEAN use %"eif_str.h%"" end str_isr (c_string: POINTER; length: INTEGER): BOOLEAN is -- Is is a real? -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_BOOLEAN use %"eif_str.h%"" end str_left (c_string: POINTER; length: INTEGER): INTEGER is -- Remove all leading whitespace from c_string. -- Return the new number of characters making c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_INTEGER use %"eif_str.h%"" end str_len (c_string: POINTER): INTEGER is -- Length of the C string: c_string -- (from STRING) external "C signature (char *): EIF_INTEGER use %"eif_str.h%"" alias "strlen" end str_ljustify (c_string: POINTER; length, cap: INTEGER) is -- Left justify in a field of capacity -- the c_string of length length -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_replace (c_string, other_string: POINTER; c_length, other_length, star_post, end_pos: INTEGER) is -- Replace substring (start_pos, end_pos) from c_string -- by other_string. -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_resize (a: POINTER; newsize: INTEGER): like area is -- Area which can accomodate -- at least newsize characters -- (from STRING) external "C use %"eif_malloc.h%"" alias "sprealloc" end str_right (c_string: POINTER; length: INTEGER): INTEGER is -- Remove all trailing whitespace from c_string. -- Return the new number of characters making c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER): EIF_INTEGER use %"eif_str.h%"" end str_rjustify (c_string: POINTER; length, cap: INTEGER) is -- Right justify in a field of capacity -- the c_string of length length -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_rmall (c_string: POINTER; c: CHARACTER; length: INTEGER): INTEGER is -- Remove all occurrences of c in c_string. -- Return new number of character making up c_string -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_CHARACTER, EIF_INTEGER): EIF_INTEGER use %"eif_str.h%"" end str_rmchar (c_string: POINTER; length, i: INTEGER) is -- Remove i-th character from c_string. -- (from STRING) external "C signature (EIF_CHARACTER *, EIF_INTEGER, EIF_INTEGER) use %"eif_str.h%"" end str_str (c_str, o_str: POINTER; clen, olen, i, fuzzy: INTEGER): INTEGER is -- Forward search of o_str within c_str starting at i. -- Return the index within c_str where the pattern was -- located, 0 if not found. -- The 'fuzzy' parameter is the maximum allowed number of -- mismatches within the pattern. A 0 means an exact match. -- (from STRING) external "C use %"eif_eiffel.h%"" end str_strict_cmp (this, other: POINTER; len: INTEGER): INTEGER is -- Compare this and other C strings -- for the first len characters. -- 0 if equal, < 0 if this < other, -- > 0 if this > other -- (from STRING) external "C signature (char *, char *, size_t): EIF_INTEGER use <string.h>" alias "strncmp" end feature {NONE} -- Empty string implementation empty_area: SPECIAL [CHARACTER] is -- Empty area used when calling `make (0)'. -- (from STRING) local old_area: like area once old_area := area make_area (1) Result := area area := old_area end feature -- Iteration do_all (action: PROCEDURE [ANY, TUPLE [CHARACTER]]) is -- Apply action to every item. -- Semantics not guaranteed if action changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from LINEAR) require -- from TRAVERSABLE action_exists: action /= void local t: TUPLE [CHARACTER] do create t.make from start until after loop t.put (current_item, 1) action.call (t) forth end end do_if (action: PROCEDURE [ANY, TUPLE [CHARACTER]]; test: FUNCTION [ANY, TUPLE [CHARACTER], BOOLEAN]) is -- Apply action to every item that satisfies test. -- Semantics not guaranteed if action or test changes the structure; -- in such a case, apply iterator to clone of structure instead. -- (from LINEAR) require -- from TRAVERSABLE action_exists: action /= void test_exits: test /= void local t: TUPLE [CHARACTER] do create t.make from start until after loop t.put (current_item, 1) if test.item (t) then action.call (t) end forth end end for_all (test: FUNCTION [ANY, TUPLE [CHARACTER], BOOLEAN]): BOOLEAN is -- Is test true for all items? -- (from LINEAR) require -- from TRAVERSABLE test_exits: test /= void local cs: CURSOR_STRUCTURE [CHARACTER] c: CURSOR t: TUPLE [CHARACTER] do create t.make cs ?= Current if cs /= void then c := cs.cursor end from start Result := True until after or not Result loop t.put (current_item, 1) Result := test.item (t) forth end if cs /= void then cs.go_to (c) end end there_exists (test: FUNCTION [ANY, TUPLE [CHARACTER], BOOLEAN]): BOOLEAN is -- Is test true for at least one item? -- (from LINEAR) require -- from TRAVERSABLE test_exits: test /= void local cs: CURSOR_STRUCTURE [CHARACTER] c: CURSOR t: TUPLE [CHARACTER] do create t.make cs ?= Current if cs /= void then c := cs.cursor end from start until after or Result loop t.put (current_item, 1) Result := test.item (t) forth end if cs /= void then cs.go_to (c) end end feature -- Output out: like Current is -- Printable representation -- (from STRING) do Result := clone (Current) end invariant -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) -- from STRING extendible: extendible compare_character: not object_comparison index_set_has_same_count: index_set.count = count -- from INDEXABLE index_set_not_void: index_set /= void -- from RESIZABLE increase_by_at_least_one: minimal_increase >= 1 -- from BOUNDED valid_count: count <= capacity full_definition: full = (count = capacity) -- from FINITE empty_definition: is_empty = (count = 0) non_negative_count: count >= 0 -- from COMPARABLE irreflexive_comparison: not (Current < Current) -- from ACTIVE writable_constraint: writable implies readable empty_constraint: is_empty implies (not readable) and (not writable) -- from BILINEAR not_both: not (after and before) before_constraint: before implies off -- from LINEAR after_constraint: after implies off -- from TRAVERSABLE empty_constraint: is_empty implies off indexing library: "[ EiffelBase: Library of reusable components for Eiffel. ]" status: "[ Copyright 1986-2001 Interactive Software Engineering (ISE). For ISE customers the original versions are an ISE product covered by the ISE Eiffel license and support agreements. ]" license: "[ EiffelBase may now be used by anyone as FREE SOFTWARE to develop any product, public-domain or commercial, without payment to ISE, under the terms of the ISE Free Eiffel Library License (IFELL) at http://eiffel.com/products/base/license.html. ]" source: "[ Interactive Software Engineering Inc. ISE Building 360 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Electronic mail <info@eiffel.com> Customer support http://support.eiffel.com ]" info: "[ For latest info see award-winning pages: http://eiffel.com ]" end -- class SEQ_STRING
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

-- Generated by ISE Eiffel --
For more details: www.eiffel.com