elogger API
Overview Classes Cluster Class Index          Top Features

kernel.spec.ise

Class UC_STRING


Direct ancestors

KS_STRING, STRING_8, STRING_8, COMPARABLE, KI_TEXT_OUTPUT_STREAM, UC_STRING_HANDLER, UC_IMPORTED_UNICODE_ROUTINES, UC_IMPORTED_UTF8_ROUTINES, UC_IMPORTED_UTF16_ROUTINES, UC_IMPORTED_UTF32_ROUTINES, KL_IMPORTED_INTEGER_ROUTINES, DEBUG_OUTPUT

Known direct descendants

UC_UTF8_STRING

Creation

Features

Invariants

indexing

description

Unicode strings

remark

Unless specified otherwise, STRING_8 and CHARACTER_8 are
supposed to contain characters whose code follows the
unicode character set. In other words characters whose
code is between 128 and 255 should follow the ISO 8859-1
Latin-1 character set.

remark2

By default UC_STRING is implemented using the UTF-8 encoding.
Use UC_UTF*_STRING to specify the encoding explicitly.

library

Gobo Eiffel Kernel Library

copyright

Copyright (c) 2001-2004, Eric Bezault and others

license

Eiffel Forum License v2 (see forum.txt)

class UC_STRING

inherit

KS_STRING
KS_HASHABLE
KS_COMPARABLE
KL_IMPORTED_STRING_ROUTINES
KL_IMPORTED_ANY_ROUTINES
KL_IMPORTED_CHARACTER_ROUTINES
KL_SHARED_PLATFORM
STRING
STRING_GENERAL
INDEXABLE [CHARACTER, INTEGER]
TABLE
BAG
COLLECTION
CONTAINER
RESIZABLE [CHARACTER]
BOUNDED
FINITE
BOX
CONTAINER
TO_SPECIAL [CHARACTER]
MISMATCH_CORRECTOR
KI_TEXT_OUTPUT_STREAM
KI_CHARACTER_OUTPUT_STREAM
UC_STRING_HANDLER
UC_IMPORTED_UNICODE_ROUTINES
UC_IMPORTED_UTF8_ROUTINES
UC_IMPORTED_UTF16_ROUTINES
UC_IMPORTED_UTF32_ROUTINES
KL_IMPORTED_INTEGER_ROUTINES
DEBUG_OUTPUT

create

make (suggested_capacity: INTEGER)

-- Create empty string, or remove all characters from
-- existing string.
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

require

non_negative_suggested_capacity: suggested_capacity >= 0

ensure

empty_string: count = 0

ensure then

byte_count_set: byte_count = 0
byte_capacity_set: byte_capacity >= suggested_capacity

make_empty

-- Create empty string.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

empty: count = 0

make_from_string (a_string: STRING)

-- Initialize from the character sequence of a_string.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

s_not_void: s /= Void

ensure

initialized: same_string (s)

ensure then

same_unicode: same_unicode_string (a_string)

make_from_utf8 (s: STRING)

-- Initialize from the bytes sequence of s corresponding
-- to the UTF-8 representation of a string.

require

s_not_void: s /= Void
s_is_string: ANY_.same_types (s, "")
valid_utf8: utf8.valid_utf8 (s)

make_filled (c: CHARACTER; n: INTEGER)

-- Create string of length n filled with character c.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

valid_count: n >= 0

ensure

count_set: count = n
filled: occurrences (c) = count

ensure then

filled_code: code_occurrences (c.code) = count

make_filled_code (a_code: INTEGER; n: INTEGER)

-- Create string of length n filled with unicode
-- character of code a_code.

require

valid_code: unicode.valid_code (a_code)
valid_count: n >= 0

ensure

count_set: count = n
filled: code_occurrences (a_code) = count

make_filled_unicode (c: UC_CHARACTER; n: INTEGER)

-- Create string of length n filled with unicode character c.

require

c_not_void: c /= Void
valid_count: n >= 0

ensure

count_set: count = n
filled: unicode_occurrences (c) = count

make_from_substring (a_string: STRING; start_index, end_index: INTEGER)

-- Initialize from the character sequence of a_string
-- between start_index and end_index inclusive.

require

a_string_not_void: a_string /= Void
valid_start_index: 1 <= start_index
valid_end_index: end_index <= a_string.count
meaningful_interval: start_index <= end_index + 1

make_from_utf16 (s: STRING)

-- Initialize from the bytes sequence of s corresponding
-- to the UTF-16 representation of a string.

require

s_not_void: s /= Void
s_is_string: ANY_.same_types (s, "")
valid_utf16: utf16.valid_utf16 (s)

feature -- Initialization

adapt (s: STRING): like Current

-- Object of a type conforming to the type of s,
-- initialized with attributes from s
-- (From STRING_8)

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.
-- (From STRING_8)

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.
-- (From STRING_8)

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)

-- Initialize from contents of c_string,
-- a string created by some C function
-- (From STRING_8)

require

c_string_exists: c_string /= default_pointer

make_from_cil (a_system_string: SYSTEM_STRING)

-- Initialize Current with a_system_string.
-- (From STRING_8)

require

is_dotnet: {PLATFORM}.is_dotnet

remake (n: INTEGER)

-- Allocate space for at least n characters.
-- (From STRING_8)

obsolete

Use make instead

require

non_negative_size: n >= 0

ensure

empty_string: count = 0
area_allocated: capacity >= n

make (suggested_capacity: INTEGER)

-- Create empty string, or remove all characters from
-- existing string.
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

require

non_negative_suggested_capacity: suggested_capacity >= 0

ensure

empty_string: count = 0

ensure then

byte_count_set: byte_count = 0
byte_capacity_set: byte_capacity >= suggested_capacity

make_from_string (a_string: STRING)

-- Initialize from the character sequence of a_string.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

s_not_void: s /= Void

ensure

initialized: same_string (s)

ensure then

same_unicode: same_unicode_string (a_string)

feature -- Access

STRING_: KL_STRING_ROUTINES

-- Routines that ought to be in class STRING_8
-- (From KL_IMPORTED_STRING_ROUTINES)

ensure

string_routines_not_void: Result /= Void

utf16: UC_UTF16_ROUTINES

-- UTF-16 encoding routines
-- (From UC_IMPORTED_UTF16_ROUTINES)

ensure

utf16_not_void: Result /= Void

area: SPECIAL[CHARACTER]

-- Special data zone
-- (From TO_SPECIAL)

CHARACTER_: KL_CHARACTER_ROUTINES

-- Routines that ought to be in class CHARACTER_8
-- (From KL_IMPORTED_CHARACTER_ROUTINES)

ensure

character_routines_not_void: Result /= Void

utf8: UC_UTF8_ROUTINES

-- UTF-8 encoding routines
-- (From UC_IMPORTED_UTF8_ROUTINES)

ensure

utf8_not_void: Result /= Void

Platform: KL_PLATFORM

-- Platform-dependent properties
-- (From KL_SHARED_PLATFORM)

ensure

platform_not_void: Result /= Void

false_constant: STRING

-- Constant string "false"
-- (From STRING_8)

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
-- (From STRING_8)

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

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

-- Position of last occurrence of c.
-- 0 if none
-- (From STRING_8)

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?
-- (From STRING_8)

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.
-- (From STRING_8)

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"
-- (From STRING_8)

ANY_: KL_ANY_ROUTINES

-- Routines that ought to be in class ANY
-- (From KL_IMPORTED_ANY_ROUTINES)

ensure

any_routines_not_void: Result /= Void

unicode: UC_UNICODE_ROUTINES

-- Unicode routines
-- (From UC_IMPORTED_UNICODE_ROUTINES)

ensure

unicode_not_void: Result /= Void

INTEGER_: KL_INTEGER_ROUTINES

-- Routines that ought to be in class INTEGER_32
-- (From KL_IMPORTED_INTEGER_ROUTINES)

ensure

integer_routines_not_void: Result /= Void

hash_code: INTEGER

-- Hash code
-- (ELKS 2001 STRING_8)
-- (From KS_HASHABLE)

ensure

good_hash_value: Result >= 0

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

-- Index of first occurrence of character c
-- at or after start_index; 0 if none
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

valid_start_index: start_index >= 1 and 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)

index_of_item_code (a_code: INTEGER; start_index: INTEGER): INTEGER

-- Index of first occurrence of unicode character with
-- code a_code at or after start_index; 0 if none

require

valid_start_index: start_index >= 1 and start_index <= count + 1
valid_code: unicode.valid_code (a_code)

ensure

valid_result: Result = 0 or (start_index <= Result and Result <= count)
zero_if_absent: (Result = 0) = not substring (start_index, count).has_item_code (a_code)
found_if_present: substring (start_index, count).has_item_code (a_code) implies item_code (Result) = a_code
none_before: substring (start_index, count).has_item_code (a_code) implies not substring (start_index, Result - 1).has_item_code (a_code)

index_of_unicode (c: UC_CHARACTER; start_index: INTEGER): INTEGER

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

require

valid_start_index: start_index >= 1 and 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_unicode (c)
found_if_present: substring (start_index, count).has_unicode (c) implies item_code (Result) = c.code
none_before: substring (start_index, count).has_unicode (c) implies not substring (start_index, Result - 1).has_unicode (c)

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

-- New object which is a clone of Current extended
-- by the characters of other
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

other_not_void: other /= Void

ensure

result_not_void: Result /= Void
result_count: Result.count = count + other.count
initial: Result.substring (1, count).is_equal (Current)
final: Result.substring (count + 1, count + other.count).same_string (other)

ensure then

final_unicode: Result.substring (count + 1, count + other.count).same_unicode_string (other)

infix "@" (i: INTEGER): CHARACTER

-- Character at index i
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

valid_index: valid_index (i)

ensure

definition: Result = item (i)

item (i: INTEGER): CHARACTER

-- Character at index i;
-- '%U' if the unicode character at index
-- i cannot fit into a CHARACTER_8
-- (Extended from ELKS 2001 STRING_8)
-- Note: Use item_code instead of this routine when Current
-- can contain characters which may not fit into a CHARACTER_8.
-- (From KS_STRING)

require

valid_index: valid_index (i)

ensure

code_small_enough: item_code (i) <= Platform.Maximum_character_code implies Result.code = item_code (i)
overflow: item_code (i) > Platform.Maximum_character_code implies Result = '%U'

item_code (i: INTEGER): INTEGER

-- Code of character at index i
-- (From KS_STRING)

require

valid_index: valid_index (i)

ensure

item_code_positive: Result >= 0

ensure then

valid_item_code: unicode.valid_code (Result)

new_empty_string (suggested_capacity: INTEGER): like Current

-- New empty string with same dynamic type as Current

require

non_negative_suggested_capacity: suggested_capacity >= 0

ensure

new_string_not_void: Result /= Void
same_type: ANY_.same_types (Result, Current)
new_string_empty: Result.count = 0
byte_count_set: Result.byte_count = 0
byte_capacity_set: Result.byte_capacity >= suggested_capacity

prefixed_string (other: STRING): like Current

-- New object which is a clone of Current preceded
-- by the characters of other

require

other_not_void: other /= Void

ensure

prefixed_string_not_void: Result /= Void
prefixed_string_count: Result.count = other.count + count
initial: Result.substring (1, other.count).same_unicode_string (other)
final: Result.substring (other.count + 1, Result.count).is_equal (Current)

string: STRING

-- New STRING_8 having the same character sequence as Current
-- where characters which do not fit in a CHARACTER_8 are
-- replaced by a '%U'
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

string_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
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 (start_index, end_index: INTEGER): like Current

-- New object containing all characters
-- from start_index to end_index inclusive
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

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

ensure

substring_not_void: Result /= Void
substring_count: Result.count = end_index - start_index + 1
first_item: Result.count > 0 implies Result.item (1) = item (start_index)

ensure then

first_unicode_item: Result.count > 0 implies Result.item_code (1) = item_code (start_index)

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

-- Index of first occurrence of other at or after start_index;
-- 0 if none. other and Current are considered with their
-- characters which do not fit in a CHARACTER_8 replaced by a '%U'
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

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).current_string)
none_before: Result > start_index implies not substring (start_index, Result + other.count - 2).has_substring (other)

unicode_item (i: INTEGER): UC_CHARACTER

-- Unicode character at index i;
-- Return a new object at each call

require

valid_index: valid_index (i)

ensure

item_not_void: Result /= Void
code_set: Result.code = item_code (i)

unicode_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_unicode_substring (other)
at_this_index: Result >= start_index implies substring (Result, Result + other.count - 1).same_unicode_string (other)
none_before: Result > start_index implies not substring (start_index, Result + other.count - 2).has_unicode_substring (other)

utf32: UC_UTF32_ROUTINES

-- UTF-32 encoding routines
-- (From UC_IMPORTED_UTF32_ROUTINES)

ensure

utf32_not_void: Result /= Void

feature -- Measurement

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)

index_set: INTEGER_INTERVAL

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

ensure

not_void: Result /= Void

ensure then

Result.count = count

byte_capacity: INTEGER

-- Maximum number of bytes that can be put in
-- internal storage
-- (From STRING_GENERAL)

ensure

capacity_non_negative: Result >= 0

byte_count: INTEGER

-- Number of bytes in internal storage

code_occurrences (a_code: INTEGER): INTEGER

-- Number of times unicode character of code
-- a_code appears in the string

require

valid_code: unicode.valid_code (a_code)

ensure

zero_if_empty: count = 0 implies Result = 0
recurse_if_not_found_at_first_position: (count > 0 and then item_code (1) /= a_code) implies Result = substring (2, count).code_occurrences (a_code)
recurse_if_found_at_first_position: (count > 0 and then item_code (1) = a_code) implies Result = 1 + substring (2, count).code_occurrences (a_code)

count: INTEGER

-- Number of characters
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

occurrences (c: CHARACTER): INTEGER

-- Number of times character c appears in the string
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

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)

unicode_occurrences (c: UC_CHARACTER): INTEGER

-- Number of times c appears in the string

require

c_not_void: c /= Void

ensure

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

feature -- Comparison

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

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

require

other_not_void: other /= Void

ensure

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

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

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

require

other_not_void: other /= Void

ensure

definition: Result = (other < Current)

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

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

require

other_not_void: other /= Void

ensure

definition: Result = (other <= Current)

max (other: like Current): like Current

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

require

other_not_void: 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 KS_COMPARABLE)

require

other_not_void: other /= Void

ensure

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

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

-- Is string lexicographically lower than other?
-- (Extended from ELKS 2001 STRING_8, inherited from COMPARABLE)
-- (From KS_COMPARABLE)

require

other_not_void: other /= Void

ensure

asymmetric: Result implies not (other < Current)

ensure then

definition: ANY_.same_types (Current, "") implies Result = (count = 0 and other.count > 0 or count > 0 and then other.count > 0 and then (item (1) < other.item (1) or item (1) = other.item (1) and substring (2, count) < other.substring (2, other.count)))

ensure then

unicode_definition: Result = (count = 0 and other.count > 0 or count > 0 and then other.count > 0 and then (item_code (1) < other.item_code (1) or item_code (1) = other.item_code (1) and substring (2, count) < other.substring (2, other.count)))

is_equal (other: like Current): BOOLEAN

-- Is other attached to an object considered equal
-- to current object?
-- (Extended from ELKS 2001 STRING_8)
-- (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

definition: ANY_.same_types (Current, "") implies (Result = (ANY_.same_types (Current, other) and then count = other.count and then (count > 0 implies (item (1) = other.item (1) and (count > 1 implies substring (2, count).is_equal (other.substring (2, count)))))))

ensure then

unicode_definition: Result = (ANY_.same_types (Current, other) and then count = other.count and then (count > 0 implies (item_code (1) = other.item_code (1) and substring (2, count).is_equal (other.substring (2, count)))))

same_string (other: STRING): BOOLEAN

-- Do Current and other have the same character sequence?
-- Current is considered with its characters which do not
-- fit in a CHARACTER_8 replaced by a '%U'.
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

require

other_not_void: other /= Void

ensure

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

same_unicode_string (other: STRING): BOOLEAN

-- Do Current and other have the same unicode character sequence?

require

other_not_void: other /= Void

ensure

definition: Result = (count = other.count and then (count > 0 implies (item_code (1) = other.item_code (1) and (count >= 2 implies substring (2, count).same_unicode_string (other.substring (2, count))))))
same_string: Result implies same_string (other)

three_way_comparison (other: like Current): INTEGER

-- If current object equal to other, 0;
-- if smaller, -1; if greater, 1
-- (ELKS 2001 STRING_8, inherited from COMPARABLE)
-- Note: there is a bug in the specification of the
-- contracts of three_way_comparison inherited
-- from COMPARABLE. This routine cannot satisfy
-- its postconditions if other is not of the
-- same type as Current because the postcondition
-- uses is_equal and is_equal has a postcondition
-- inherited from ANY which says if it returns true
-- then other has the same type as Current.
-- (From KS_COMPARABLE)

require

other_not_void: other /= Void

ensure

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

three_way_unicode_comparison (other: STRING): INTEGER

-- If current object equal to other, 0;
-- if smaller, -1; if greater, 1
-- Note: there is a bug in the specification of the
-- contracts of three_way_comparison inherited
-- from COMPARABLE. This routine cannot satisfy
-- its postconditions if other is not of the
-- same type as Current because the postcondition
-- uses is_equal and is_equal has a postcondition
-- inherited from ANY which says if it returns true
-- then other has the same type as Current.
-- three_way_unicode_comparison solves this problem
-- and make the comparison polymorphically safe by
-- changing the signature from 'like Current' to
-- 'STRING_8' and by using same_unicode_string instead
-- of is_equal in its postcondition.

require

other_not_void: other /= Void

ensure

equal_zero: (Result = 0) = same_unicode_string (other)

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)?
-- (From STRING_8)

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

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

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

feature -- Status report

object_comparison: BOOLEAN

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

old_empty: BOOLEAN

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

obsolete

ELKS 2000: Use is_empty instead

changeable_comparison_criterion: BOOLEAN

-- (From CONTAINER)

extendible: BOOLEAN

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

is_boolean: BOOLEAN

-- Does Current represent a BOOLEAN?
-- (From STRING_8)

ensure

is_double: BOOLEAN

-- Does Current represent a REAL_64?
-- (From STRING_8)

ensure

syntax_and_range:

is_integer: BOOLEAN

-- Does Current represent an INTEGER_32?
-- (From STRING_8)

is_integer_16: BOOLEAN

-- Does Current represent an INTEGER_16?
-- (From STRING_8)

is_integer_32: BOOLEAN

-- Does Current represent an INTEGER_32?
-- (From STRING_8)

is_integer_64: BOOLEAN

-- Does Current represent an INTEGER_64?
-- (From STRING_8)

is_integer_8: BOOLEAN

-- Does Current represent an INTEGER_8?
-- (From STRING_8)

is_natural: BOOLEAN

-- Does Current represent a NATURAL_32?
-- (From STRING_8)

is_natural_16: BOOLEAN

-- Does Current represent a NATURAL_16?
-- (From STRING_8)

is_natural_32: BOOLEAN

-- Does Current represent a NATURAL_32?
-- (From STRING_8)

is_natural_64: BOOLEAN

-- Does Current represent a NATURAL_64?
-- (From STRING_8)

is_natural_8: BOOLEAN

-- Does Current represent a NATURAL_8?
-- (From STRING_8)

is_number_sequence: BOOLEAN

-- Does Current represent a number sequence?
-- (From STRING_8)

ensure

syntax_and_range:

is_real: BOOLEAN

-- Does Current represent a REAL_32?
-- (From STRING_8)

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

ensure

definition: Result = (1 <= i and i <= count)

has (c: CHARACTER): BOOLEAN

-- Does Current contain character c?
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

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_item_code (a_code: INTEGER): BOOLEAN

-- Does Current contain the unicode character of code a_code?

require

valid_code: unicode.valid_code (a_code)

ensure

false_if_empty: count = 0 implies not Result
true_if_first: count > 0 and then item_code (1) = a_code implies Result
recurse: (count > 0 and then item_code (1) /= a_code) implies (Result = substring (2, count).has_item_code (a_code))

has_substring (other: STRING): BOOLEAN

-- Does Current contain other?
-- other and Current are considered with their characters
-- which do not fit in a CHARACTER_8 replaced by a '%U'.
-- (Extented from ELKS 2001 STRING_8)
-- (From KS_STRING)

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).current_string)) implies Result
recurse: (count >= other.count and then not other.same_string (substring (1, other.count).current_string)) implies (Result = substring (2, count).has_substring (other))

has_unicode (c: UC_CHARACTER): BOOLEAN

-- Does Current contain c?

require

c_not_void: c /= Void

ensure

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

has_unicode_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 substring (1, other.count).same_unicode_string (other)) implies Result
recurse: (count >= other.count and then not substring (1, other.count).same_unicode_string (other)) implies (Result = substring (2, count).has_unicode_substring (other))
has_substring: Result implies has_substring (other)

is_ascii: BOOLEAN

-- Does string contain only ASCII characters?

ensure

empty: count = 0 implies Result
recurse: count > 0 implies Result = (unicode_item (1).is_ascii and substring (2, count).is_ascii)

is_empty: BOOLEAN

-- Is string empty?
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

definition: Result = (count = 0)

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)

old_is_empty: BOOLEAN

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

is_closable: BOOLEAN

-- Can current output stream be closed?
-- (From KI_OUTPUT_STREAM)

ensure

is_open: Result implies is_open_write

resizable: BOOLEAN

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

full: BOOLEAN

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

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

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 (s: STRING)

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

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.
-- (From STRING_8)

append_double (d: DOUBLE)

-- Append the string representation of d at end.
-- (From STRING_8)

append_integer (i: INTEGER)

-- Append the string representation of i at end.
-- (From STRING_8)

append_real (r: REAL)

-- Append the string representation of r at end.
-- (From STRING_8)

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)

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.
-- (From STRING_8)

ensure

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

fill_character (c: CHARACTER)

-- Fill with capacity characters all equal to c.
-- (From STRING_8)

ensure

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

insert (s: STRING; i: INTEGER)

-- Add s to left of position i in current string.
-- (From STRING_8)

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

precede (c: CHARACTER)

-- Add c at front.
-- (From STRING_8)

ensure

new_count: count = old count + 1

prepend (s: STRING)

-- Prepend a copy of s at front.
-- (From STRING_8)

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.
-- (From STRING_8)

prepend_character (c: CHARACTER)

-- Add c at front.
-- (From STRING_8)

ensure

new_count: count = old count + 1

prepend_double (d: DOUBLE)

-- Prepend the string representation of d at front.
-- (From STRING_8)

prepend_integer (i: INTEGER)

-- Prepend the string representation of i at front.
-- (From STRING_8)

prepend_real (r: REAL)

-- Prepend the string representation of r at front.
-- (From STRING_8)

prepend_string (s: STRING)

-- Prepend a copy of s, if not void, at front.
-- (From STRING_8)

replace_blank

-- Replace all current characters with blanks.
-- (From STRING_8)

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.
-- (From STRING_8)

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_all (original, new: like Current)

-- Replace every occurrence of original with new.
-- (From STRING_8)

require

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

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.
-- (From STRING_8)

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.
-- (From STRING_8)

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.
-- (From STRING_8)

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

append_character (c: CHARACTER)

-- Append character c at end.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

new_count: count = old count + 1
appended: item (count) = c
stable_before: substring (1, count - 1).current_string.is_equal (old STRING_.cloned_string (current_string))

ensure then

unicode_appended: item_code (count) = c.code

append_item_code (a_code: INTEGER)

-- Append unicode character of code a_code at end.

require

valid_item_code: unicode.valid_code (a_code)

ensure

new_count: count = old count + 1
appended: item_code (count) = a_code
stable_before: substring (1, count - 1).is_equal (old cloned_string)

append_string (a_string: STRING)

-- Append a copy of a_string at end.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

s_not_void: s /= Void

ensure

append_substring (a_string: STRING; s, e: INTEGER)

-- Append substring of a_string between indexes
-- s and e at end of current string.
-- (From KI_CHARACTER_OUTPUT_STREAM)

require

is_open_write: is_open_write
a_string_not_void: a_string /= Void
s_large_enough: s >= 1
e_small_enough: e <= a_string.count
valid_interval: s <= e + 1

ensure then

appended: is_equal (old cloned_string + old a_string.substring (s, e))

append_unicode_character (c: UC_CHARACTER)

-- Append unicode character c at end.

require

c_not_void: c /= Void

ensure

new_count: count = old count + 1
appended: item_code (count) = c.code
stable_before: substring (1, count - 1).is_equal (old cloned_string)

append_utf16 (s: STRING)

-- Append UTF-16 encoded string s at end of current string.

require

s_not_void: s /= Void
s_is_string: ANY_.same_types (s, "")
valid_utf16: utf16.valid_utf16 (s)

append_utf8 (s: STRING)

-- Append UTF-8 encoded string s at end of current string.

require

s_not_void: s /= Void
s_is_string: ANY_.same_types (s, "")
valid_utf8: utf8.valid_utf8 (s)

fill_with (c: CHARACTER)

-- Replace every character with character c.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

same_count: old count = count
filled: occurrences (c) = count

ensure then

all_code: code_occurrences (c.code) = count

fill_with_code (a_code: INTEGER)

-- Replace every character with unicode character of code a_code.

require

valid_code: unicode.valid_code (a_code)

ensure

same_count: old count = count
filled: code_occurrences (a_code) = count

fill_with_unicode (c: UC_CHARACTER)

-- Replace every character with unicode character c.

require

c_not_void: c /= Void

ensure

same_count: old count = count
filled: unicode_occurrences (c) = count

insert_character (c: CHARACTER; i: INTEGER)

-- Insert character c at index i, shifting
-- characters between ranks i and count rightwards.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

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: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i, count))

ensure then

code_inserted: item_code (i) = c.code

insert_code (a_code: INTEGER; i: INTEGER)

-- Insert unicode character of code a_code
-- at index i, shifting characters between
-- ranks i and count rightwards.

require

valid_code: unicode.valid_code (a_code)
valid_insertion_index: 1 <= i and i <= count + 1

ensure

one_more_character: count = old count + 1
inserted: item_code (i) = a_code
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i, count))

insert_string (a_string: STRING; i: INTEGER)

-- Insert a_string at index i, shifting characters between ranks
-- i and count rightwards.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

string_not_void: s /= Void
valid_insertion_index: 1 <= i and i <= count + 1
not_current: s /= current_string

require else

string_not_void: a_string /= Void
valid_insertion_index: 1 <= i and i <= count + 1

ensure

inserted: is_equal (old substring (1, i - 1) + old STRING_.cloned_string (s) + old substring (i, count).current_string)

insert_unicode_character (c: UC_CHARACTER; i: INTEGER)

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

require

c_not_void: c /= Void
valid_insertion_index: 1 <= i and i <= count + 1

ensure

one_more_character: count = old count + 1
inserted: item_code (i) = c.code
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i, count))

put (c: CHARACTER; i: INTEGER)

-- Replace unicode character at index i by character c.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

valid_index: valid_index (i)

ensure

stable_count: count = old count
replaced: item (i) = c
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i + 1, count))

ensure then

unicode_replaced: item_code (i) = c.code

put_item_code (a_code: INTEGER; i: INTEGER)

-- Replace unicode character at index i
-- by unicode character of code a_code.

require

valid_index: valid_index (i)
valid_item_code: unicode.valid_code (a_code)

ensure

stable_count: count = old count
replaced: item_code (i) = a_code
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i + 1, count))

put_unicode (c: UC_CHARACTER; i: INTEGER)

-- Replace unicode character at index i by c.

require

valid_index: valid_index (i)
c_not_void: c /= Void

ensure

stable_count: count = old count
replaced: item_code (i) = c.code
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i + 1, count))

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

-- Replace the substring from start_index to end_index,
-- inclusive, with a_string.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

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

ensure

replaced: is_equal (old (substring (1, start_index - 1) + s + substring (end_index + 1, count).current_string))

replace_substring_by_string (a_string: STRING; start_index, end_index: INTEGER)

-- Replace the substring from start_index to end_index,
-- inclusive, with a_string.

feature -- Removal

keep_head (n: INTEGER)

-- Remove all the characters except for the first n;
-- if n > count, do nothing.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

n_non_negative: n >= 0

ensure

kept: is_equal (old substring (1, n.min (count)))

keep_tail (n: INTEGER)

-- Remove all the characters except for the last n;
-- if n > count, do nothing.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

n_non_negative: n >= 0

ensure

kept: is_equal (old substring (count - n.min (count) + 1, count))

remove (i: INTEGER)

-- Remove i-th character, shifting characters between
-- ranks i + 1 and count leftwards.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

valid_removal_index: valid_index (i)

ensure

removed: is_equal (old substring (1, i - 1) + old substring (i + 1, count).current_string)

remove_head (n: INTEGER)

-- Remove the first n characters;
-- if n > count, remove all.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

n_non_negative: n >= 0

ensure

removed: 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.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

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

ensure

removed: is_equal (old substring (1, start_index - 1) + old substring (end_index + 1, count).current_string)

remove_tail (n: INTEGER)

-- Remove the last n characters;
-- if n > count, remove all.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

require

n_non_negative: n >= 0

ensure

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

wipe_out

-- Remove all characters.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

empty_string: count = 0

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.
-- (From STRING_8)

prune_all_trailing (c: CHARACTER)

-- Remove all trailing occurrences of c.
-- (From STRING_8)

feature -- Resizing

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

adapt_size

-- Adapt the size to accommodate count characters.
-- (From STRING_8)

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

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
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

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

ensure then

unicode_anchor: count > 0 implies Result.unicode_item (1).is_equal (unicode_item (1).as_lower)
unicode_recurse: count > 1 implies Result.substring (2, count).is_equal (substring (2, count).as_lower)

as_string: STRING

-- STRING_8 version of current string;
-- Return the UTF8 representation if it is encoded
-- with UTF8, the UTF16 representation if it is
-- encoded with UTF16, etc.

ensure

as_string_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")

as_upper: like Current

-- New object with all letters in upper case
-- (Extended from ELKS 2001 STRING_8)
-- (From KS_STRING)

ensure

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

ensure then

unicode_anchor: count > 0 implies Result.unicode_item (1).is_equal (unicode_item (1).as_upper)
unicode_recurse: count > 1 implies Result.substring (2, count).is_equal (substring (2, count).as_upper)

to_lower

-- Convert all letters to lower case.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

to_upper

-- Convert all letters to upper case.
-- (ELKS 2001 STRING_8)
-- (From KS_STRING)

to_utf16_be: STRING

-- New STRING_8 made up of bytes corresponding to
-- the UTF-16BE representation of current string

ensure

to_utf16_be_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
valid_utf16: utf16.valid_utf16 (Result)

to_utf16_le: STRING

-- New STRING_8 made up of bytes corresponding to
-- the UTF-16LE representation of current string

ensure

to_utf16_le_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
valid_utf16: utf16.valid_utf16 (utf16.bom_le + Result)

to_utf32_be: STRING

-- New STRING_8 made up of bytes corresponding to
-- the UTF-32BE representation of current string

ensure

to_utf32_be_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
valid_utf32: utf32.valid_utf32 (Result)

to_utf32_le: STRING

-- New STRING_8 made up of bytes corresponding to
-- the UTF-32LE representation of current string

ensure

to_utf32_le_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
valid_utf32: utf32.valid_utf32 (utf32.bom_le + Result)

to_utf8: STRING

-- New STRING_8 made up of bytes corresponding to
-- the UTF-8 representation of current string

ensure

to_utf8_not_void: Result /= Void
string_type: ANY_.same_types (Result, "")
valid_utf8: utf8.valid_utf8 (Result)

center_justify

-- Center justify Current using count as width.
-- (From STRING_8)

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.
-- (From STRING_8)

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.
-- (From STRING_8)

linear_representation: LINEAR[CHARACTER]

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

mirror

-- Reverse the order of characters.
-- "Hello world" -> "dlrow olleH".
-- (From STRING_8)

ensure

same_count: count = old count

mirrored: like Current

-- Mirror image of string;
-- Result for "Hello world" is "dlrow olleH".
-- (From STRING_8)

ensure

same_count: Result.count = count

right_justify

-- Right justify Current using count as width.
-- (From STRING_8)

ensure

same_count: count = old count

split (a_separator: CHARACTER): LIST[STRING]

-- Split on a_separator.
-- (From STRING_8)

ensure

Result /= Void

to_boolean: BOOLEAN

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

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.
-- (From STRING_8)

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)
-- (From STRING_8)

require

represents_a_double: is_double

to_integer: INTEGER

-- 32-bit integer value
-- (From STRING_8)

require

is_integer: is_integer_32

to_integer_16: INTEGER_16

-- 16-bit integer value
-- (From STRING_8)

require

is_integer_16: is_integer_16

to_integer_32: INTEGER

-- 32-bit integer value
-- (From STRING_8)

require

is_integer: is_integer_32

to_integer_64: INTEGER_64

-- 64-bit integer value
-- (From STRING_8)

require

is_integer_64: is_integer_64

to_integer_8: INTEGER_8

-- 8-bit integer value
-- (From STRING_8)

require

is_integer_8: is_integer_8

to_natural: NATURAL_32

-- 32-bit natural value
-- (From STRING_8)

require

is_natural: is_natural

to_natural_16: NATURAL_16

-- 16-bit natural value
-- (From STRING_8)

require

is_natural_16: is_natural_16

to_natural_32: NATURAL_32

-- 32-bit natural value
-- (From STRING_8)

require

is_natural: is_natural

to_natural_64: NATURAL_64

-- 64-bit natural value
-- (From STRING_8)

require

is_natural_64: is_natural_64

to_natural_8: NATURAL_8

-- 8-bit natural value
-- (From STRING_8)

require

is_natural_8: is_natural_8

to_real: REAL

-- Real value;
-- for example, when applied to "123.0", will yield 123.0
-- (From STRING_8)

require

represents_a_real: is_real

feature -- Duplication

multiply (n: INTEGER)

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

require

meaningful_multiplier: n >= 1

cloned_string: like Current

-- New object equal to Current

ensure

twin_not_void: Result /= Void
is_equal: Result.is_equal (Current)

copy (other: like Current)

-- Reinitialize by copying the characters of other.
-- (This is also used by clone.)
-- (ELKS 2001 STRING_8)
-- (From ANY)

require

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

ensure

is_equal: is_equal (other)

feature -- Basic operations

close

-- Try to close output stream if it is closable. Set
-- is_open_write to false if operation was successful.
-- (From KI_OUTPUT_STREAM)

require

is_closable: is_closable

feature {UC_STRING} -- Byte index cache

last_byte_index_input: INTEGER

-- Last byte_index requested
-- (Cache for 'i := i + 1' iterations and similar)

last_byte_index_result: INTEGER

-- Last byte_index Result
-- (Cache for 'i := i + 1' iterations and similar)

reset_byte_index_cache

-- Reset byte index (after write operation for example).

feature -- Correction

mismatch_information: MISMATCH_INFORMATION

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

feature -- Output

put_line (a_string: STRING)

-- Write a_string to output stream
-- followed by a line separator.
-- (From KI_TEXT_OUTPUT_STREAM)

require

is_open_write: is_open_write
a_string_not_void: a_string /= Void

put_new_line

-- Write a line separator to output stream.
-- (From KI_TEXT_OUTPUT_STREAM)

require

is_open_write: is_open_write

append_stream (an_input_stream: KI_INPUT_STREAM[CHARACTER])

-- Read items of an_input_stream until the end
-- of input is reached, and write these items to
-- current output stream.
-- (From KI_OUTPUT_STREAM)

require

is_open_write: is_open_write
an_input_stream_not_void: an_input_stream /= Void
an_input_stream_open_read: an_input_stream.is_open_read

ensure

end_of_input: an_input_stream.end_of_input

put_boolean (b: BOOLEAN)

-- Write "True" to output stream if
-- b is true, "False" otherwise.
-- (From KI_CHARACTER_OUTPUT_STREAM)

require

is_open_write: is_open_write

put_integer (i: INTEGER)

-- Write decimal representation
-- of i to output stream.
-- Regexp: 0|(-?[1-9][0-9]*)
-- (From KI_CHARACTER_OUTPUT_STREAM)

require

is_open_write: is_open_write

debug_output: STRING

-- String that should be displayed in debugger to represent Current.
-- (From DEBUG_OUTPUT)

ensure

result_not_void: Result /= Void

out: STRING

-- New STRING_8 containing terse printable representation
-- of current object; Non-ascii characters are represented
-- with the %/code/ convention.
-- (ELKS 2001 STRING_8)
-- (From ANY)

ensure then

out_not_void: Result /= Void
same_items: ANY_.same_types (Current, "") implies Result.same_string (current_string)

feature -- Output stream

eol: STRING

-- Line separator
-- (From KI_TEXT_OUTPUT_STREAM)

ensure

eol_not_void: Result /= Void
eol_not_empty: Result.count > 0

flush

-- Do nothing (operation does not apply to string).
-- (From KI_CHARACTER_OUTPUT_STREAM)

require

is_open_write: is_open_write

is_open_write: BOOLEAN

-- Can characters be written to output stream?
-- (From KI_OUTPUT_STREAM)

name: STRING

-- Name of output stream
-- (From KI_OUTPUT_STREAM)

ensure

name_not_void: Result /= Void

feature -- Traversal

byte_index (i: INTEGER): INTEGER

-- Byte index of character at index i

require

valid_index: valid_index (i)

ensure

byte_index_large_enough: Result >= 1
byte_index_small_enough: Result <= byte_count
is_encoded_first_byte: is_encoded_first_byte (Result)

character_item_at_byte_index (i: INTEGER): CHARACTER

-- Character at byte_index i;
-- '%U' is the unicode character at byte index
-- i cannot fit into a CHARACTER_8

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count
is_encoded_first_byte: is_encoded_first_byte (i)

ensure

code_small_enough: item_code_at_byte_index (i) <= Platform.Maximum_character_code implies Result.code = item_code_at_byte_index (i)
overflow: item_code_at_byte_index (i) > Platform.Maximum_character_code implies Result = '%U'

is_encoded_first_byte (i: INTEGER): BOOLEAN

-- Is byte at index i the first byte of an encoded unicode character?

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count

item_code_at_byte_index (i: INTEGER): INTEGER

-- Code of character at byte index i

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count
is_encoded_first_byte: is_encoded_first_byte (i)

ensure

valid_item_code: unicode.valid_code (Result)

next_byte_index (i: INTEGER): INTEGER

-- Byte index of unicode character after character
-- at byte index i; Return 'byte_count + 1' if
-- character at byte index i is the last character
-- in the string

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count
is_encoded_first_byte: is_encoded_first_byte (i)

ensure

next_byte_index_large_enough: Result > i
next_byte_index_small_enough: Result <= byte_count + 1

shifted_byte_index (i: INTEGER; n: INTEGER): INTEGER

-- Byte index of unicode character n positions after
-- character at byte index i; Return 'byte_count + 1'
-- if no such character in the string

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count
is_encoded_first_byte: is_encoded_first_byte (i)
n_positive: n >= 0

ensure

next_byte_index_large_enough: Result >= i
next_byte_index_small_enough: Result <= byte_count + 1

feature -- Obsolete

append_uc_character (c: UC_CHARACTER)

-- Append unicode character c at end.

obsolete

[020720] Use append_unicode_character instead.

require

c_not_void: c /= Void

append_uc_string (a_string: UC_STRING)

-- Append a copy of a_string at end.

obsolete

[011225] Use append_string instead.

require

a_string_not_void: a_string /= Void

append_unicode (c: UC_CHARACTER)

-- Append unicode character c at end.

obsolete

[020720] Use append_unicode_character instead.

require

c_not_void: c /= Void

empty: BOOLEAN

-- Is string empty?

obsolete

[011225] Use is_empty instead.

head (n: INTEGER)

-- Remove all the characters except for the first n;
-- if n > count, do nothing.
-- (From STRING_8)

obsolete

[020602] 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)))

insert_unicode (c: UC_CHARACTER; i: INTEGER)

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

obsolete

[020720] Use insert_unicode_character instead.

require

c_not_void: c /= Void
valid_insertion_index: 1 <= i and i <= count + 1

ensure

one_more_character: count = old count + 1
inserted: item_code (i) = c.code
stable_before_i: substring (1, i - 1).is_equal (old substring (1, i - 1))
stable_after_i: substring (i + 1, count).is_equal (old substring (i, count))

tail (n: INTEGER)

-- Remove all the characters except for the last n;
-- if n > count, do nothing.
-- (From STRING_8)

obsolete

[020602] 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))

platform_: KL_PLATFORM

-- Platform-dependent properties
-- (From KL_SHARED_PLATFORM)

obsolete

[040101] Use Platform instead.

ensure

platform_not_void: Result /= Void

feature {UC_STRING} -- Inapplicable

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)

code (i: INTEGER): NATURAL_32

-- Code at position i
-- (From STRING_GENERAL)

require

valid_index: valid_index (i)

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

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)

old_left_adjust

-- Remove leading whitespace.
-- (From STRING_8)

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

old_right_adjust

-- Remove trailing whitespace.
-- (From STRING_8)

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

put_code (v: like code; i: INTEGER)

-- Put code v at position i.
-- (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))

feature {STRING_HANDLER} -- Implementation

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

feature -- Implementation

current_any: ANY

-- Current any
-- (From KS_STRING)

ensure

definition: Result = Current

current_string: STRING

-- Current string
-- (From KS_STRING)

ensure

definition: Result = current_any

feature {UC_STRING_HANDLER} -- Implementation

byte_item (i: INTEGER): CHARACTER

-- Byte at index i

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count

move_bytes_left (i, offset: INTEGER)

-- Move bytes at and after position i
-- by offset positions to the left.

require

valid_index: 1 <= i and i <= byte_count + 1
positive_offset: offset >= 0
constraint: offset < i

ensure

byte_count_set: byte_count = old byte_count - offset

move_bytes_right (i, offset: INTEGER)

-- Move bytes at and after position i
-- by offset positions to the right.

require

valid_index: 1 <= i and i <= byte_count + 1
positive_offset: offset >= 0
offset_small_enough: offset <= (byte_capacity - byte_count)

ensure

byte_count_set: byte_count = old byte_count + offset

put_byte (c: CHARACTER; i: INTEGER)

-- Replace byte at index i by c.

require

i_large_enough: i >= 1
i_small_enough: i <= byte_count

resize_byte_storage (n: INTEGER)

-- Resize space for n bytes.
-- Do not lose previously stored bytes.

require

n_large_enough: n >= byte_capacity

ensure

byte_capacity_set: byte_capacity = n

set_byte_count (nb: INTEGER)

-- Set byte_count to nb.

require

nb_large_enough: nb >= 0
nb_small_enough: nb <= byte_capacity

ensure

byte_count_set: byte_count = nb

set_count (nb: INTEGER)

-- Set count to nb.

require

nb_positive: nb >= 0

ensure

count_set: count = nb

invariant

non_negative_byte_count: byte_count >= 0
byte_count_small_enough: byte_count <= byte_capacity
count_small_enough: count <= byte_count

-- From KS_STRING
non_negative_count: count >= 0

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

-- From KS_COMPARABLE

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

Documentation generated by edoc