Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
TextEncoder Class Reference

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

Inheritance diagram for TextEncoder:
TextNode FrameRateMeter SceneGraphAnalyzerMeter

Public Types

enum  Encoding { E_iso8859 = 0, E_utf8 = 1, E_unicode = 2 }
 

Public Member Functions

 __init__ ()
 
 __init__ (const TextEncoder copy)
 
 appendText (str text)
 Appends the indicates string to the end of the stored text. More...
 
 appendUnicodeChar (int character)
 Appends a single character to the end of the stored text. This may be a wide character, up to 16 bits in Unicode. More...
 
 appendWtext (str text)
 Appends the indicates string to the end of the stored wide-character text. More...
 
 clearText ()
 Removes the text from the TextEncoder. More...
 
str decodeText (str text)
 Returns the given wstring decoded to a single-byte string, via the current encoding system. More...
 
str encodeWtext (str wtext)
 Encodes a wide-text string into a single-char string, according to the current encoding. More...
 
str getEncodedChar (int index)
 Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string. More...
 
str getEncodedChar (int index, TextEncoder::Encoding encoding)
 Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string. More...
 
TextEncoder::Encoding getEncoding ()
 Returns the encoding by which the string set via set_text() is to be interpreted. See set_encoding(). More...
 
int getNumChars ()
 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(). More...
 
str getText ()
 Returns the current text, as encoded via the current encoding system. More...
 
str getText (TextEncoder::Encoding encoding)
 Returns the current text, as encoded via the indicated encoding system. More...
 
str getTextAsAscii ()
 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. More...
 
int getUnicodeChar (int index)
 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(). More...
 
str getWtext ()
 Returns the text associated with the TextEncoder, as a wide-character string. More...
 
str getWtextAsAscii ()
 
bool hasText ()
 
bool isWtext ()
 
 makeLower ()
 
 makeUpper ()
 
 setEncoding (TextEncoder::Encoding encoding)
 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. More...
 
 setText (str text)
 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. More...
 
 setText (str text, TextEncoder::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. Subsequent calls to get_text() will return the same text re-encoded using whichever encoding is specified by set_encoding(). More...
 
 setUnicodeChar (int index, int character)
 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(). More...
 
 setWtext (str wtext)
 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. More...
 

Static Public Member Functions

static str decodeText (str text, TextEncoder::Encoding encoding)
 
static str encodeWchar (wchar_t ch, TextEncoder::Encoding encoding)
 
static str encodeWtext (str wtext, TextEncoder::Encoding encoding)
 
static TextEncoder::Encoding getDefaultEncoding ()
 Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding(). More...
 
static str lower (str source)
 Converts the string to lowercase, assuming the string is encoded in the default encoding. More...
 
static str lower (str source, TextEncoder::Encoding encoding)
 Converts the string to lowercase, assuming the string is encoded in the indicated encoding. More...
 
static str reencodeText (str text, TextEncoder::Encoding from, TextEncoder::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. This does not change or affect any properties on the TextEncoder itself. More...
 
static setDefaultEncoding (TextEncoder::Encoding encoding)
 Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding(). More...
 
static bool unicodeIsalpha (int character)
 Returns true if the indicated character is an alphabetic letter, false otherwise. This is akin to ctype's isalpha(), extended to Unicode. More...
 
static bool unicodeIsdigit (int character)
 Returns true if the indicated character is a numeric digit, false otherwise. This is akin to ctype's isdigit(), extended to Unicode. More...
 
static bool unicodeIslower (int character)
 Returns true if the indicated character is a lowercase letter, false otherwise. This is akin to ctype's islower(), extended to Unicode. More...
 
static bool unicodeIspunct (int character)
 Returns true if the indicated character is a punctuation mark, false otherwise. This is akin to ctype's ispunct(), extended to Unicode. More...
 
static bool unicodeIsspace (int character)
 Returns true if the indicated character is a whitespace letter, false otherwise. This is akin to ctype's isspace(), extended to Unicode. More...
 
static bool unicodeIsupper (int character)
 Returns true if the indicated character is an uppercase letter, false otherwise. This is akin to ctype's isupper(), extended to Unicode. More...
 
static int unicodeTolower (int character)
 Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's tolower(), extended to Unicode. More...
 
static int unicodeToupper (int character)
 Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's toupper(), extended to Unicode. More...
 
static str upper (str source)
 Converts the string to uppercase, assuming the string is encoded in the default encoding. More...
 
static str upper (str source, TextEncoder::Encoding encoding)
 Converts the string to uppercase, assuming the string is encoded in the indicated encoding. More...
 

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.

Member Enumeration Documentation

◆ Encoding

enum Encoding
Enumerator
E_iso8859 
E_utf8 
E_unicode 

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

◆ __init__() [2/2]

__init__ ( const TextEncoder  copy)

◆ appendText()

appendText ( str  text)

Appends the indicates string to the end of the stored text.

◆ appendUnicodeChar()

appendUnicodeChar ( int  character)

Appends a single character to the end of the stored text. This may be a wide character, up to 16 bits in Unicode.

◆ appendWtext()

appendWtext ( str  text)

Appends the indicates string to the end of the stored wide-character text.

◆ clearText()

clearText ( )

Removes the text from the TextEncoder.

◆ decodeText() [1/2]

str decodeText ( str  text)

Returns the given wstring decoded to a single-byte string, via the current encoding system.

◆ decodeText() [2/2]

static str decodeText ( str  text,
TextEncoder::Encoding  encoding 
)
static

◆ encodeWchar()

static str encodeWchar ( wchar_t  ch,
TextEncoder::Encoding  encoding 
)
static

◆ encodeWtext() [1/2]

str encodeWtext ( str  wtext)

Encodes a wide-text string into a single-char string, according to the current encoding.

◆ encodeWtext() [2/2]

static str encodeWtext ( str  wtext,
TextEncoder::Encoding  encoding 
)
static

◆ getDefaultEncoding()

static TextEncoder::Encoding getDefaultEncoding ( )
static

Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding().

◆ getEncodedChar() [1/2]

str getEncodedChar ( int  index)

Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.

◆ getEncodedChar() [2/2]

str getEncodedChar ( int  index,
TextEncoder::Encoding  encoding 
)

Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.

◆ getEncoding()

TextEncoder::Encoding getEncoding ( )

Returns the encoding by which the string set via set_text() is to be interpreted. See set_encoding().

◆ getNumChars()

int getNumChars ( )

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() [1/2]

str getText ( )

Returns the current text, as encoded via the current encoding system.

◆ getText() [2/2]

str getText ( TextEncoder::Encoding  encoding)

Returns the current text, as encoded via the indicated encoding system.

◆ getTextAsAscii()

str getTextAsAscii ( )

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 getUnicodeChar ( int  index)

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

str getWtext ( )

Returns the text associated with the TextEncoder, as a wide-character string.

◆ getWtextAsAscii()

str getWtextAsAscii ( )

◆ hasText()

bool hasText ( )

◆ isWtext()

bool isWtext ( )

◆ lower() [1/2]

static str lower ( str  source)
static

Converts the string to lowercase, assuming the string is encoded in the default encoding.

◆ lower() [2/2]

static str lower ( str  source,
TextEncoder::Encoding  encoding 
)
static

Converts the string to lowercase, assuming the string is encoded in the indicated encoding.

◆ makeLower()

makeLower ( )

◆ makeUpper()

makeUpper ( )

◆ reencodeText()

static str reencodeText ( str  text,
TextEncoder::Encoding  from,
TextEncoder::Encoding  to 
)
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.

◆ setDefaultEncoding()

static setDefaultEncoding ( TextEncoder::Encoding  encoding)
static

Specifies the default encoding to be used for all subsequently created TextEncoder objects. See set_encoding().

◆ setEncoding()

setEncoding ( TextEncoder::Encoding  encoding)

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() [1/2]

setText ( str  text)

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.

◆ setText() [2/2]

setText ( str  text,
TextEncoder::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. Subsequent calls to get_text() will return the same text re-encoded using whichever encoding is specified by set_encoding().

◆ setUnicodeChar()

setUnicodeChar ( int  index,
int  character 
)

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

setWtext ( str  wtext)

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 unicodeIsalpha ( int  character)
static

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 unicodeIsdigit ( int  character)
static

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 unicodeIslower ( int  character)
static

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 unicodeIspunct ( int  character)
static

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 unicodeIsspace ( int  character)
static

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 unicodeIsupper ( int  character)
static

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 unicodeTolower ( int  character)
static

Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's tolower(), extended to Unicode.

◆ unicodeToupper()

static int unicodeToupper ( int  character)
static

Returns the uppercase equivalent of the given Unicode character. This is akin to ctype's toupper(), extended to Unicode.

◆ upper() [1/2]

static str upper ( str  source)
static

Converts the string to uppercase, assuming the string is encoded in the default encoding.

◆ upper() [2/2]

static str upper ( str  source,
TextEncoder::Encoding  encoding 
)
static

Converts the string to uppercase, assuming the string is encoded in the indicated encoding.