Automatic generation produced by ISE Eiffel
indexing status: "See notice at end of class" date: "$Date: 2001/11/16 20:34:14 $" revision: "$Revision: 1.1.1.1 $" 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 := (