浏览代码

add (unsigned) for ctype fns

cxgeorge 23 年之前
父节点
当前提交
763195a6aa
共有 3 个文件被更改,包括 11 次插入12 次删除
  1. 0 1
      panda/src/text/dynamicTextFont.cxx
  2. 7 7
      panda/src/text/textFont.cxx
  3. 4 4
      panda/src/text/textNode.cxx

+ 0 - 1
panda/src/text/dynamicTextFont.cxx

@@ -22,7 +22,6 @@
 
 #include "config_text.h"
 #include "config_util.h"
-#include "ctype.h"
 
 bool DynamicTextFont::_update_cleared_glyphs = text_update_cleared_glyphs;
 

+ 7 - 7
panda/src/text/textFont.cxx

@@ -29,7 +29,7 @@ TypeHandle TextFont::_type_handle;
 //               does not consider newlines to be whitespace.
 ////////////////////////////////////////////////////////////////////
 INLINE bool
-isblank(int ch) {
+isblank(unsigned int ch) {
   return (ch == ' ' || ch == '\t');
 }
 
@@ -39,7 +39,7 @@ isblank(int ch) {
 //               safe to call for a wide character.
 ////////////////////////////////////////////////////////////////////
 INLINE bool
-isspacew(int ch) {
+isspacew(unsigned int ch) {
   return isascii(ch) && isspace(ch);
 }
 
@@ -125,7 +125,7 @@ wordwrap_to(const string &text, float wordwrap_width,
 
   // Preserve any initial whitespace and newlines.
   float initial_width = 0.0f;
-  while (p < text.length() && isspace(text[p])) {
+  while (p < text.length() && isspace((unsigned int)text[p])) {  // dbg runtime will bomb if text[p]>=128 without (unsigned int) cast
     if (text[p] == '\n') {
       initial_width = 0.0f;
     } else {
@@ -137,7 +137,7 @@ wordwrap_to(const string &text, float wordwrap_width,
   bool needs_newline = false;
 
   while (p < text.length()) {
-    nassertr(!isspace(text[p]), string());
+    nassertr(!isspace((unsigned int)text[p]), string());
 
     // Scan the next n characters, until the end of the string or an
     // embedded newline character, or we exceed wordwrap_width.
@@ -148,7 +148,7 @@ wordwrap_to(const string &text, float wordwrap_width,
 
     float width = initial_width;
     while (q < text.length() && text[q] != '\n') {
-      if (isspace(text[q])) {
+      if (isspace((unsigned int)text[q])) {
         any_spaces = true;
       }
 
@@ -166,7 +166,7 @@ wordwrap_to(const string &text, float wordwrap_width,
     if (overflow && any_spaces) {
       // If we stopped because we exceeded the wordwrap width, then
       // back up to the end of the last complete word.
-      while (q > p && !isspace(text[q])) {
+      while (q > p && !isspace((unsigned int)text[q])) {
         q--;
       }
     }
@@ -215,7 +215,7 @@ wordwrap_to(const string &text, float wordwrap_width,
 
     // Preserve any initial whitespace and newlines.
     initial_width = 0.0f;
-    while (p < text.length() && isspace(text[p])) {
+    while (p < text.length() && isspace((unsigned int)text[p])) {
       if (text[p] == '\n') {
         initial_width = 0.0f;
       } else {

+ 4 - 4
panda/src/text/textNode.cxx

@@ -382,7 +382,7 @@ string TextNode::
 encode_wchar(wchar_t ch) const {
   switch (_encoding) {
   case E_iso8859:
-    if (isascii(ch)) {
+    if (isascii((unsigned int)ch)) {
       return string(1, (char)ch);
     } else {
       return ".";
@@ -502,7 +502,7 @@ expand_amp_sequence(StringDecoder &decoder) const {
     // An explicit numeric sequence: &#nnn;
     result = 0;
     character = decoder.get_next_character();
-    while (!decoder.is_eof() && character < 128 && isdigit(character)) {
+    while (!decoder.is_eof() && character < 128 && isdigit((unsigned int)character)) {
       result = (result * 10) + (character - '0');
       character = decoder.get_next_character();
     }
@@ -517,7 +517,7 @@ expand_amp_sequence(StringDecoder &decoder) const {
   string sequence;
   
   // Some non-numeric sequence.
-  while (!decoder.is_eof() && character < 128 && isalpha(character)) {
+  while (!decoder.is_eof() && character < 128 && isalpha((unsigned int)character)) {
     sequence += character;
     character = decoder.get_next_character();
   }
@@ -673,7 +673,7 @@ assemble_row(wstring::iterator &si, const wstring::iterator &send,
         text_cat.warning()
           << "No definition in " << _font->get_name() 
           << " for character " << character;
-        if (character < 128 && isprint(character)) {
+        if (character < 128 && isprint((unsigned int)character)) {
           text_cat.warning(false)
             << " ('" << (char)character << "')";
         }