AdaCL.EAstrings
More...Entities
Constants and variables
Simple types
Access types
Record types
Subprograms
Nested packages
Description
EAstring - encoding-aware string - is a dynamic string type similar to
Ada.Strings.Unbounded.Unbounded_String, but it handles strings in all
character encodings and frees you from character encoding troubles. It
keeps track of how each string is encoded and transcodes them
automatically when necessary.
The child packages Latin_1 and UCS_2 contain subprograms for using
EAstrings together with Ada's standard string types. Latin_1 is for
String and Unbounded_String, and UCS_2 is for Wide_String and
Unbounded_Wide_String.
The child package IO provides encoding-aware input and output.
The child package OS and its descendants provide encoding-aware access
to information from the environment.
The procedures and functions that manipulate EAstrings will transcode
them as needed. The procedures may change the encoding of their
parameters when these are declared "in out". The functions will leave
their parameters unchanged but may return EAstrings in other encodings.
There are also subprograms available that allow for explicit
transcoding (Transcode and Convert). In most cases it should not be
necessary to use them, but if you need to convert an EAstring to a byte
sequence in a particular encoding you should call Transcode to make
sure that it is in the right encoding, and then retrieve the byte
sequence with Bytes. You may also want to call Transcode for
performance reasons in certain cases. A series of function calls may
lead to the same string being transcoded over and over, and this can be
prevented by explicitly transcoding it first.
The first character in an EAstring always has the index 1.
In this package, a character is a Unicode code point; not a byte, a
code unit or a grapheme. In some encodings, a code unit is one byte. In
others it's two or four bytes. In some encodings, one character (code
point) can be encoded in several code units. A grapheme can be
represented as one character or as a base character followed by one or
more combining characters. Most of the subprograms in this package
count, compare and process code points. A few deal with bytes.
Througout the EAstrings library, it is assumed that a byte is eight
bits.
111 | Null_Converter : constant Converter; |
---|
720 | Null_Sequence : aliased Byte_Sequence := [1 .. 0 => 0]; |
---|
88 | type Byte_Sequence is |
---|
89 | array (Positive range <>) of aliased Interfaces.Unsigned_8; |
---|
Conversion_Stop_Cause [source]
Reason why Convert returns.
All_Done : The whole input string was converted.
Target_Full : There isn't enough room in the target.
Incomplete : The source ends in an incomplete code sequence.
Inconvertible : One of these errors happened:
1 | 1: The source isn't a valid encoded string for the |
---|
2 | source encoding. |
---|
3 | 2: The source contains a character that can't be |
---|
4 | represented in the target encoding. |
---|
- All_Done
- Target_Full
- Incomplete
- Inconvertible
Byte_Sequence_Access [source]
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | Null_EAstring : constant EAstring; |
---|
Null_String_Encoding [source]
The null string is set to the least demanding encoding to avoid
unnecessarily transcoding other strings.
Concatenates two EAstrings.
- Left of type AdaCL.EAstrings.EAstring
- Right of type AdaCL.EAstrings.EAstring
- Return value
Returns an EAstring that comprises Left concatenated copies of Right.
- Left of type Natural
- Right of type AdaCL.EAstrings.EAstring
- Return value
Returns True if and only if Left and Right contain identical sequences
of characters (regardless of their current encodings).
- Left of type AdaCL.EAstrings.EAstring
- Right of type AdaCL.EAstrings.EAstring
- Return value
- Object of type AdaCL.EAstrings.EAstring
Appends New_Item to the end of Source.
- Source of type AdaCL.EAstrings.EAstring
- New_Item of type AdaCL.EAstrings.EAstring
Byte_Sequence_To_Fake_String [source]
Unchecked conversion of Byte_Sequence to String. The result will not be
a real String (unless the byte sequence happens to be in Latin 1). For
passing strings to functions that take String parameters but interpret
them as some other encoding.
- Source of type AdaCL.EAstrings.Byte_Sequence
- Return value
Returns the byte sequence that an EAstring is encoded as in its current
encoding.
- Source of type AdaCL.EAstrings.EAstring
- Return value
Frees a converter object allocated by Open_Converter.
- Item of type AdaCL.EAstrings.Converter
State must be a converter object allocated by Open_Converter. Source
must be a string encoded in the encoding that this converter converts
from. The string is converted and stored in Target. The indices in
Source and in Target of the last byte of the last character that was
converted are stored in Source_Last and Target_Last, respectively. The
reason why Convert stopped is reported in Cause.
- State of type AdaCL.EAstrings.Converter
- Source of type AdaCL.EAstrings.Byte_Sequence
- Target of type AdaCL.EAstrings.Byte_Sequence
- Source_Last of type Natural
- Target_Last of type Natural
- Cause of type AdaCL.EAstrings.Conversion_Stop_Cause
Returns the maximum number of nonoverlapping slices of Source that
match Pattern with respect to Mapping. If Pattern is the null string
then Pattern_Error is propagated.
- Source of type AdaCL.EAstrings.EAstring
- Pattern of type AdaCL.EAstrings.EAstring
- Return value
Returns Replace_Slice(Source, From, Through, Null_EAstring).
- Source of type AdaCL.EAstrings.EAstring
- From of type Positive
- Through of type Natural
- Return value
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- From of type Positive
- Through of type Natural
Returns the encoding that an EAstring is currently encoded in.
- Source of type AdaCL.EAstrings.EAstring
- Return value
Fake_String_To_Byte_Sequence [source]
Unchecked conversion of String to Byte_Sequence. For making EAstrings
from objects that are declared as String but contain some other
encoding than Latin 1.
- Source of type String
- Return value
- Object of type AdaCL.EAstrings.EAstring
Returns an EAstring of length Count. If Count <= Length(Source), the
string comprises the first Count characters of Source. Otherwise its
contents are Source concatenated with Count - Length(Source) spaces.
- Source of type AdaCL.EAstrings.EAstring
- Count of type Natural
- Return value
"Pad : in Unicode_Character := Space" to be added later.
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Count of type Natural
Searches for a slice of Source, with the same length as Pattern, that
matches Pattern with respect to Mapping. The parameter Going indicates
the direction of the lookup. Index returns the smallest (if Going =
Forward) or largest (if Going = Backward) index I such that the slice
of Source starting at I matches Pattern. If there is no such slice,
then 0 is returned. If Pattern is the null string then Pattern_Error is
propagated.
- Source of type AdaCL.EAstrings.EAstring
- Pattern of type AdaCL.EAstrings.EAstring
- Going of type Direction
- Return value
Returns the index of the first (if Going = Forward) or last (if Going =
Backward) character in Source that is not a space (U+0020). If there is
no such character, then 0 is returned.
- Source of type AdaCL.EAstrings.EAstring
- Going of type Direction
- Return value
- Object of type AdaCL.EAstrings.EAstring
Propagates Index_Error if Before > Length(Source)+1; otherwise returns
Slice(Source, 1, Before-1) & New_Item & Slice(Source, Before,
Length(Source)).
- Source of type AdaCL.EAstrings.EAstring
- Before of type Positive
- New_Item of type AdaCL.EAstrings.EAstring
- Return value
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Before of type Positive
- New_Item of type AdaCL.EAstrings.EAstring
Returns the number of characters in the string. (This is not the same
as the space it will take when printed, even in a fixed-width font.)
This may be a more expensive operation than one might think, because if
the string is in a variable-width encoding, a copy of it must be
converted to a fixed-width encoding before the characters can be
counted.
- Source of type AdaCL.EAstrings.EAstring
- Return value
Returns a freshly allocated converter object that converts text from
the encoding given in From to the one in To. The converter must be
freed with Close_Converter. Unsupported_Conversion is raised if the
operating system doesn't support this conversion.
- From of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
- To of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
- Return value
Propagates Index_Error if Position > Length(Source)+1; otherwise
returns the string obtained from Source by consecutively replacing
characters starting at Position with corresponding characters from
New_Item. If the end of Source is reached before the characters in
New_Item are exhausted, the remaining characters from New_Item are
appended to the string.
- Source of type AdaCL.EAstrings.EAstring
- Position of type Positive
- New_Item of type AdaCL.EAstrings.EAstring
- Return value
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Position of type Positive
- New_Item of type AdaCL.EAstrings.EAstring
Realloc_For_Chunk [source]
- Source of type AdaCL.EAstrings.EAstring
- Chunk_Size of type Natural
If Low > Length(Source)+1, then Index_Error is propagated. Otherwise: �
If High >= Low, then the returned string comprises
Slice(Source, 1, Low-1) & By & Slice(Source, High+1, Length(Source)).
� If High < Low, then the returned string is Insert(Source, Low, By).
- Source of type AdaCL.EAstrings.EAstring
- Low of type Positive
- High of type Natural
- By of type AdaCL.EAstrings.EAstring
- Return value
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Low of type Positive
- High of type Natural
- By of type AdaCL.EAstrings.EAstring
Resets a converter object to its initial state.
- Item of type AdaCL.EAstrings.Converter
Returns the number of bytes in the byte sequence that the string is
currently encoded as.
- Source of type AdaCL.EAstrings.EAstring
- Return value
Slice returns the characters Low through High in Source. It returns
Null_EAstring if Low > High, and raises Index_Error if Low <= High and
High > Length(Source).
- Source of type AdaCL.EAstrings.EAstring
- Low of type Positive
- High of type Natural
- Return value
Returns an EAstring of length Count. If Count <= Length(Source), the
string comprises the last Count characters of Source. Otherwise its
contents are Count - Length(Source) spaces concatenated with Source.
- Source of type AdaCL.EAstrings.EAstring
- Count of type Natural
- Return value
"Pad : in Unicode_Character := Space" to be added later.
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Count of type Natural
Returns a string of Length spaces.
- Length of type Natural
- Return value
Constructs an EAstring from a byte sequence and a character encoding.
Source had better be a valid encoded text in Encoding.
- Source of type AdaCL.EAstrings.Byte_Sequence
- Encoding of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
- Return value
Returns a copy of Source encoded in New_Encoding.
- Source of type AdaCL.EAstrings.EAstring
- New_Encoding of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
- Return value
Makes sure that Source is encoded in New_Encoding.
- Source of type AdaCL.EAstrings.EAstring
- New_Encoding of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
Returns a copy of Source where each string is encoded in New_Encoding.
- Source of type AdaCL.EAstrings.EAstring_Array
- New_Encoding of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
- Return value
Makes sure that each string in Source is encoded in New_Encoding.
- Source of type AdaCL.EAstrings.EAstring_Array
- New_Encoding of type AdaCL.EAstrings.Character_Encodings.Character_Encoding
Returns the EAstring obtained by removing from Source all leading (if
Side = Left), trailing (if Side = Right), or leading and trailing (if
Side = Both) space characters (U+0020).
- Source of type AdaCL.EAstrings.EAstring
- Side of type Trim_End
- Return value
Like above, but changes Source instead of returning a new string.
- Source of type AdaCL.EAstrings.EAstring
- Side of type Trim_End