33class EXPCL_DTOOL_DTOOLUTIL TextEncoder {
41 E_unicode = E_utf16be,
45 INLINE TextEncoder(
const TextEncoder ©);
47 virtual ~TextEncoder() =
default;
57 EXTEND
void set_text(PyObject *text);
58 EXTEND
void set_text(PyObject *text, Encoding encoding);
60 INLINE
void set_text(
const std::string &text);
61 INLINE
void set_text(
const std::string &text, Encoding encoding);
64 INLINE
bool has_text()
const;
71 EXTEND PyObject *
get_text(Encoding encoding)
const;
75 INLINE std::string
get_text(Encoding encoding)
const;
86 INLINE
static std::string
reencode_text(
const std::string &text, Encoding from, Encoding to);
97 INLINE
static std::string
upper(
const std::string &source);
98 INLINE
static std::string
upper(
const std::string &source, Encoding encoding);
99 INLINE
static std::string
lower(
const std::string &source);
100 INLINE
static std::string
lower(
const std::string &source, Encoding encoding);
104 INLINE
void set_wtext(
const std::wstring &wtext);
105 INLINE
const std::wstring &
get_wtext()
const;
111 EXTEND
static PyObject *
encode_wchar(
char32_t ch, Encoding encoding);
112 EXTEND INLINE PyObject *
encode_wtext(
const std::wstring &wtext)
const;
113 EXTEND
static PyObject *
encode_wtext(
const std::wstring &wtext, Encoding encoding);
114 EXTEND INLINE PyObject *
decode_text(PyObject *text)
const;
115 EXTEND
static PyObject *
decode_text(PyObject *text, Encoding encoding);
117 static std::string
encode_wchar(
char32_t ch, Encoding encoding);
118 INLINE std::string
encode_wtext(
const std::wstring &wtext)
const;
119 static std::string
encode_wtext(
const std::wstring &wtext, Encoding encoding);
120 INLINE std::wstring
decode_text(
const std::string &text)
const;
121 static std::wstring
decode_text(
const std::string &text, Encoding encoding);
127 virtual void text_changed();
132 F_got_wtext = 0x0002,
134 static std::wstring decode_text_impl(
StringDecoder &decoder);
141 static Encoding _default_encoding;
144EXPCL_DTOOL_DTOOLUTIL std::ostream &
145operator << (std::ostream &out, TextEncoder::Encoding encoding);
146EXPCL_DTOOL_DTOOLUTIL std::istream &
147operator >> (std::istream &in, TextEncoder::Encoding &encoding);
154INLINE EXPCL_DTOOL_DTOOLUTIL std::ostream &
155operator << (std::ostream &out,
const std::wstring &str);
The base class to a family of classes that decode various kinds of encoded byte streams.
std::wstring decode_text(const std::string &text) const
Returns the given wstring decoded to a single-byte string, via the current encoding system.
void append_text(const std::string &text)
Appends the indicates string to the end of the stored text.
set_text
Changes the text that is stored in the encoder.
static std::string upper(const std::string &source)
Converts the string to uppercase, assuming the string is encoded in the default encoding.
void append_wtext(const std::wstring &text)
Appends the indicates string to the end of the stored wide-character text.
void set_unicode_char(size_t index, char32_t character)
Sets the Unicode value of the nth character in the stored text.
static std::string lower(const std::string &source)
Converts the string to lowercase, assuming the string is encoded in the default encoding.
std::string get_text_as_ascii() const
Returns the text associated with the node, converted as nearly as possible to a fully-ASCII represent...
static std::string reencode_text(const std::string &text, Encoding from, Encoding to)
Given the indicated text string, which is assumed to be encoded via the encoding "from",...
static std::string encode_wchar(char32_t ch, Encoding encoding)
Encodes a single Unicode character into a one-, two-, three-, or four-byte string,...
static bool unicode_ispunct(char32_t character)
Returns true if the indicated character is a punctuation mark, false otherwise.
static int unicode_tolower(char32_t character)
Returns the uppercase equivalent of the given Unicode character.
static bool unicode_isupper(char32_t character)
Returns true if the indicated character is an uppercase letter, false otherwise.
bool is_wtext() const
Returns true if any of the characters in the string returned by get_wtext() are out of the range of a...
get_default_encoding
Specifies the default encoding to be used for all subsequently created TextEncoder objects.
static int unicode_toupper(char32_t character)
Returns the uppercase equivalent of the given Unicode character.
std::wstring get_wtext_as_ascii() const
Returns the text associated with the node, converted as nearly as possible to a fully-ASCII represent...
Encoding get_encoding() const
Returns the encoding by which the string set via set_text() is to be interpreted.
static bool unicode_isdigit(char32_t character)
Returns true if the indicated character is a numeric digit, false otherwise.
void set_encoding(Encoding encoding)
Specifies how the string set via set_text() is to be interpreted.
get_text
Returns the current text, as encoded via the current encoding system.
const std::wstring & get_wtext() const
Returns the text associated with the TextEncoder, as a wide-character string.
size_t get_num_chars() const
Returns the number of characters in the stored text.
void make_lower()
Adjusts the text stored within the encoder to all lowercase letters (preserving accent marks correctl...
void clear_text()
Removes the text from the TextEncoder.
void make_upper()
Adjusts the text stored within the encoder to all uppercase letters (preserving accent marks correctl...
std::string get_encoded_char(size_t index) const
Returns the nth char of the stored text, as a one-, two-, or three-byte encoded string.
static bool unicode_isspace(char32_t character)
Returns true if the indicated character is a whitespace letter, false otherwise.
int get_unicode_char(size_t index) const
Returns the Unicode value of the nth character in the stored text.
static bool unicode_islower(char32_t character)
Returns true if the indicated character is a lowercase letter, false otherwise.
set_default_encoding
Specifies the default encoding to be used for all subsequently created TextEncoder objects.
std::string encode_wtext(const std::wstring &wtext) const
Encodes a wide-text string into a single-char string, according to the current encoding.
static bool unicode_isalpha(char32_t character)
Returns true if the indicated character is an alphabetic letter, false otherwise.
void append_unicode_char(char32_t character)
Appends a single character to the end of the stored text.
void set_wtext(const std::wstring &wtext)
Changes the text that is stored in the encoder.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.