|
|
|
This class can be used to convert text between multiple representations, e.g.
More...
#include "textEncoder.h"
List of all members.
Public Types |
| enum | Encoding { E_iso8859,
E_utf8,
E_unicode
} |
Public Member Functions |
|
| TextEncoder (const TextEncoder ©) |
| void | append_text (const string &text) |
| | Appends the indicates string to the end of the stored text.
|
| void | append_unicode_char (int character) |
| | Appends a single character to the end of the stored text.
|
| void | append_wtext (const wstring &text) |
| | Appends the indicates string to the end of the stored wide-character text.
|
| void | clear_text () |
| | Removes the text from the TextEncoder.
|
| wstring | decode_text (const string &text) const |
| | Returns the given wstring decoded to a single-byte string, via the current encoding system.
|
| string | encode_wtext (const wstring &wtext) const |
| | Encodes a wide-text string into a single-char string, according to the current encoding.
|
| string | get_encoded_char (int index) const |
| | Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.
|
| string | get_encoded_char (int index, Encoding encoding) const |
| | Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.
|
| Encoding | get_encoding () const |
| | Returns the encoding by which the string set via set_text() is to be interpreted.
|
| int | get_num_chars () const |
| | Returns the number of characters in the stored text.
|
| string | get_text () const |
| | Returns the current text, as encoded via the current encoding system.
|
| string | get_text (Encoding encoding) const |
| | Returns the current text, as encoded via the indicated encoding system.
|
| string | get_text_as_ascii () const |
| | Returns the text associated with the node, converted as nearly as possible to a fully-ASCII representation.
|
| int | get_unicode_char (int index) const |
| | Returns the Unicode value of the nth character in the stored text.
|
| const wstring & | get_wtext () const |
| | Returns the text associated with the TextEncoder, as a wide-character string.
|
| wstring | get_wtext_as_ascii () const |
| | Returns the text associated with the node, converted as nearly as possible to a fully-ASCII representation.
|
|
bool | has_text () const |
| bool | is_wtext () const |
| | Returns true if any of the characters in the string returned by get_wtext() are out of the range of an ASCII character (and, therefore, get_wtext() should be called in preference to get_text()).
|
| void | make_lower () |
| | Adjusts the text stored within the encoder to all lowercase letters (preserving accent marks correctly).
|
| void | make_upper () |
| | Adjusts the text stored within the encoder to all uppercase letters (preserving accent marks correctly).
|
| void | set_encoding (Encoding encoding) |
| | Specifies how the string set via set_text() is to be interpreted.
|
| void | set_text (const string &text) |
| | Changes the text that is stored in the encoder.
|
| void | set_text (const string &text, Encoding encoding) |
| | The two-parameter version of set_text() accepts an explicit encoding; the text is immediately decoded and stored as a wide-character string.
|
| void | set_unicode_char (int index, int character) |
| | Sets the Unicode value of the nth character in the stored text.
|
| void | set_wtext (const wstring &wtext) |
| | Changes the text that is stored in the encoder.
|
Static Public Member Functions |
| static wstring | decode_text (const string &text, Encoding encoding) |
| | Returns the given wstring decoded to a single-byte string, via the given encoding system.
|
| static string | encode_wchar (wchar_t ch, Encoding encoding) |
| | Encodes a single wide char into a one-, two-, or three-byte string, according to the given encoding system.
|
| static string | encode_wtext (const wstring &wtext, Encoding encoding) |
| | Encodes a wide-text string into a single-char string, according to the given encoding.
|
| static Encoding | get_default_encoding () |
| | Specifies the default encoding to be used for all subsequently created TextEncoder objects.
|
| static string | lower (const string &source) |
| | Converts the string to lowercase, assuming the string is encoded in the default encoding.
|
| static string | lower (const string &source, Encoding encoding) |
| | Converts the string to lowercase, assuming the string is encoded in the indicated encoding.
|
| static string | reencode_text (const string &text, Encoding from, Encoding to) |
| | Given the indicated text string, which is assumed to be encoded via the encoding "from", decodes it and then reencodes it into the encoding "to", and returns the newly encoded string.
|
| static void | set_default_encoding (Encoding encoding) |
| | Specifies the default encoding to be used for all subsequently created TextEncoder objects.
|
| static bool | unicode_isalpha (int character) |
| | Returns true if the indicated character is an alphabetic letter, false otherwise.
|
| static bool | unicode_isdigit (int character) |
| | Returns true if the indicated character is a numeric digit, false otherwise.
|
| static bool | unicode_islower (int character) |
| | Returns true if the indicated character is a lowercase letter, false otherwise.
|
| static bool | unicode_ispunct (int character) |
| | Returns true if the indicated character is a punctuation mark, false otherwise.
|
| static bool | unicode_isspace (int character) |
| | Returns true if the indicated character is a whitespace letter, false otherwise.
|
| static bool | unicode_isupper (int character) |
| | Returns true if the indicated character is an uppercase letter, false otherwise.
|
| static int | unicode_tolower (int character) |
| | Returns the uppercase equivalent of the given Unicode character.
|
| static int | unicode_toupper (int character) |
| | Returns the uppercase equivalent of the given Unicode character.
|
| static string | upper (const string &source) |
| | Converts the string to uppercase, assuming the string is encoded in the default encoding.
|
| static string | upper (const string &source, Encoding encoding) |
| | Converts the string to uppercase, assuming the string is encoded in the indicated encoding.
|
Detailed Description
This class can be used to convert text between multiple representations, e.g.
utf-8 to Unicode. You may use it as a static class object, passing the encoding each time, or you may create an instance and use that object, which will record the current encoding and retain the current string.
This class is also a base class of TextNode, which inherits this functionality.
Definition at line 37 of file textEncoder.h.
Member Function Documentation
Appends a single character to the end of the stored text.
This may be a wide character, up to 16 bits in Unicode.
Definition at line 206 of file textEncoder.I.
References get_wtext().
Returns the given wstring decoded to a single-byte string, via the given encoding system.
Definition at line 200 of file textEncoder.cxx.
Encodes a wide-text string into a single-char string, according to the given encoding.
Definition at line 183 of file textEncoder.cxx.
References encode_wchar().
Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.
Definition at line 264 of file textEncoder.I.
References get_encoding().
Returns the number of characters in the stored text.
This is a count of wide characters, after the string has been decoded according to set_encoding().
Definition at line 219 of file textEncoder.I.
References get_wtext().
Returns the text associated with the node, converted as nearly as possible to a fully-ASCII representation.
This means replacing accented letters with their unaccented ASCII equivalents.
It is possible that some characters in the string cannot be converted to ASCII. (The string may involve symbols like the copyright symbol, for instance, or it might involve letters in some other alphabet such as Greek or Cyrillic, or even Latin letters like thorn or eth that are not part of the ASCII character set.) In this case, as much of the string as possible will be converted to ASCII, and the nonconvertible characters will remain encoded in the encoding specified by set_encoding().
Definition at line 300 of file textEncoder.I.
References encode_wtext(), and get_wtext_as_ascii().
Returns the text associated with the TextEncoder, as a wide-character string.
Definition at line 530 of file textEncoder.I.
References decode_text().
Referenced by append_unicode_char(), append_wtext(), PNMTextMaker::calc_width(), PNMTextMaker::generate_into(), Filename::get_fullpath_w(), get_num_chars(), get_text(), get_unicode_char(), get_wtext_as_ascii(), is_wtext(), make_lower(), make_upper(), set_encoding(), and set_unicode_char().
Returns the text associated with the node, converted as nearly as possible to a fully-ASCII representation.
This means replacing accented letters with their unaccented ASCII equivalents.
It is possible that some characters in the string cannot be converted to ASCII. (The string may involve symbols like the copyright symbol, for instance, or it might involve letters in some other alphabet such as Greek or Cyrillic, or even Latin letters like thorn or eth that are not part of the ASCII character set.) In this case, as much of the string as possible will be converted to ASCII, and the nonconvertible characters will remain in their original form.
Definition at line 76 of file textEncoder.cxx.
References get_wtext(), and UnicodeLatinMap::look_up().
Referenced by get_text_as_ascii().
| string TextEncoder::lower |
( |
const string & |
source, |
|
|
TextEncoder::Encoding |
encoding |
|
) |
| [inline, static] |
Given the indicated text string, which is assumed to be encoded via the encoding "from", decodes it and then reencodes it into the encoding "to", and returns the newly encoded string.
This does not change or affect any properties on the TextEncoder itself.
Definition at line 314 of file textEncoder.I.
References decode_text(), and encode_wtext().
Specifies how the string set via set_text() is to be interpreted.
The default, E_iso8859, means a standard string with one-byte characters (i.e. ASCII). Other encodings are possible to take advantage of character sets with more than 256 characters.
This affects only future calls to set_text(); it does not change text that was set previously.
Definition at line 59 of file textEncoder.I.
References get_text(), and get_wtext().
Referenced by Filename::get_fullpath_w(), lower(), and upper().
Sets the Unicode value of the nth character in the stored text.
This may be a wide character (greater than 255), after the string has been decoded according to set_encoding().
Definition at line 249 of file textEncoder.I.
References get_wtext().
Returns true if the indicated character is an alphabetic letter, false otherwise.
This is akin to ctype's isalpha(), extended to Unicode.
Definition at line 327 of file textEncoder.I.
References UnicodeLatinMap::look_up().
Returns true if the indicated character is a numeric digit, false otherwise.
This is akin to ctype's isdigit(), extended to Unicode.
Definition at line 344 of file textEncoder.I.
References UnicodeLatinMap::look_up().
Returns true if the indicated character is a lowercase letter, false otherwise.
This is akin to ctype's islower(), extended to Unicode.
Definition at line 415 of file textEncoder.I.
References UnicodeLatinMap::look_up().
Returns true if the indicated character is a punctuation mark, false otherwise.
This is akin to ctype's ispunct(), extended to Unicode.
Definition at line 362 of file textEncoder.I.
References UnicodeLatinMap::look_up().
Returns true if the indicated character is a whitespace letter, false otherwise.
This is akin to ctype's isspace(), extended to Unicode.
Definition at line 395 of file textEncoder.I.
Returns true if the indicated character is an uppercase letter, false otherwise.
This is akin to ctype's isupper(), extended to Unicode.
Definition at line 379 of file textEncoder.I.
References UnicodeLatinMap::look_up().
| string TextEncoder::upper |
( |
const string & |
source, |
|
|
TextEncoder::Encoding |
encoding |
|
) |
| [inline, static] |
The documentation for this class was generated from the following files:
| | |