Skip to content

Commit

Permalink
Fixed problems with signed characters.
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@85 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Jul 18, 2007
1 parent 4df1016 commit eeaca1b
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 62 deletions.
10 changes: 5 additions & 5 deletions ccutil/unichar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ int UNICHAR::first_uni() const {
default:
break;
case 4:
uni += *src++;
uni += static_cast<unsigned char>(*src++);
uni <<= 6;
case 3:
uni += *src++;
uni += static_cast<unsigned char>(*src++);
uni <<= 6;
case 2:
uni += *src++;
uni += static_cast<unsigned char>(*src++);
uni <<= 6;
case 1:
uni += *src++;
uni += static_cast<unsigned char>(*src++);
}
uni -= utf8_offsets[len];
return uni;
Expand Down Expand Up @@ -140,5 +140,5 @@ int UNICHAR::utf8_step(const char* utf8_str) {
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0
};

return utf8_bytes[*utf8_str];
return utf8_bytes[static_cast<unsigned char>(*utf8_str)];
}
20 changes: 10 additions & 10 deletions ccutil/unicharmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ UNICHAR_ID UNICHARMAP::unichar_to_id(const char* const unichar_repr) const {

do {
if (*(current_char + 1) == '\0')
return current_nodes[static_cast<unsigned int>(*current_char)].id;
return current_nodes[static_cast<unsigned char>(*current_char)].id;
current_nodes =
current_nodes[static_cast<unsigned int>(*current_char)].children;
current_nodes[static_cast<unsigned char>(*current_char)].children;
++current_char;
} while (true);
}
Expand All @@ -61,9 +61,9 @@ UNICHAR_ID UNICHARMAP::unichar_to_id(const char* const unichar_repr,

do {
if (length == 1 || *(current_char + 1) == '\0')
return current_nodes[static_cast<unsigned int>(*current_char)].id;
return current_nodes[static_cast<unsigned char>(*current_char)].id;
current_nodes =
current_nodes[static_cast<unsigned int>(*current_char)].children;
current_nodes[static_cast<unsigned char>(*current_char)].children;
++current_char;
--length;
} while (true);
Expand All @@ -85,12 +85,12 @@ void UNICHARMAP::insert(const char* const unichar_repr, UNICHAR_ID id) {
*current_nodes_pointer = new UNICHARMAP_NODE[256];
if (*(current_char + 1) == '\0') {
(*current_nodes_pointer)
[static_cast<unsigned int>(*current_char)].id = id;
[static_cast<unsigned char>(*current_char)].id = id;
return;
}
current_nodes_pointer =
&((*current_nodes_pointer)
[static_cast<unsigned int>(*current_char)].children);
[static_cast<unsigned char>(*current_char)].children);
++current_char;
} while (true);
}
Expand All @@ -106,11 +106,11 @@ bool UNICHARMAP::contains(const char* const unichar_repr) const {

while (current_nodes != 0 && *(current_char + 1) != '\0') {
current_nodes =
current_nodes[static_cast<unsigned int>(*current_char)].children;
current_nodes[static_cast<unsigned char>(*current_char)].children;
++current_char;
}
return current_nodes != 0 && *(current_char + 1) == '\0' &&
current_nodes[static_cast<unsigned int>(*current_char)].id >= 0;
current_nodes[static_cast<unsigned char>(*current_char)].id >= 0;
}

// Search the given unichar representation in the tree, using length characters
Expand All @@ -127,12 +127,12 @@ bool UNICHARMAP::contains(const char* const unichar_repr,

while (current_nodes != 0 && (length > 1 && *(current_char + 1) != '\0')) {
current_nodes =
current_nodes[static_cast<unsigned int>(*current_char)].children;
current_nodes[static_cast<unsigned char>(*current_char)].children;
--length;
++current_char;
}
return current_nodes != 0 && (length == 1 || *(current_char + 1) == '\0') &&
current_nodes[static_cast<unsigned int>(*current_char)].id >= 0;
current_nodes[static_cast<unsigned char>(*current_char)].id >= 0;
}

void UNICHARMAP::clear() {
Expand Down
Loading

0 comments on commit eeaca1b

Please sign in to comment.