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

This class can be used to convert text between multiple representations, e.g. More...

Inheritance diagram for TextEncoder:
TextNode FrameRateMeter SceneGraphAnalyzerMeter

Public Types

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

Public Member Functions

 __init__ ()
 
 __init__ (const TextEncoder copy)
 
 appendText (object text)
 
 appendUnicodeChar (char32_t character)
 Appends a single character to the end of the stored text. 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...
 
object decodeText (object text)
 
object 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. More...
 
int getNumChars ()
 Returns the number of characters in the stored text. More...
 
object getText ()
 Returns the current text, as encoded via the current encoding system. More...
 
object 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. More...
 
int getUnicodeChar (int index)
 Returns the Unicode value of the nth character in the stored text. More...
 
str getWtext ()
 Returns the text associated with the TextEncoder, as a wide-character string. More...
 
str getWtextAsAscii ()
 Returns the text associated with the node, converted as nearly as possible to a fully-ASCII representation. More...
 
bool hasText ()
 
bool isWtext ()
 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()). More...
 
 makeLower ()
 Adjusts the text stored within the encoder to all lowercase letters (preserving accent marks correctly). More...
 
 makeUpper ()
 Adjusts the text stored within the encoder to all uppercase letters (preserving accent marks correctly). More...
 
 setEncoding (TextEncoder::Encoding encoding)
 Specifies how the string set via set_text() is to be interpreted. More...
 
 setText (object text)
 
 setText (object text, TextEncoder::Encoding encoding)
 
 setUnicodeChar (int index, char32_t character)
 Sets the Unicode value of the nth character in the stored text. More...
 
 setWtext (str wtext)
 Changes the text that is stored in the encoder. More...
 

Static Public Member Functions

static object decodeText (object text, TextEncoder::Encoding encoding)
 
static object encodeWchar (char32_t ch, TextEncoder::Encoding encoding)
 Encodes a single Unicode character into a one-, two-, three-, or four-byte string, according to the given encoding system. More...
 
static object encodeWtext (str wtext, TextEncoder::Encoding encoding)
 Encodes a wide-text string into a single-char string, according to the given encoding. More...
 
static TextEncoder::Encoding getDefaultEncoding ()
 Specifies the default encoding to be used for all subsequently created TextEncoder objects. 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. More...
 
static setDefaultEncoding (TextEncoder::Encoding encoding)
 Specifies the default encoding to be used for all subsequently created TextEncoder objects. More...
 
static bool unicodeIsalpha (char32_t character)
 Returns true if the indicated character is an alphabetic letter, false otherwise. More...
 
static bool unicodeIsdigit (char32_t character)
 Returns true if the indicated character is a numeric digit, false otherwise. More...
 
static bool unicodeIslower (char32_t character)
 Returns true if the indicated character is a lowercase letter, false otherwise. More...
 
static bool unicodeIspunct (char32_t character)
 Returns true if the indicated character is a punctuation mark, false otherwise. More...
 
static bool unicodeIsspace (char32_t character)
 Returns true if the indicated character is a whitespace letter, false otherwise. More...
 
static bool unicodeIsupper (char32_t character)
 Returns true if the indicated character is an uppercase letter, false otherwise. More...
 
static int unicodeTolower (char32_t character)
 Returns the uppercase equivalent of the given Unicode character. More...
 
static int unicodeToupper (char32_t character)
 Returns the uppercase equivalent of the given Unicode character. 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...
 

Public Attributes

TextEncoder::Encoding default_encoding
 Specifies the default encoding to be used for all subsequently created TextEncoder objects. More...
 
object text
 Returns the current text, as encoded via the current encoding system. More...
 

Detailed Description

This class can be used to convert text between multiple representations, e.g.

UTF-8 to UTF-16. 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_utf16be 
E_unicode 

Deprecated alias for E_utf16be.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

◆ __init__() [2/2]

__init__ ( const TextEncoder  copy)

◆ appendText()

appendText ( object  text)

◆ appendUnicodeChar()

appendUnicodeChar ( char32_t  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]

object decodeText ( object  text)

◆ decodeText() [2/2]

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

◆ encodeWchar()

static object encodeWchar ( char32_t  ch,
TextEncoder::Encoding  encoding 
)
static

Encodes a single Unicode character into a one-, two-, three-, or four-byte string, according to the given encoding system.

◆ encodeWtext() [1/2]

object encodeWtext ( str  wtext)

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

◆ encodeWtext() [2/2]

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

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

◆ 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]

object getText ( )

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

◆ getText() [2/2]

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

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

◆ isWtext()

bool isWtext ( )

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

Adjusts the text stored within the encoder to all lowercase letters (preserving accent marks correctly).

◆ makeUpper()

makeUpper ( )

Adjusts the text stored within the encoder to all uppercase letters (preserving accent marks correctly).

◆ 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 ( object  text)

◆ setText() [2/2]

setText ( object  text,
TextEncoder::Encoding  encoding 
)

◆ setUnicodeChar()

setUnicodeChar ( int  index,
char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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 ( char32_t  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.

Member Data Documentation

◆ default_encoding

TextEncoder::Encoding default_encoding

Specifies the default encoding to be used for all subsequently created TextEncoder objects.

See set_encoding().

◆ text

object text

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

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