TextEncoder

from panda3d.core import TextEncoder
class TextEncoder

Bases:

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.

Inheritance diagram

Inheritance diagram of TextEncoder

enum Encoding
enumerator E_iso8859 = 0
enumerator E_utf8 = 1
enumerator E_utf16be = 2
enumerator E_cp437 = 3
enumerator E_unicode = 2

Deprecated alias for E_utf16be

__init__()
__init__(copy: TextEncoder)
append_text(text: object)
append_unicode_char(character: int)

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

append_wtext(text: str)

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

clear_text()

Removes the text from the TextEncoder.

decode_text(text: object) object
decode_text(text: object, encoding: Encoding) object
property default_encoding Encoding

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

static encode_wchar(ch: int, encoding: Encoding) object

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

encode_wtext(wtext: str) object

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

encode_wtext(wtext: str, encoding: Encoding) object

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

static get_default_encoding() Encoding

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

get_encoded_char(index: int) str

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

get_encoded_char(index: int, encoding: Encoding) str

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

get_encoding() Encoding

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

get_num_chars() int

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

get_text() object

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

get_text(encoding: Encoding) object

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

get_text_as_ascii() str

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

get_unicode_char(index: int) int

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

get_wtext() str

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

get_wtext_as_ascii() str

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.

has_text() bool
is_wtext() bool

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

static lower(source: str) str

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

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

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

make_lower()

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

make_upper()

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

static reencode_text(text: str, from: Encoding, to: Encoding) str

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.

static set_default_encoding(encoding: Encoding)

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

set_encoding(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.

set_text(text: object)
set_text(text: object, encoding: Encoding)
set_unicode_char(index: int, character: int)

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

set_wtext(wtext: str)

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.

property text
Getter

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

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

Setter

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.

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

static unicode_isalpha(character: int) bool

Returns true if the indicated character is an alphabetic letter, false otherwise. This is akin to ctype’s isalpha(), extended to Unicode.

static unicode_isdigit(character: int) bool

Returns true if the indicated character is a numeric digit, false otherwise. This is akin to ctype’s isdigit(), extended to Unicode.

static unicode_islower(character: int) bool

Returns true if the indicated character is a lowercase letter, false otherwise. This is akin to ctype’s islower(), extended to Unicode.

static unicode_ispunct(character: int) bool

Returns true if the indicated character is a punctuation mark, false otherwise. This is akin to ctype’s ispunct(), extended to Unicode.

static unicode_isspace(character: int) bool

Returns true if the indicated character is a whitespace letter, false otherwise. This is akin to ctype’s isspace(), extended to Unicode.

static unicode_isupper(character: int) bool

Returns true if the indicated character is an uppercase letter, false otherwise. This is akin to ctype’s isupper(), extended to Unicode.

static unicode_tolower(character: int) int

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

static unicode_toupper(character: int) int

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

static upper(source: str) str

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

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

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