]> git.tdb.fi Git - libs/core.git/commitdiff
Use unsigned char as element of Regex::Code
authorMikko Rasa <tdb@tdb.fi>
Wed, 8 Jun 2011 06:41:03 +0000 (09:41 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 8 Jun 2011 11:08:43 +0000 (14:08 +0300)
source/strings/regex.cpp
source/strings/regex.h

index 03bf7dde64a8c786bcf6ac0449589835d36f797d..bfd25c7036bffc88fbe5ca4a7db0a8057295c6de 100644 (file)
@@ -22,7 +22,7 @@ T read_int(Msp::Regex::Code::const_iterator &c)
 {
        T result = 0;
        for(unsigned i=0; i<sizeof(T); ++i)
-               result += static_cast<unsigned char>(*c++)<<i*8;
+               result += (*c++)<<i*8;
        return result;
 }
 
@@ -328,7 +328,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
        else
        {
                result += MATCH_MASK;
-               result.append(reinterpret_cast<char *>(mask), 32);
+               result.append(mask, 32);
        }
 
        iter = end;
@@ -360,7 +360,7 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch
        {
                int c;
                if(i!=str.end())
-                       c = static_cast<unsigned char>(*i);
+                       c = *i;
                else
                        c = -1;
 
@@ -506,7 +506,7 @@ string Regex::disassemble() const
                string decompiled = disassemble_instruction(i);
                string bytes;
                for(; j!=i; ++j)
-                       bytes += format(" %02X", static_cast<int>(*j)&0xFF);
+                       bytes += format(" %02X", *j);
                result += format("%3d:%-9s  ", offset, bytes);
                if(bytes.size()>9)
                        result += "\n               ";
@@ -545,24 +545,24 @@ string Regex::disassemble_instruction(Code::const_iterator &i) const
                return "MATCH_END";
        case MATCH_CHAR:
                {
-                       char c = *i++;
+                       unsigned char c = *i++;
                        if(c>=0x20 && c<=0x7E)
                                return format("MATCH_CHAR '%c'", c);
                        else
-                               return format("MATCH_CHAR %d", static_cast<int>(c)&0xFF);
+                               return format("MATCH_CHAR %d", c);
                }
                break;
        case MATCH_RANGE:
                {
                        int begin = *i++;
                        int end = *i++;
-                       return format("MATCH_RANGE %d-%d", begin&0xFF, end&0xFF);
+                       return format("MATCH_RANGE %d-%d", begin, end);
                }
        case MATCH_MASK:
                {
                        string result = "MATCH_MASK";
                        for(unsigned j=0; j<32; ++j)
-                               result += format(" %02X", static_cast<int>(*i++)&0xFF);
+                               result += format(" %02X", *i++);
                        return result;
                }
        case MATCH_ANY:
index 8226c44ae057c2b17bb63adf8198c1686015525b..5b809ab3c363415382a66bbbcf855140a47c5329 100644 (file)
@@ -61,7 +61,7 @@ The MATCH_ANY instruction consumes the input character and always succeeds.
 class Regex
 {
 private:
-       typedef std::string Code;
+       typedef std::basic_string<unsigned char> Code;
        typedef unsigned short Count;
        typedef short Offset;
        typedef unsigned short Index;