# TextEncoder

from pandac.PandaModules import TextEncoder

Class : TextEncoder
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.

## Inheritance:

TextEncoder:

## Methods of TextEncoder:

appendText
appendUnicodeChar
appendWtext
clearText
decodeText
encodeWchar
encodeWtext
getClassType
getDefaultEncoding
getEncodedChar
getEncoding
getNumChars
getText
getTextAsAscii
getUnicodeChar
getWtext
getWtextAsAscii
hasText
isWtext
lower
makeLower
makeUpper
reencodeText
setDefaultEncoding
setEncoding
setText
setUnicodeChar
setWtext
unicodeIsalpha
unicodeIsdigit
unicodeIslower
unicodeIspunct
unicodeIsspace
unicodeIsupper
unicodeTolower
unicodeToupper
upper

## Constants in TextEncoder:

EIso8859 | (Encoding)
EUtf8 | (Encoding)
EUnicode | (Encoding)

appendText void TextEncoder::append_text(string const &text); Description: Appends the indicates string to the end of the stored text.

appendUnicodeChar void TextEncoder::append_unicode_char(int character); Description: Appends a single character to the end of the stored text. This may be a wide character, up to 16 bits in Unicode.

appendWtext void TextEncoder::append_wtext(basic_string< wchar_t > const &text); Description: Appends the indicates string to the end of the stored wide-character text.

clearText void TextEncoder::clear_text(void); Description: Removes the text from the TextEncoder.

decodeText basic_string< wchar_t > TextEncoder::decode_text(string const &text) const; Description: Returns the given wstring decoded to a single-byte string, via the current encoding system. Description: Returns the given wstring decoded to a single-byte string, via the given encoding system.

encodeWchar static string TextEncoder::encode_wchar(wchar_t ch, TextEncoder::Encoding encoding); Description: Encodes a single wide char into a one-, two-, or three-byte string, according to the given encoding system.

encodeWtext string TextEncoder::encode_wtext(basic_string< wchar_t > const &wtext) const; Description: Encodes a wide-text string into a single-char string, according to the current encoding. Description: Encodes a wide-text string into a single-char string, according to the given encoding.

getClassType static TypeHandle TextEncoder::get_class_type(void); Undocumented function.

getDefaultEncoding static TextEncoder::Encoding TextEncoder::get_default_encoding(void); Description: Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding().

getEncodedChar string TextEncoder::get_encoded_char(int index) const; Description: Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.

getEncoding TextEncoder::Encoding TextEncoder::get_encoding(void) const; Description: Returns the encoding by which the string set via set_text() is to be interpreted. See set_encoding().

getNumChars int TextEncoder::get_num_chars(void) const; Description: 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().

getText string TextEncoder::get_text(void) const; Description: Returns the current text, as encoded via the current encoding system. Description: Returns the current text, as encoded via the indicated encoding system.

getTextAsAscii string TextEncoder::get_text_as_ascii(void) const; Description: 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().

getUnicodeChar int TextEncoder::get_unicode_char(int index) const; Description: Returns 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().

getWtext basic_string< wchar_t > const &TextEncoder::get_wtext(void) const; Direct support for wide-character strings. Now publishable with the new wstring support in interrogate. Description: Returns the text associated with the TextEncoder, as a wide-character string.

getWtextAsAscii basic_string< wchar_t > TextEncoder::get_wtext_as_ascii(void) const; Description: 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.

hasText bool TextEncoder::has_text(void) const; Description:

isWtext bool TextEncoder::is_wtext(void) const; Description: 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()).

lower static string TextEncoder::lower(string const &source); Description: Converts the string to lowercase, assuming the string is encoded in the default encoding. Description: Converts the string to lowercase, assuming the string is encoded in the indicated encoding.

makeLower void TextEncoder::make_lower(void); Description: Adjusts the text stored within the encoder to all lowercase letters (preserving accent marks correctly).

makeUpper void TextEncoder::make_upper(void); Description: Adjusts the text stored within the encoder to all uppercase letters (preserving accent marks correctly).

reencodeText static string TextEncoder::reencode_text(string const &text, TextEncoder::Encoding from, TextEncoder::Encoding to); Description: 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.

setDefaultEncoding static void TextEncoder::set_default_encoding(TextEncoder::Encoding encoding); Description: Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding().

setEncoding void TextEncoder::set_encoding(TextEncoder::Encoding encoding); Description: 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.

setText void TextEncoder::set_text(string const &text); Description: Changes the text that is stored in the encoder. The text should be encoded according to the method indicated by set_encoding(). Subsequent calls to get_text() will return this same string, while get_wtext() will return the decoded version of the string. Description: The two-parameter version of set_text() accepts an explicit encoding; the text is immediately decoded and stored as a wide-character string. Subsequent calls to get_text() will return the same text re-encoded using whichever encoding is specified by set_encoding().

setUnicodeChar void TextEncoder::set_unicode_char(int index, int character); Description: 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().

setWtext void TextEncoder::set_wtext(basic_string< wchar_t > const &wtext); Direct support for wide-character strings. Now publishable with the new wstring support in interrogate. Description: Changes the text that is stored in the encoder. Subsequent calls to get_wtext() will return this same string, while get_text() will return the encoded version of the string.

unicodeIsalpha static bool TextEncoder::unicode_isalpha(int character); Description: Returns true if the indicated character is an alphabetic letter, false otherwise. This is akin to ctype's isalpha(), extended to Unicode.

unicodeIsdigit static bool TextEncoder::unicode_isdigit(int character); Description: Returns true if the indicated character is a numeric digit, false otherwise. This is akin to ctype's isdigit(), extended to Unicode.

unicodeIslower static bool TextEncoder::unicode_islower(int character); Description: Returns true if the indicated character is a lowercase letter, false otherwise. This is akin to ctype's islower(), extended to Unicode.

unicodeIspunct static bool TextEncoder::unicode_ispunct(int character); Description: Returns true if the indicated character is a punctuation mark, false otherwise. This is akin to ctype's ispunct(), extended to Unicode.

unicodeIsspace static bool TextEncoder::unicode_isspace(int character); Description: Returns true if the indicated character is a whitespace letter, false otherwise. This is akin to ctype's isspace(), extended to Unicode.

unicodeIsupper static bool TextEncoder::unicode_isupper(int character); Description: Returns true if the indicated character is an uppercase letter, false otherwise. This is akin to ctype's isupper(), extended to Unicode.

unicodeTolower static int TextEncoder::unicode_tolower(int character); Description: Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's tolower(), extended to Unicode.

unicodeToupper static int TextEncoder::unicode_toupper(int character); Description: Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's toupper(), extended to Unicode.

upper static string TextEncoder::upper(string const &source); Description: Converts the string to uppercase, assuming the string is encoded in the default encoding. Description: Converts the string to uppercase, assuming the string is encoded in the indicated encoding.