mail[Wesnoth-commits] r44255 - in /trunk/src/serialization: tokenizer.cpp tokenizer.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on July 17, 2010 - 19:09:
Author: silene
Date: Sat Jul 17 19:09:42 2010
New Revision: 44255

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44255&view=rev
Log:
Moved to table-based lookup of character types.

Modified:
    trunk/src/serialization/tokenizer.cpp
    trunk/src/serialization/tokenizer.hpp

Modified: trunk/src/serialization/tokenizer.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/tokenizer.cpp?rev=44255&r1=44254&r2=44255&view=diff
==============================================================================
--- trunk/src/serialization/tokenizer.cpp (original)
+++ trunk/src/serialization/tokenizer.cpp Sat Jul 17 19:09:42 2010
@@ -30,6 +30,17 @@
        token_(),
        in_(in)
 {
+       for (int c = 0; c < 128; ++c)
+       {
+               int t = TOK_IS_OTHER;
+               if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+                   (c >= '0' && c <= '9') || c == '_') {
+                       t = TOK_IS_ALNUM;
+               } else if (c == ' ' || c == '\t') {
+                       t = TOK_IS_SPACE;
+               }
+               char_types_[c] = t;
+       }
        in_.exceptions(std::ios_base::badbit);
        next_char_fast();
 }

Modified: trunk/src/serialization/tokenizer.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/tokenizer.hpp?rev=44255&r1=44254&r2=44255&view=diff
==============================================================================
--- trunk/src/serialization/tokenizer.hpp (original)
+++ trunk/src/serialization/tokenizer.hpp Sat Jul 17 19:09:42 2010
@@ -146,15 +146,26 @@
                return in_.peek();
        }
 
-       bool is_space(const int c) const
+       enum
        {
-               return c == ' ' || c == '\t';
+               TOK_IS_OTHER = 0,
+               TOK_IS_SPACE = 1,
+               TOK_IS_ALNUM = 2
+       };
+
+       int char_type(unsigned c) const
+       {
+               return c < 128 ? char_types_[c] : int(TOK_IS_OTHER);
        }
 
-       bool is_alnum(const int c) const
+       bool is_space(int c) const
        {
-               return (c >= 'a' && c <= 'z')
-                       || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') 
|| c == '_';
+               return char_type(c) == TOK_IS_SPACE;
+       }
+
+       bool is_alnum(int c) const
+       {
+               return char_type(c) == TOK_IS_ALNUM;
        }
 
        void skip_comment();
@@ -166,6 +177,7 @@
        token previous_token_;
 #endif
        std::istream &in_;
+       char char_types_[128];
 };
 
 #endif




Related Messages


Powered by MHonArc, Updated Sat Jul 17 19:20:11 2010