Browse Source

add is_wtext

David Rose 20 years ago
parent
commit
d673267be3

+ 24 - 3
panda/src/express/textEncoder.cxx

@@ -103,6 +103,27 @@ get_wtext_as_ascii() const {
   return result;
   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
 //     Function: TextEncoder::encode_wchar
 //       Access: Published, Static
 //       Access: Published, Static
@@ -114,7 +135,7 @@ string TextEncoder::
 encode_wchar(wchar_t ch, TextEncoder::Encoding encoding) {
 encode_wchar(wchar_t ch, TextEncoder::Encoding encoding) {
   switch (encoding) {
   switch (encoding) {
   case E_iso8859:
   case E_iso8859:
-    if (ch < 0x100) {
+    if ((ch & ~0xff) == 0) {
       return string(1, (char)ch);
       return string(1, (char)ch);
     } else {
     } else {
       // The character won't fit in the 8-bit ISO 8859.  See if we can
       // 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:
   case E_utf8:
-    if (ch < 0x80) {
+    if ((ch & ~0x7f) == 0) {
       return string(1, (char)ch);
       return string(1, (char)ch);
-    } else if (ch < 0x800) {
+    } else if ((ch & ~0x7ff) == 0) {
       return 
       return 
         string(1, (char)((ch >> 6) | 0xc0)) +
         string(1, (char)((ch >> 6) | 0xc0)) +
         string(1, (char)((ch & 0x3f) | 0x80));
         string(1, (char)((ch & 0x3f) | 0x80));

+ 1 - 0
panda/src/express/textEncoder.h

@@ -93,6 +93,7 @@ PUBLISHED:
   INLINE const wstring &get_wtext() const;
   INLINE const wstring &get_wtext() const;
   INLINE void append_wtext(const wstring &text);
   INLINE void append_wtext(const wstring &text);
   wstring get_wtext_as_ascii() const;
   wstring get_wtext_as_ascii() const;
+  bool is_wtext() const;
 
 
   static string encode_wchar(wchar_t ch, Encoding encoding);
   static string encode_wchar(wchar_t ch, Encoding encoding);
   INLINE string encode_wtext(const wstring &wtext) const;
   INLINE string encode_wtext(const wstring &wtext) const;

+ 20 - 0
panda/src/pgui/pgEntry.cxx

@@ -657,6 +657,26 @@ set_focus(bool focus) {
   update_state();
   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
 //     Function: PGEntry::get_display_wtext
 //       Access: Private
 //       Access: Private

+ 1 - 0
panda/src/pgui/pgEntry.h

@@ -122,6 +122,7 @@ PUBLISHED:
 
 
   INLINE void set_wtext(const wstring &wtext);
   INLINE void set_wtext(const wstring &wtext);
   INLINE const wstring &get_wtext() const;
   INLINE const wstring &get_wtext() const;
+  bool is_wtext() const;
 
 
 
 
 private:
 private: