elogger API
Overview Classes Cluster Class Index          Top Features

ise.base.kernel

Class STRING_8


Direct ancestors

STRING_GENERAL, INDEXABLE, RESIZABLE, TO_SPECIAL, MISMATCH_CORRECTOR

Creation

Features

Invariants

indexing

description

Sequences of characters, accessible through integer indices
in a contiguous range.

legal

See notice at end of class.

status

See notice at end of class.

class STRING_8

inherit

STRING_GENERAL
COMPARABLE
HASHABLE
STRING_HANDLER
INDEXABLE [CHARACTER, INTEGER]
TABLE
BAG
COLLECTION
CONTAINER
RESIZABLE [CHARACTER]
BOUNDED
FINITE
BOX
CONTAINER
TO_SPECIAL [CHARACTER]
MISMATCH_CORRECTOR

create

make (n: INTEGER)

-- Allocate space for at least n characters.

require

non_negative_size: n >= 0

ensure

empty_string: count = 0
area_allocated: capacity >= n

make_empty

-- Create empty string.

ensure

empty: count = 0
area_allocated: capacity >= 0

make_filled (c: CHARACTER; n: INTEGER)

-- Create string of length n filled with c.

require

valid_count: n >= 0

ensure

count_set: count = n
area_allocated: capacity >= n
filled: occurrences (c) = count

make_from_string (s: STRING)

-- Initialize from the characters of s.
-- (Useful in proper descendants of class STRING_8,
-- to initialize a string-like object from a manifest string.)

require

string_exists: s /= Void

ensure

not_shared_implementation: Current /= s implies not shared_with (s)
initialized: same_string (s)

make_from_c (c_string: POINTER)

-- Initialize from contents of c_string,
-- a string created by some C function

require

c_string_exists: c_string /= default_pointer

make_from_cil (a_system_string: SYSTEM_STRING)

-- Initialize Current with a_system_string.

require

is_dotnet: {PLATFORM}.is_dotnet

convert

to_cil: {SYSTEM_STRING},
as_string_32: {STRING_32},
make_from_cil ({SYSTEM_STRING})

feature -- Initialization

adapt (s: STRING): like Current

-- Object of a type conforming to the type of s,
-- initialized with attributes from s

ensure

adapt_not_void: Result /= Void
shared_implementation: Result.shared_with (s)

from_c (c_string: POINTER)

-- Reset contents of string from contents of c_string,
-- a string created by some C function.

require

c_string_exists: c_string /= default_pointer

ensure

no_zero_byte: not has ('%/0/')

from_c_substring (c_string: POINTER; start_pos, end_pos: INTEGER)

-- Reset contents of string from substring of c_string,
-- a string created by some C function.

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 (n: INTEGER)

-- Allocate space for at least n characters.

require

non_negative_size: n >= 0

ensure

empty_string: count = 0
area_allocated: capacity >= n

make_empty

-- Create empty string.

ensure

empty: count = 0
area_allocated: capacity >= 0

make_filled (c: CHARACTER; n: INTEGER)

-- Create string of length n filled with c.

require

valid_count: n >= 0

ensure

count_set: count = n
area_allocated: capacity >= n
filled: occurrences (c) = count

make_from_c (c_string: POINTER)

-- Initialize from contents of c_string,
-- a string created by some C function

require

c_string_exists: c_string /= default_pointer

make_from_cil (a_system_string: SYSTEM_STRING)

-- Initialize Current with a_system_string.

require

is_dotnet: {PLATFORM}.is_dotnet

make_from_string (s: STRING)

-- Initialize from the characters of s.
-- (Useful in proper descendants of class STRING_8,
-- to initialize a string-like object from a manifest string.)

require

string_exists: s /= Void

ensure

not_shared_implementation: Current /= s implies not shared_with (s)
initialized: same_string (s)

remake (n: INTEGER)

-- Allocate space for at least n characters.

obsolete

Use make instead

require

non_negative_size: n >= 0

ensure

empty_string: count = 0
area_allocated: capacity >= n

feature -- Access

index_of_code (c: like code; start_index: INTEGER): INTEGER

-- Position of first occurrence of c at or after start_index;
-- 0 if none.
-- (From STRING_GENERAL)

require

start_large_enough: start_index >= 1
start_small_enough: start_index <= count + 1

ensure

valid_result: Result = 0 or (start_index <= Result and Result <= count)
zero_if_absent: (Result = 0) = not substring (start_index, count).has_code (c)
found_if_present: substring (start_index, count).has_code (c) implies code (Result) = c
none_before: substring (start_index, count).has_code (c) implies not substring (start_index, Result - 1).has_code (c)

area: SPECIAL[CHARACTER]

-- Special data zone
-- (From TO_SPECIAL)

code (i: INTEGER): NATURAL_32

-- Numeric code of character at position i
-- (From STRING_GENERAL)

require

valid_index: valid_index (i)

false_constant: STRING

-- Constant string "false"

fuzzy_index (other: STRING; start: INTEGER; fuzz: INTEGER): INTEGER

-- 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

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

hash_code: INTEGER

-- Hash code value
-- (From HASHABLE)

ensure

good_hash_value: Result >= 0

index_of (c: CHARACTER; start_index: INTEGER): INTEGER

-- Position of first occurrence of c at or after start_index;
-- 0 if none.

require

start_large_enough: start_index >= 1
start_small_enough: start_index <= count + 1

ensure

valid_result: Result = 0 or (start_index <= Result and Result <= count)
zero_if_absent: (Result = 0) = not substring (start_index, count).has (c)
found_if_present: substring (start_index, count).has (c) implies item (Result) = c
none_before: substring (start_index, count).has (c) implies not substring (start_index, Result - 1).has (c)

infix "@" (i: INTEGER): CHARACTER

-- Character at position i
-- (From TABLE)

require

valid_key: valid_key (k)

item (i: INTEGER): CHARACTER

-- Character at position i
-- (From TABLE)

require

valid_key: valid_key (k)

item_code (i: INTEGER): INTEGER

-- Numeric code of character at position i

require

index_small_enough: i <= count
index_large_enough: i > 0

last_index_of (c: CHARACTER; start_index_from_end: INTEGER): INTEGER

-- Position of last occurrence of c.
-- 0 if none

require

start_index_small_enough: start_index_from_end <= count
start_index_large_enough: start_index_from_end >= 1

ensure

last_index_of_non_negative: Result >= 0
correct_place: Result > 0 implies item (Result) = c

shared_with (other: STRING): BOOLEAN

-- Does string share the text of other?

string: STRING

-- New STRING_8 having same character sequence as Current.

ensure

string_not_void: Result /= Void
string_type: Result.same_type ("")
first_item: count > 0 implies Result.item (1) = item (1)
recurse: count > 1 implies Result.substring (2, count).is_equal ( substring (2, count).string)

substring_index (other: STRING; start_index: INTEGER): INTEGER

-- Index of first occurrence of other at or after start_index;
-- 0 if none

require

other_not_void: other /= Void
valid_start_index: start_index >= 1 and start_index <= count + 1

ensure

valid_result: Result = 0 or else (start_index <= Result and Result <= count - other.count + 1)
zero_if_absent: (Result = 0) = not substring (start_index, count).has_substring (other)
at_this_index: Result >= start_index implies other.same_string (substring (Result, Result + other.count - 1))
none_before: Result > start_index implies not substring (start_index, Result + other.count - 2).has_substring (other)

substring_index_in_bounds (other: STRING; start_pos, end_pos: INTEGER): INTEGER

-- Position of first occurrence of other at or after start_pos
-- and to or before end_pos;
-- 0 if none.

require

other_nonvoid: other /= Void
other_notempty: not other.is_empty
start_pos_large_enough: start_pos >= 1
start_pos_small_enough: start_pos <= count
end_pos_large_enough: end_pos >= start_pos
end_pos_small_enough: end_pos <= count

ensure

correct_place: Result > 0 implies other.is_equal (substring (Result, Result + other.count - 1))

true_constant: STRING

-- Constant string "true"

feature -- Measurement

capacity: INTEGER

-- Allocated space
-- (From STRING_GENERAL)

ensure

capacity_non_negative: Result >= 0

count: INTEGER

-- Actual number of characters making up the string
-- (From STRING_GENERAL)

ensure

count_non_negative: Result >= 0

index_set: INTEGER_INTERVAL

-- Range of acceptable indexes
-- (From INDEXABLE)

ensure

not_void: Result /= Void

ensure then

Result.count = count

occurrences (c: CHARACTER): INTEGER

-- Number of times c appears in the string
-- (From BAG)

ensure

non_negative_occurrences: Result >= 0

ensure then

zero_if_empty: count = 0 implies Result = 0
recurse_if_not_found_at_first_position: (count > 0 and then item (1) /= c) implies Result = substring (2, count).occurrences (c)
recurse_if_found_at_first_position: (count > 0 and then item (1) = c) implies Result = 1 + substring (2, count).occurrences (c)

additional_space: INTEGER

-- Proposed number of additional items
--| Result is a reasonable value, resulting from a space-time tradeoff.
-- (From RESIZABLE)

ensure

At_least_one: Result >= 1

Growth_percentage: INTEGER

-- Percentage by which structure will grow automatically
-- (From RESIZABLE)

Minimal_increase: INTEGER

-- Minimal number of additional items
-- (From RESIZABLE)

feature -- Comparison

infix "<=" (other: like Current): BOOLEAN

-- Is current object less than or equal to other?
-- (From PART_COMPARABLE)

require

other_exists: other /= Void

ensure then

definition: Result = ((Current < other) or is_equal (other))

infix ">" (other: like Current): BOOLEAN

-- Is current object greater than other?
-- (From PART_COMPARABLE)

require

other_exists: other /= Void

ensure then

definition: Result = (other < Current)

infix ">=" (other: like Current): BOOLEAN

-- Is current object greater than or equal to other?
-- (From PART_COMPARABLE)

require

other_exists: other /= Void

ensure then

definition: Result = (other <= Current)

max (other: like Current): like Current

-- The greater of current object and other
-- (From COMPARABLE)

require

other_exists: other /= Void

ensure

current_if_not_smaller: Current >= other implies Result = Current
other_if_smaller: Current < other implies Result = other

min (other: like Current): like Current

-- The smaller of current object and other
-- (From COMPARABLE)

require

other_exists: other /= Void

ensure

current_if_not_greater: Current <= other implies Result = Current
other_if_greater: Current > other implies Result = other

three_way_comparison (other: like Current): INTEGER

-- If current object equal to other, 0;
-- if smaller, -1; if greater, 1
-- (From COMPARABLE)

require

other_exists: other /= Void

ensure

equal_zero: (Result = 0) = is_equal (other)
smaller_negative: (Result = -1) = (Current < other)
greater_positive: (Result = 1) = (Current > other)

infix "<" (other: like Current): BOOLEAN

-- Is string lexicographically lower than other?
-- (From PART_COMPARABLE)

require

other_exists: other /= Void

ensure then

asymmetric: Result implies not (other < Current)

is_case_insensitive_equal (other: like Current): BOOLEAN

-- Is string made of same character sequence as other regardless of casing
-- (possibly with a different capacity)?

require

other_not_void: other /= Void

ensure

symmetric: Result implies other.is_case_insensitive_equal (Current)
consistent: standard_is_equal (other) implies Result
valid_result: as_lower.is_equal (other.as_lower) implies Result

is_equal (other: like Current): BOOLEAN

-- Is string made of same character sequence as other
-- (possibly with a different capacity)?
-- (From ANY)

require

other_not_void: other /= Void

ensure

symmetric: Result implies other.is_equal (Current)
consistent: standard_is_equal (other) implies Result

ensure then

trichotomy: Result = (not (Current < other) and not (other < Current))

same_string (other: STRING): BOOLEAN

-- Do Current and other have same character sequence?

require

other_not_void: other /= Void

ensure

definition: Result = string.is_equal (other.string)

feature -- Status report

is_empty: BOOLEAN

-- Is structure empty?
-- (From STRING_GENERAL)

is_hashable: BOOLEAN

-- May current object be hashed?
-- (True if it is not its type's default.)
-- (From HASHABLE)

ensure

ok_if_not_default: Result implies (Current /= default)

is_inserted (v: CHARACTER): BOOLEAN

-- 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)

resizable: BOOLEAN

-- May capacity be changed? (Answer: yes.)
-- (From BOUNDED)

full: BOOLEAN

-- Is structure full?
-- (From BOX)

empty: BOOLEAN

-- Is there no element?
-- (From CONTAINER)

obsolete

ELKS 2000: Use is_empty instead

object_comparison: BOOLEAN

-- Must search operations use equal rather than =
-- for comparing references? (Default: no, use =.)
-- (From CONTAINER)

has_code (c: like code): BOOLEAN

-- Does string include c?
-- (From STRING_GENERAL)

ensure then

false_if_empty: count = 0 implies not Result
true_if_first: count > 0 and then code (1) = c implies Result
recurse: (count > 0 and then code (1) /= c) implies (Result = substring (2, count).has_code (c))

changeable_comparison_criterion: BOOLEAN

-- (From CONTAINER)

extendible: BOOLEAN

-- May new items be added? (Answer: yes.)
-- (From COLLECTION)

has (c: CHARACTER): BOOLEAN

-- Does string include c?
-- (From CONTAINER)

ensure

not_found_in_empty: Result implies not is_empty

ensure then

false_if_empty: count = 0 implies not Result
true_if_first: count > 0 and then item (1) = c implies Result
recurse: (count > 0 and then item (1) /= c) implies (Result = substring (2, count).has (c))

has_substring (other: STRING): BOOLEAN

-- Does Current contain other?

require

other_not_void: other /= Void

ensure

false_if_too_small: count < other.count implies not Result
true_if_initial: (count >= other.count and then other.same_string (substring (1, other.count))) implies Result
recurse: (count >= other.count and then not other.same_string (substring (1, other.count))) implies (Result = substring (2, count).has_substring (other))

is_boolean: BOOLEAN

-- Does Current represent a BOOLEAN?

ensure

is_double: BOOLEAN

-- Does Current represent a REAL_64?

ensure

syntax_and_range:

is_integer: BOOLEAN

-- Does Current represent an INTEGER_32?

is_integer_16: BOOLEAN

-- Does Current represent an INTEGER_16?

is_integer_32: BOOLEAN

-- Does Current represent an INTEGER_32?

is_integer_64: BOOLEAN

-- Does Current represent an INTEGER_64?

is_integer_8: BOOLEAN

-- Does Current represent an INTEGER_8?

is_natural: BOOLEAN

-- Does Current represent a NATURAL_32?

is_natural_16: BOOLEAN

-- Does Current represent a NATURAL_16?

is_natural_32: BOOLEAN

-- Does Current represent a NATURAL_32?

is_natural_64: BOOLEAN

-- Does Current represent a NATURAL_64?

is_natural_8: BOOLEAN

-- Does Current represent a NATURAL_8?

is_number_sequence: BOOLEAN

-- Does Current represent a number sequence?

ensure

syntax_and_range:

is_real: BOOLEAN

-- Does Current represent a REAL_32?

ensure

syntax_and_range:

is_string_32: BOOLEAN

-- Current is a STRING_32 instance
-- (From STRING_GENERAL)

is_string_8: BOOLEAN

-- Current is not a STRING_8 instance
-- (From STRING_GENERAL)

is_valid_as_string_8: BOOLEAN

-- Is Current convertible to STRING_8 without information loss?
-- (From STRING_GENERAL)

prunable: BOOLEAN

-- May items be removed? (Answer: yes.)
-- (From COLLECTION)

valid_code (v: NATURAL_32): BOOLEAN

-- Is v a valid code for a CHARACTER_32?
-- (From STRING_GENERAL)

valid_index (i: INTEGER): BOOLEAN

-- Is i within the bounds of the string?
-- (From STRING_GENERAL)

feature -- Status setting

compare_objects

-- Ensure that future search operations will use equal
-- rather than = for comparing references.
-- (From CONTAINER)

require

changeable_comparison_criterion: changeable_comparison_criterion

ensure

compare_references

-- Ensure that future search operations will use =
-- rather than equal for comparing references.
-- (From CONTAINER)

require

changeable_comparison_criterion: changeable_comparison_criterion

ensure

reference_comparison: not object_comparison

feature -- Element change

append (s: STRING)

-- Append a copy of s at end.

require

argument_not_void: s /= Void

ensure

new_count: count = old count + old s.count
appended: elks_checking implies is_equal (old twin + old s.twin)

append_boolean (b: BOOLEAN)

-- Append the string representation of b at end.

append_character (c: CHARACTER)

-- Append c at end.

ensure then

item_inserted: item (count) = c
new_count: count = old count + 1
stable_before: elks_checking implies substring (1, count - 1).is_equal (old twin)

append_double (d: DOUBLE)

-- Append the string representation of d at end.

append_integer (i: INTEGER)

-- Append the string representation of i at end.

append_real (r: REAL)

-- Append the string representation of r at end.

append_string (s: STRING)

-- Append a copy of s, if not void, at end.

ensure

appended: s /= Void implies (elks_checking implies is_equal (old twin + old s.twin))

append_string_general (s: STRING_GENERAL)

-- Append a copy of s at end.
-- (From STRING_GENERAL)

require

argument_not_void: s /= Void
compatible_strings: is_string_8 implies s.is_valid_as_string_8

ensure

new_count: count = old count + old s.count
appended: elks_checking implies to_string_32.is_equal (old to_string_32.twin + old s.to_string_32.twin)

copy (other: like Current)

-- Reinitialize by copying the characters of other.
-- (This is also used by twin.)
-- (From ANY)

require

other_not_void: other /= Void
type_identity: same_type (other)

ensure

is_equal: is_equal (other)

ensure then

new_result_count: count = other.count

extend (c: CHARACTER)

-- Append c at end.
-- (From COLLECTION)

require

extendible: extendible

ensure

item_inserted: is_inserted (v)

ensure then

one_more_occurrence: occurrences (v) = old (occurrences (v)) + 1

ensure then

item_inserted: item (count) = c
new_count: count = old count + 1
stable_before: elks_checking implies substring (1, count - 1).is_equal (old twin)

fill_blank

-- Fill with capacity blank characters.

ensure

filled: full
same_size: (count = capacity) and (capacity = old capacity)

fill_character (c: CHARACTER)

-- Fill with capacity characters all equal to c.

ensure

filled: full
same_size: (count = capacity) and (capacity = old capacity)

fill_with (c: CHARACTER)

-- Replace every character with c.

ensure

same_count: (count = old count) and (capacity >= old capacity)
filled: elks_checking implies occurrences (c) = count

head (n: INTEGER)

-- Remove all characters except for the first n;
-- do nothing if n >= count.

obsolete

ELKS 2001: use keep_head instead'

require

non_negative_argument: n >= 0

ensure

new_count: count = n.min (old count)
kept: elks_checking implies is_equal (old substring (1, n.min (count)))

infix "+" (s: STRING): like Current

-- Append a copy of 's' at the end of a copy of Current,
-- Then return the Result.

require

argument_not_void: s /= Void

ensure

Result_exists: Result /= Void
new_count: Result.count = count + s.count
initial: elks_checking implies Result.substring (1, count).is_equal (Current)
final: elks_checking implies Result.substring (count + 1, count + s.count).same_string (s)

insert (s: STRING; i: INTEGER)

-- Add s to left of position i in current string.

obsolete

ELKS 2001: use insert_string instead

require

string_exists: s /= Void
index_small_enough: i <= count + 1
index_large_enough: i > 0

ensure

inserted: elks_checking implies (is_equal (old substring (1, i - 1) + old (s.twin) + old substring (i, count)))

insert_character (c: CHARACTER; i: INTEGER)

-- Insert c at index i, shifting characters between ranks
-- i and count rightwards.

require

valid_insertion_index: 1 <= i and i <= count + 1

ensure

one_more_character: count = old count + 1
inserted: item (i) = c
stable_before_i: elks_checking implies substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: elks_checking implies substring (i + 1, count).is_equal (old substring (i, count))

insert_string (s: STRING; i: INTEGER)

-- Insert s at index i, shifting characters between ranks
-- i and count rightwards.

require

string_exists: s /= Void
valid_insertion_index: 1 <= i and i <= count + 1

ensure

inserted: elks_checking implies (is_equal (old substring (1, i - 1) + old (s.twin) + old substring (i, count)))

keep_head (n: INTEGER)

-- Remove all characters except for the first n;
-- do nothing if n >= count.

require

non_negative_argument: n >= 0

ensure

new_count: count = n.min (old count)
kept: elks_checking implies is_equal (old substring (1, n.min (count)))

keep_tail (n: INTEGER)

-- Remove all characters except for the last n;
-- do nothing if n >= count.

require

non_negative_argument: n >= 0

ensure

new_count: count = n.min (old count)
kept: elks_checking implies is_equal (old substring (count - n.min(count) + 1, count))

left_adjust

-- Remove leading whitespace.

ensure

valid_count: count <= old count
new_count: not is_empty implies not item (1).is_space
kept: elks_checking implies is_equal ((old twin).substring (old count - count + 1, old count))

precede (c: CHARACTER)

-- Add c at front.

ensure

new_count: count = old count + 1

prepend (s: STRING)

-- Prepend a copy of s at front.

require

argument_not_void: s /= Void

ensure

new_count: count = old (count + s.count)
inserted: elks_checking implies string.is_equal (old (s.twin) + old substring (1, count))

prepend_boolean (b: BOOLEAN)

-- Prepend the string representation of b at front.

prepend_character (c: CHARACTER)

-- Add c at front.

ensure

new_count: count = old count + 1

prepend_double (d: DOUBLE)

-- Prepend the string representation of d at front.

prepend_integer (i: INTEGER)

-- Prepend the string representation of i at front.

prepend_real (r: REAL)

-- Prepend the string representation of r at front.

prepend_string (s: STRING)

-- Prepend a copy of s, if not void, at front.

put (c: CHARACTER; i: INTEGER)

-- Replace character at position i by c.
-- (From TABLE)

require

valid_key: valid_key (k)

ensure then

insertion_done: item (k) = v

ensure then

stable_count: count = old count
stable_before_i: elks_checking implies substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: elks_checking implies substring (i + 1, count).is_equal (old substring (i + 1, count))

put_code (v: NATURAL_32; i: INTEGER)

-- Replace character at position i by character of code v.
-- (From STRING_GENERAL)

require

valid_code: valid_code (v)
valid_index: valid_index (i)

ensure

inserted: code (i) = v
stable_count: count = old count
stable_before_i: elks_checking implies substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: elks_checking implies substring (i + 1, count).is_equal (old substring (i + 1, count))

replace_blank

-- Replace all current characters with blanks.

ensure

same_size: (count = old count) and (capacity >= old capacity)
all_blank: elks_checking implies occurrences (' ') = count

replace_character (c: CHARACTER)

-- Replace every character with c.

obsolete

ELKS 2001: use fill_with instead'

ensure

same_count: (count = old count) and (capacity >= old capacity)
filled: elks_checking implies occurrences (c) = count

replace_substring (s: STRING; start_index, end_index: INTEGER)

-- Replace characters from start_index to end_index with s.

require

string_not_void: s /= Void
valid_start_index: 1 <= start_index
valid_end_index: end_index <= count
meaningfull_interval: start_index <= end_index + 1

ensure

new_count: count = old count + old s.count - end_index + start_index - 1
replaced: elks_checking implies (is_equal (old (substring (1, start_index - 1) + s + substring (end_index + 1, count))))

replace_substring_all (original, new: like Current)

-- Replace every occurrence of original with new.

require

original_exists: original /= Void
new_exists: new /= Void
original_not_empty: not original.is_empty

right_adjust

-- Remove trailing whitespace.

ensure

valid_count: count <= old count
new_count: (count /= 0) implies ((item (count) /= ' ') and (item (count) /= '%T') and (item (count) /= '%R') and (item (count) /= '%N'))
kept: elks_checking implies is_equal ((old twin).substring (1, count))

set (t: like Current; n1, n2: INTEGER)

-- Set current string to substring of t from indices n1
-- to n2, or to empty string if no such substring.

require

argument_not_void: t /= Void

ensure

is_substring: is_equal (t.substring (n1, n2))

share (other: STRING)

-- Make current string share the text of other.
-- Subsequent changes to the characters of current string
-- will also affect other, and conversely.

require

argument_not_void: other /= Void

ensure

shared_count: other.count = count
shared_area: other.area = area

subcopy (other: like Current; start_pos, end_pos, index_pos: INTEGER)

-- Copy characters of other within bounds start_pos and
-- end_pos to current string starting at index index_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)

ensure

same_count: count = old count
copied: elks_checking implies (is_equal (old substring (1, index_pos - 1) + old other.substring (start_pos, end_pos) + old substring (index_pos + (end_pos - start_pos + 1), count)))

tail (n: INTEGER)

-- Remove all characters except for the last n;
-- do nothing if n >= count.

obsolete

ELKS 2001: use keep_tail instead'

require

non_negative_argument: n >= 0

ensure

new_count: count = n.min (old count)
kept: elks_checking implies is_equal (old substring (count - n.min(count) + 1, count))

fill (other: CONTAINER[CHARACTER])

-- Fill with as many items of other as possible.
-- The representations of other and current structure
-- need not be the same.
-- (From COLLECTION)

require

other_not_void: other /= Void
extendible: extendible

append_code (c: like code)

-- Append c at end.
-- (From STRING_GENERAL)

require

valid_code: valid_code (c)

ensure then

item_inserted: code (count) = c
new_count: count = old count + 1
stable_before: elks_checking implies substring (1, count - 1).is_equal (old twin)

feature -- Removal

clear_all

-- Reset all characters.

ensure

is_empty: count = 0
same_capacity: capacity = old capacity

prune (c: CHARACTER)

-- Remove first occurrence of c, if any.
-- (From COLLECTION)

require

prunable: prunable

require else

True

prune_all (c: CHARACTER)

-- Remove all occurrences of c.
-- (From COLLECTION)

require

prunable: prunable

require else

True

ensure

no_more_occurrences: not has (v)

ensure then

changed_count: count = (old count) - (old occurrences (c))

prune_all_leading (c: CHARACTER)

-- Remove all leading occurrences of c.

prune_all_trailing (c: CHARACTER)

-- Remove all trailing occurrences of c.

remove (i: INTEGER)

-- Remove i-th character.
-- (From STRING_GENERAL)

require

valid_index: valid_index (i)

ensure

new_count: count = old count - 1
removed: elks_checking implies to_string_32.is_equal (old substring (1, i - 1).to_string_32 + old substring (i + 1, count).to_string_32)

remove_head (n: INTEGER)

-- Remove first n characters;
-- if n > count, remove all.

require

n_non_negative: n >= 0

ensure

removed: elks_checking implies is_equal (old substring (n.min (count) + 1, count))

remove_substring (start_index, end_index: INTEGER)

-- Remove all characters from start_index
-- to end_index inclusive.

require

valid_start_index: 1 <= start_index
valid_end_index: end_index <= count
meaningful_interval: start_index <= end_index + 1

ensure

removed: elks_checking implies is_equal (old substring (1, start_index - 1) + old substring (end_index + 1, count))

remove_tail (n: INTEGER)

-- Remove last n characters;
-- if n > count, remove all.

require

n_non_negative: n >= 0

ensure

removed: elks_checking implies is_equal (old substring (1, count - n.min (count)))

wipe_out

-- Remove all characters.
-- (From COLLECTION)

require

prunable: prunable

ensure

wiped_out: is_empty

ensure then

is_empty: count = 0
empty_capacity: capacity = 0

feature -- Resizing

adapt_size

-- Adapt the size to accommodate count characters.

grow (newsize: INTEGER)

-- Ensure that the capacity is at least newsize.
-- (From RESIZABLE)

ensure

new_capacity: capacity >= i

resize (newsize: INTEGER)

-- Rearrange string so that it can accommodate
-- at least newsize characters.
-- Do not lose any previously entered character.
-- (From STRING_GENERAL)

require

new_size_non_negative: newsize >= 0

automatic_grow

-- Change the capacity to accommodate at least
-- Growth_percentage more items.
--| Trades space for time:
--| allocates fairly large chunks of memory but not very often.
-- (From RESIZABLE)

ensure

increased_capacity: capacity >= old capacity + old capacity * Growth_percentage // 100

feature -- Conversion

as_string_32: STRING_32

-- Convert Current as a STRING_32.
-- (From STRING_GENERAL)

ensure

as_string_32_not_void: Result /= Void
identity: (is_string_32 and Result = Current) or (not is_string_32 and Result /= Current)

as_string_8: STRING

-- Convert Current as a STRING_8. If a code of Current is
-- node a valid code for a STRING_8 it is replaced with the null
-- character.
-- (From STRING_GENERAL)

ensure

as_string_8_not_void: Result /= Void
identity: (is_string_8 and Result = Current) or (not is_string_8 and Result /= Current)

frozen to_cil: SYSTEM_STRING

-- Create an instance of SYSTEM_STRING using characters
-- of Current between indices 1 and count.
-- (From STRING_GENERAL)

require

is_dotnet: {PLATFORM}.is_dotnet

ensure

to_cil_not_void: Result /= Void

to_string_32: STRING_32

-- Convert Current as a STRING_32.
-- (From STRING_GENERAL)

ensure

as_string_32_not_void: Result /= Void
identity: (is_string_32 and Result = Current) or (not is_string_32 and Result /= Current)

to_string_8: STRING

-- Convert Current as a STRING_8.
-- (From STRING_GENERAL)

require

is_valid_as_string_8: is_valid_as_string_8

ensure

as_string_8_not_void: Result /= Void
identity: (is_string_8 and Result = Current) or (not is_string_8 and Result /= Current)

as_lower: like Current

-- New object with all letters in lower case.

ensure

length: Result.count = count
anchor: count > 0 implies Result.item (1) = item (1).as_lower
recurse: count > 1 implies Result.substring (2, count). is_equal (substring (2, count).as_lower)

as_upper: like Current

-- New object with all letters in upper case

ensure

length: Result.count = count
anchor: count > 0 implies Result.item (1) = item (1).as_upper
recurse: count > 1 implies Result.substring (2, count). is_equal (substring (2, count).as_upper)

center_justify

-- Center justify Current using count as width.

character_justify (pivot: CHARACTER; position: INTEGER)

-- 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.

require

valid_position: position <= capacity
positive_position: position >= 1
pivot_not_space: pivot /= ' '
not_empty: not is_empty

left_justify

-- Left justify Current using count as witdth.

linear_representation: LINEAR[CHARACTER]

-- Representation as a linear structure
-- (From CONTAINER)

mirror

-- Reverse the order of characters.
-- "Hello world" -> "dlrow olleH".

ensure

same_count: count = old count

mirrored: like Current

-- Mirror image of string;
-- Result for "Hello world" is "dlrow olleH".

ensure

same_count: Result.count = count

right_justify

-- Right justify Current using count as width.

ensure

same_count: count = old count

split (a_separator: CHARACTER): LIST[STRING]

-- Split on a_separator.

ensure

Result /= Void

to_boolean: BOOLEAN

-- Boolean value;
-- "True" yields True, "False" yields False
-- (case-insensitive)

require

is_boolean: is_boolean

ensure

to_boolean: (Result = true_constant.same_string (as_lower)) or (not Result = false_constant.same_string (as_lower))

frozen to_c: ANY

-- A reference to a C form of current string.
-- Useful only for interfacing with C software.

require

not_is_dotnet: not {PLATFORM}.is_dotnet

to_double: DOUBLE

-- "Double" value;
-- for example, when applied to "123.0", will yield 123.0 (double)

require

represents_a_double: is_double

to_integer: INTEGER

-- 32-bit integer value

require

is_integer: is_integer_32

to_integer_16: INTEGER_16

-- 16-bit integer value

require

is_integer_16: is_integer_16

to_integer_32: INTEGER

-- 32-bit integer value

require

is_integer: is_integer_32

to_integer_64: INTEGER_64

-- 64-bit integer value

require

is_integer_64: is_integer_64

to_integer_8: INTEGER_8

-- 8-bit integer value

require

is_integer_8: is_integer_8

to_lower

-- Convert to lower case.

ensure

length_end_content: elks_checking implies is_equal (old as_lower)

to_natural: NATURAL_32

-- 32-bit natural value

require

is_natural: is_natural

to_natural_16: NATURAL_16

-- 16-bit natural value

require

is_natural_16: is_natural_16

to_natural_32: NATURAL_32

-- 32-bit natural value

require

is_natural: is_natural

to_natural_64: NATURAL_64

-- 64-bit natural value

require

is_natural_64: is_natural_64

to_natural_8: NATURAL_8

-- 8-bit natural value

require

is_natural_8: is_natural_8

to_real: REAL

-- Real value;
-- for example, when applied to "123.0", will yield 123.0

require

represents_a_real: is_real

to_upper

-- Convert to upper case.

ensure

length_end_content: elks_checking implies is_equal (old as_upper)

feature -- Duplication

multiply (n: INTEGER)

-- Duplicate a string within itself
-- ("hello").multiply(3) => "hellohellohello"

require

meaningful_multiplier: n >= 1

substring (start_index, end_index: INTEGER): like Current

-- Copy of substring containing all characters at indices
-- between start_index and end_index
-- (From STRING_GENERAL)

ensure

substring_not_void: Result /= Void
substring_count: Result.count = end_index - start_index + 1 or Result.count = 0
first_item: Result.count > 0 implies Result.code (1) = code (start_index)
recurse: Result.count > 0 implies Result.substring (2, Result.count).is_equal (substring (start_index + 1, end_index))

ensure then

first_item: Result.count > 0 implies Result.item (1) = item (start_index)
recurse: Result.count > 0 implies Result.substring (2, Result.count).is_equal (substring (start_index + 1, end_index))

feature -- Correction

mismatch_information: MISMATCH_INFORMATION

-- Original attribute values of mismatched object
-- (From MISMATCH_CORRECTOR)

feature -- Output

out: STRING

-- Printable representation
-- (From ANY)

ensure then

out_not_void: Result /= Void
same_items: same_type ("") implies Result.same_string (Current)

feature {STRING_HANDLER} -- Implementation

frozen set_count (number: INTEGER)

-- Set count to number of characters.
-- (From STRING_GENERAL)

require

valid_count: 0 <= number and number <= capacity

ensure

new_count: count = number

invariant

extendible: extendible
compare_character: not object_comparison
index_set_has_same_count: index_set.count = count
area_not_void: area /= Void

-- From COMPARABLE
irreflexive_comparison: not (Current < Current)

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

-- 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

indexing

library

EiffelBase: Library of reusable components for Eiffel.

copyright

Copyright (c) 1984-2006, Eiffel Software and others

license

Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)

source

Eiffel Software
356 Storke Road, Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com


Documentation generated by edoc