indexing
description: "[
Sequences of characters, accessible through integer indices
in a contiguous range.
]"
status: "See notice at end of class"
date: "$Date$"
revision: "$Revision$"
class interface
STRING
create
make (n: INTEGER)
n
require
non_negative_size: n >= 0
ensure
empty_string: count = 0
area_allocated: capacity >= n
make_from_string (s: STRING)
s
STRING
require
string_exists: s /= void
ensure
shared_implementation: shared_with (s)
make_from_c (c_string: POINTER)
c_string
require
c_string_exists: c_string /= default_pointer
feature
adapt (s: STRING): like Current
s
s
from_c (c_string: POINTER)
c_string
require
c_string_exists: c_string /= default_pointer
ensure
no_zero_byte: not has ('%U')
from_c_substring (c_string: POINTER; start_pos, end_pos: INTEGER)
c_string
require
c_string_exists: c_string /= default_pointer
start_position_big_enough: start_pos >= 1
end_position_big_enough: start_pos <= end_pos + 1
ensure
valid_count: count = end_pos - start_pos + 1
make_from_c (c_string: POINTER)
c_string
require
c_string_exists: c_string /= default_pointer
make_from_string (s: STRING)
s
STRING
require
string_exists: s /= void
ensure
shared_implementation: shared_with (s)
feature
area: SPECIAL [CHARACTER]
TO_SPECIAL
False_constant: STRING is "false"
fuzzy_index (other: STRING; start: INTEGER; fuzz: INTEGER): INTEGER
otherstart
fuzzother
require
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
has (c: CHARACTER): BOOLEAN
c
ensure CONTAINER
not_found_in_empty: Result implies not is_empty
hash_code: INTEGER
ensure HASHABLE
good_hash_value: Result >= 0
index_of (c: CHARACTER; start: INTEGER): INTEGER
cstart
require
start_large_enough: start >= 1
start_small_enough: start <= count + 1
ensure
correct_place: Result > 0 implies item (Result) = c
item (i: INTEGER): CHARACTER
i
STRING@
require TABLE
valid_key: valid_index (k)
item_code (i: INTEGER): INTEGER
i
require
index_small_enough: i <= count
index_large_enough: i > 0
last_index_of (c: CHARACTER; start_index_from_end: INTEGER): INTEGER
c
require
start_index_small_enough: start_index_from_end <= count
start_index_large_enough: start_index_from_end >= 1
ensure
correct_place: Result > 0 implies item (Result) = c
shared_with (other: like Current): BOOLEAN
other
substring_index (other: STRING; start: INTEGER): INTEGER
otherstart
require
other_nonvoid: other /= void
other_notempty: not other.is_empty
start_large_enough: start >= 1
start_small_enough: start <= count
ensure
correct_place: Result > 0 implies substring (Result, Result + other.count - 1).is_equal (other)
True_constant: STRING is "true"
infix "@" (i: INTEGER): CHARACTER
i
STRINGitem
require TABLE
valid_key: valid_index (k)
feature
additional_space: INTEGER
RESIZABLE
ensure RESIZABLE
at_least_one: Result >= 1
capacity: INTEGER
count: INTEGER
Growth_percentage: INTEGER is 50
RESIZABLE
index_set: INTEGER_INTERVAL
ensure INDEXABLE
not_void: Result /= void
ensure then
Result.count = count
Minimal_increase: INTEGER is 5
RESIZABLE
occurrences (c: CHARACTER): INTEGER
c
ensure BAG
non_negative_occurrences: Result >= 0
feature
is_equal (other: like Current): BOOLEAN
other
require ANY
other_not_void: other /= void
ensure ANY
symmetric: Result implies other.is_equal (Current)
consistent: standard_is_equal (other) implies Result
ensure then COMPARABLE
trichotomy: Result = (not (Current < other) and not (other < Current))
max (other: like Current): like Current
other
COMPARABLE
require COMPARABLE
other_exists: other /= void
ensure COMPARABLE
current_if_not_smaller: Current >= other implies Result = Current
other_if_smaller: Current < other implies Result = other
min (other: like Current): like Current
other
COMPARABLE
require COMPARABLE
other_exists: other /= void
ensure COMPARABLE
current_if_not_greater: Current <= other implies Result = Current
other_if_greater: Current > other implies Result = other
three_way_comparison (other: like Current): INTEGER
other
COMPARABLE
require COMPARABLE
other_exists: other /= void
ensure COMPARABLE
equal_zero: (Result = 0) = is_equal (other)
smaller_negative: (Result = - 1) = (Current < other)
greater_positive: (Result = 1) = (Current > other)
infix "<" (other: like Current): BOOLEAN
other
require PART_COMPARABLE
other_exists: other /= void
ensure then COMPARABLE
asymmetric: Result implies not (other < Current)
infix "<=" (other: like Current): BOOLEAN
other
COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
ensure then COMPARABLE
definition: Result = ((Current < other) or is_equal (other))
infix ">" (other: like Current): BOOLEAN
other
COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
ensure then COMPARABLE
definition: Result = (other < Current)
infix ">=" (other: like Current): BOOLEAN
other
COMPARABLE
require PART_COMPARABLE
other_exists: other /= void
ensure then COMPARABLE
definition: Result = (other <= Current)
feature
Changeable_comparison_criterion: BOOLEAN is False
Extendible: BOOLEAN is True
full: BOOLEAN
BOUNDED
is_boolean: BOOLEAN
Current
is_double: BOOLEAN
Current
is_empty: BOOLEAN
FINITE
is_hashable: BOOLEAN
HASHABLE
ensure HASHABLE
ok_if_not_default: Result implies (Current /= default)
is_inserted (v: CHARACTER): BOOLEAN
v
COLLECTION
is_integer: BOOLEAN
Current
is_real: BOOLEAN
Current
object_comparison: BOOLEAN
equal=
=
CONTAINER
prunable: BOOLEAN
resizable: BOOLEAN
capacity
RESIZABLE
valid_index (i: INTEGER): BOOLEAN
i
ensure then INDEXABLE
only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper))
feature
compare_objects
equal
=
CONTAINER
require CONTAINER
changeable_comparison_criterion
ensure CONTAINER
object_comparison
compare_references
=
equal
CONTAINER
require CONTAINER
changeable_comparison_criterion
ensure CONTAINER
reference_comparison: not object_comparison
feature
append (s: STRING)
s
require
argument_not_void: s /= void
ensure
new_count: count = old count + old s.count
append_boolean (b: BOOLEAN)
b
append_character (c: CHARACTER)
c
STRINGextend
ensure then
item_inserted: item (count) = c
new_count: count = old count + 1
append_double (d: DOUBLE)
d
append_integer (i: INTEGER)
i
append_real (r: REAL)
r
append_string (s: STRING)
s
copy (other: like Current)
other
clone
require ANY
other_not_void: other /= void
type_identity: same_type (other)
ensure ANY
is_equal: is_equal (other)
ensure then
new_result_count: count = other.count
extend (c: CHARACTER)
c
STRINGappend_character
require COLLECTION
extendible: extendible
ensure COLLECTION
item_inserted: is_inserted (v)
ensure then BAG
one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1
ensure then
item_inserted: item (count) = c
new_count: count = old count + 1
fill (other: CONTAINER [CHARACTER])
other
other
COLLECTION
require COLLECTION
other_not_void: other /= void
extendible
fill_blank
capacity
ensure
filled: full
same_size: (count = capacity) and (capacity = old capacity)
fill_character (c: CHARACTER)
capacityc
ensure
filled: full
same_size: (count = capacity) and (capacity = old capacity)
head (n: INTEGER)
n
ncount
require
non_negative_argument: n >= 0
ensure
new_count: count = n.min (old count)
insert (s: STRING; i: INTEGER)
si
require
string_exists: s /= void
index_small_enough: i <= count
index_large_enough: i > 0
ensure
new_count: count = old count + s.count
left_adjust
ensure
new_count: (count /= 0) implies ((item (1) /= ' ') and (item (1) /= ' ') and (item (1) /= '%R') and (item (1) /= ''))
precede (c: CHARACTER)
c
STRINGprepend_character
ensure
new_count: count = old count + 1
prepend (s: STRING)
s
require
argument_not_void: s /= void
ensure
new_count: count = old count + s.count
prepend_boolean (b: BOOLEAN)
b
prepend_character (c: CHARACTER)
c
STRINGprecede
ensure
new_count: count = old count + 1
prepend_double (d: DOUBLE)
d
prepend_integer (i: INTEGER)
i
prepend_real (r: REAL)
r
prepend_string (s: STRING)
s
put (c: CHARACTER; i: INTEGER)
ic
require TABLE
valid_key: valid_index (k)
ensure then INDEXABLE
insertion_done: item (k) = v
replace_blank
ensure
same_size: (count = old count) and (capacity = old capacity)
replace_character (c: CHARACTER)
c
ensure
same_size: (count = old count) and (capacity = old capacity)
replace_substring (s: like Current; start_pos, end_pos: INTEGER)
start_posend_poss
require
string_exists: s /= void
index_small_enough: end_pos <= count
order_respected: start_pos <= end_pos
index_large_enough: start_pos > 0
ensure
new_count: count = old count + s.count - end_pos + start_pos - 1
replace_substring_all (original, new: like Current)
originalnew
require
original_exists: original /= void
new_exists: new /= void
original_not_empty: not original.is_empty
right_adjust
ensure
new_count: (count /= 0) implies ((item (count) /= ' ') and (item (count) /= ' ') and (item (count) /= '%R') and (item (count) /= ''))
set (t: like Current; n1, n2: INTEGER)
tn1
n2
require
argument_not_void: t /= void
ensure
is_substring: is_equal (t.substring (n1, n2))
share (other: like Current)
other
other
require
argument_not_void: other /= void
ensure
shared_count: other.count = count
subcopy (other: like Current; start_pos, end_pos, index_pos: INTEGER)
otherstart_pos
end_posindex_pos
require
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)
tail (n: INTEGER)
n
ncount
require
non_negative_argument: n >= 0
ensure
new_count: count = n.min (old count)
infix "+" (s: STRING): STRING
require
argument_not_void: s /= void
ensure
result_exists: Result /= void
new_count: Result.count = count + s.count
feature
clear_all
ensure
is_empty: count = 0
same_capacity: capacity = old capacity
prune (c: CHARACTER)
c
require COLLECTION
prunable: prunable
require else
True
prune_all (c: CHARACTER)
c
require COLLECTION
prunable
require else
True
ensure COLLECTION
no_more_occurrences: not has (v)
ensure then
changed_count: count = (old count) - (old occurrences (c))
prune_all_leading (c: CHARACTER)
c
prune_all_trailing (c: CHARACTER)
c
remove (i: INTEGER)
i
require
index_small_enough: i <= count
index_large_enough: i > 0
ensure
new_count: count = old count - 1
wipe_out
require COLLECTION
prunable
ensure COLLECTION
wiped_out: is_empty
ensure then
is_empty: count = 0
empty_capacity: capacity = 0
feature
adapt_size
count
automatic_grow
Growth_percentage
RESIZABLE
ensure RESIZABLE
increased_capacity: capacity >= old capacity + old capacity * growth_percentage // 100
grow (newsize: INTEGER)
newsize
require RESIZABLE
True
require else
new_size_non_negative: newsize >= 0
ensure RESIZABLE
new_capacity: capacity >= i
resize (newsize: INTEGER)
newsize
require
new_size_non_negative: newsize >= 0
feature
center_justify
character_justify (pivot: CHARACTER; position: INTEGER)
pivot
position
require
valid_position: position <= capacity
positive_position: position >= 1
pivot_not_space: pivot /= ' '
not_empty: not is_empty
left_justify
linear_representation: LINEAR [CHARACTER]
mirror
ensure
same_count: count = old count
mirrored: like Current
ensure
same_count: Result.count = count
right_justify
split (a_separator: CHARACTER): LIST [STRING]
a_separator
ensure
Result /= void
to_boolean: BOOLEAN
TrueFalse
require
is_boolean: is_boolean
frozen to_c: ANY
to_double: DOUBLE
require
represents_a_double: is_double
to_integer: INTEGER
require
is_integer: is_integer
to_lower
to_real: REAL
require
represents_a_real: is_real
to_upper
feature
multiply (n: INTEGER)
require
meaningful_multiplier: n >= 1
substring (n1, n2: INTEGER): like Current
n1n2
ensure
new_result_count: Result.count = n2 - n1 + 1 or Result.count = 0
feature
out: like Current
invariant
extendible: extendible
compare_character: not object_comparison
index_set_has_same_count: index_set.count = count
ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)
INDEXABLE
index_set_not_void: index_set /= void
RESIZABLE
increase_by_at_least_one: minimal_increase >= 1
BOUNDED
valid_count: count <= capacity
full_definition: full = (count = capacity)
FINITE
empty_definition: is_empty = (count = 0)
non_negative_count: count >= 0
COMPARABLE
irreflexive_comparison: not (Current < Current)
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 -- STRING