diff --git a/panda/src/express/textEncoder.I b/panda/src/express/textEncoder.I index 9100bdbf0d..75895a0562 100644 --- a/panda/src/express/textEncoder.I +++ b/panda/src/express/textEncoder.I @@ -419,6 +419,58 @@ unicode_tolower(int character) { return entry->_tolower_character; } +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::upper +// Access: Published, Static +// Description: Converts the string to uppercase, assuming the string +// is encoded in the default encoding. +//////////////////////////////////////////////////////////////////// +INLINE string TextEncoder:: +upper(const string &source) { + return upper(source, get_default_encoding()); +} + +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::upper +// Access: Published, Static +// Description: Converts the string to uppercase, assuming the string +// is encoded in the indicated encoding. +//////////////////////////////////////////////////////////////////// +INLINE string TextEncoder:: +upper(const string &source, TextEncoder::Encoding encoding) { + TextEncoder encoder; + encoder.set_encoding(encoding); + encoder.set_text(source); + encoder.toupper_text(); + return encoder.get_text(); +} + +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::lower +// Access: Published, Static +// Description: Converts the string to lowercase, assuming the string +// is encoded in the default encoding. +//////////////////////////////////////////////////////////////////// +INLINE string TextEncoder:: +lower(const string &source) { + return lower(source, get_default_encoding()); +} + +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::lower +// Access: Published, Static +// Description: Converts the string to lowercase, assuming the string +// is encoded in the indicated encoding. +//////////////////////////////////////////////////////////////////// +INLINE string TextEncoder:: +lower(const string &source, TextEncoder::Encoding encoding) { + TextEncoder encoder; + encoder.set_encoding(encoding); + encoder.set_text(source); + encoder.tolower_text(); + return encoder.get_text(); +} + //////////////////////////////////////////////////////////////////// // Function: TextEncoder::set_wtext // Access: Public diff --git a/panda/src/express/textEncoder.cxx b/panda/src/express/textEncoder.cxx index f754e29d4a..ec79d9efb5 100644 --- a/panda/src/express/textEncoder.cxx +++ b/panda/src/express/textEncoder.cxx @@ -24,8 +24,42 @@ TypeHandle TextEncoder::_type_handle; TextEncoder::Encoding TextEncoder::_default_encoding; //////////////////////////////////////////////////////////////////// -// Function: TextEncoder::get_wtext_as_ascii +// Function: TextEncoder::toupper_text // Access: Published +// Description: Adjusts the text stored within the encoder to all +// uppercase letters (preserving accent marks +// correctly). +//////////////////////////////////////////////////////////////////// +void TextEncoder:: +toupper_text() { + get_wtext(); + wstring::iterator si; + for (si = _wtext.begin(); si != _wtext.end(); ++si) { + (*si) = unicode_toupper(*si); + } + _flags &= ~F_got_text; +} + +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::tolower_text +// Access: Published +// Description: Adjusts the text stored within the encoder to all +// lowercase letters (preserving accent marks +// correctly). +//////////////////////////////////////////////////////////////////// +void TextEncoder:: +tolower_text() { + get_wtext(); + wstring::iterator si; + for (si = _wtext.begin(); si != _wtext.end(); ++si) { + (*si) = unicode_tolower(*si); + } + _flags &= ~F_got_text; +} + +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::get_wtext_as_ascii +// Access: Public // Description: Returns the text associated with the node, converted // as nearly as possible to a fully-ASCII // representation. This means replacing accented diff --git a/panda/src/express/textEncoder.h b/panda/src/express/textEncoder.h index 33d3251f29..37b6c5c42b 100644 --- a/panda/src/express/textEncoder.h +++ b/panda/src/express/textEncoder.h @@ -56,6 +56,10 @@ PUBLISHED: INLINE void set_text(const string &text, Encoding encoding); INLINE void clear_text(); INLINE bool has_text() const; + + void toupper_text(); + void tolower_text(); + INLINE string get_text() const; INLINE string get_text(Encoding encoding) const; INLINE void append_text(const string &text); @@ -77,6 +81,11 @@ PUBLISHED: INLINE static int unicode_toupper(int character); INLINE static int unicode_tolower(int character); + INLINE static string upper(const string &source); + INLINE static string upper(const string &source, Encoding encoding); + INLINE static string lower(const string &source); + INLINE static string lower(const string &source, Encoding encoding); + public: // Direct support for wide-character strings. Not publishable for // now (until we add support for wstring to interrogate).