add replacements for string.upper and string.lower

This commit is contained in:
David Rose 2003-04-01 18:03:00 +00:00
parent 5472152a5a
commit af4494d2de
3 changed files with 96 additions and 1 deletions

View File

@ -419,6 +419,58 @@ unicode_tolower(int character) {
return entry->_tolower_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 // Function: TextEncoder::set_wtext
// Access: Public // Access: Public

View File

@ -24,8 +24,42 @@ TypeHandle TextEncoder::_type_handle;
TextEncoder::Encoding TextEncoder::_default_encoding; TextEncoder::Encoding TextEncoder::_default_encoding;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: TextEncoder::get_wtext_as_ascii // Function: TextEncoder::toupper_text
// Access: Published // 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 // Description: Returns the text associated with the node, converted
// as nearly as possible to a fully-ASCII // as nearly as possible to a fully-ASCII
// representation. This means replacing accented // representation. This means replacing accented

View File

@ -56,6 +56,10 @@ PUBLISHED:
INLINE void set_text(const string &text, Encoding encoding); INLINE void set_text(const string &text, Encoding encoding);
INLINE void clear_text(); INLINE void clear_text();
INLINE bool has_text() const; INLINE bool has_text() const;
void toupper_text();
void tolower_text();
INLINE string get_text() const; INLINE string get_text() const;
INLINE string get_text(Encoding encoding) const; INLINE string get_text(Encoding encoding) const;
INLINE void append_text(const string &text); INLINE void append_text(const string &text);
@ -77,6 +81,11 @@ PUBLISHED:
INLINE static int unicode_toupper(int character); INLINE static int unicode_toupper(int character);
INLINE static int unicode_tolower(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: public:
// Direct support for wide-character strings. Not publishable for // Direct support for wide-character strings. Not publishable for
// now (until we add support for wstring to interrogate). // now (until we add support for wstring to interrogate).