diff --git a/panda/src/express/textEncoder.cxx b/panda/src/express/textEncoder.cxx index bbd2358ccb..edc15d17df 100644 --- a/panda/src/express/textEncoder.cxx +++ b/panda/src/express/textEncoder.cxx @@ -103,6 +103,27 @@ get_wtext_as_ascii() const { return result; } +//////////////////////////////////////////////////////////////////// +// Function: TextEncoder::is_wtext +// Access: Published +// Description: 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()). +//////////////////////////////////////////////////////////////////// +bool TextEncoder:: +is_wtext() const { + get_wtext(); + wstring::const_iterator ti; + for (ti = _wtext.begin(); ti != _wtext.end(); ++ti) { + if (((*ti) & ~0x7f) != 0) { + return true; + } + } + + return false; +} + //////////////////////////////////////////////////////////////////// // Function: TextEncoder::encode_wchar // Access: Published, Static @@ -114,7 +135,7 @@ string TextEncoder:: encode_wchar(wchar_t ch, TextEncoder::Encoding encoding) { switch (encoding) { case E_iso8859: - if (ch < 0x100) { + if ((ch & ~0xff) == 0) { return string(1, (char)ch); } else { // The character won't fit in the 8-bit ISO 8859. See if we can @@ -137,9 +158,9 @@ encode_wchar(wchar_t ch, TextEncoder::Encoding encoding) { } case E_utf8: - if (ch < 0x80) { + if ((ch & ~0x7f) == 0) { return string(1, (char)ch); - } else if (ch < 0x800) { + } else if ((ch & ~0x7ff) == 0) { return string(1, (char)((ch >> 6) | 0xc0)) + string(1, (char)((ch & 0x3f) | 0x80)); diff --git a/panda/src/express/textEncoder.h b/panda/src/express/textEncoder.h index 8ed7b054c0..249ef3f162 100644 --- a/panda/src/express/textEncoder.h +++ b/panda/src/express/textEncoder.h @@ -93,6 +93,7 @@ PUBLISHED: INLINE const wstring &get_wtext() const; INLINE void append_wtext(const wstring &text); wstring get_wtext_as_ascii() const; + bool is_wtext() const; static string encode_wchar(wchar_t ch, Encoding encoding); INLINE string encode_wtext(const wstring &wtext) const; diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index 26e26ee621..2a537180bb 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -657,6 +657,26 @@ set_focus(bool focus) { update_state(); } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::is_wtext +// Access: Published +// Description: 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()). +//////////////////////////////////////////////////////////////////// +bool PGEntry:: +is_wtext() const { + wstring::const_iterator ti; + for (ti = _wtext.begin(); ti != _wtext.end(); ++ti) { + if (((*ti) & ~0x7f) != 0) { + return true; + } + } + + return false; +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::get_display_wtext // Access: Private diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 31846c83cd..1e06f7f1e9 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -122,6 +122,7 @@ PUBLISHED: INLINE void set_wtext(const wstring &wtext); INLINE const wstring &get_wtext() const; + bool is_wtext() const; private: