Fix for the bug ID: 3083640 - is_code_point_valid incorrectly returns false

git-svn-id: http://svn.code.sf.net/p/utfcpp/code@117 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
ntrifunovic 2011-02-20 18:07:59 +00:00
parent 2976b72daa
commit a4fce3befd
3 changed files with 7 additions and 5 deletions

View file

@ -92,7 +92,7 @@ namespace internal
template <typename u32> template <typename u32>
inline bool is_code_point_valid(u32 cp) inline bool is_code_point_valid(u32 cp)
{ {
return (cp <= CODE_POINT_MAX && !is_surrogate(cp) && cp != 0xfffe && cp != 0xffff); return (cp <= CODE_POINT_MAX && !is_surrogate(cp));
} }
template <typename octet_iterator> template <typename octet_iterator>

View file

@ -7,7 +7,7 @@ using namespace utf8;
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
const unsigned INVALID_LINES[] = { 75, 76, 82, 83, 84, 85, 93, 102, 103, 105, 106, 107, 108, 109, 110, 114, 115, 116, 117, 124, 125, 130, 135, 140, 145, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 169, 175, 176, 177, 207, 208, 209, 210, 211, 220, 221, 222, 223, 224, 232, 233, 234, 235, 236, 247, 248, 249, 250, 251, 252, 253, 257, 258, 259, 260, 261, 262, 263, 264, 268, 269}; const unsigned INVALID_LINES[] = { 75, 76, 82, 83, 84, 85, 93, 102, 103, 105, 106, 107, 108, 109, 110, 114, 115, 116, 117, 124, 125, 130, 135, 140, 145, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 169, 175, 176, 177, 207, 208, 209, 210, 211, 220, 221, 222, 223, 224, 232, 233, 234, 235, 236, 247, 248, 249, 250, 251, 252, 253, 257, 258, 259, 260, 261, 262, 263, 264};
const unsigned* INVALID_LINES_END = INVALID_LINES + sizeof(INVALID_LINES)/sizeof(unsigned); const unsigned* INVALID_LINES_END = INVALID_LINES + sizeof(INVALID_LINES)/sizeof(unsigned);
int main(int argc, char** argv) int main(int argc, char** argv)
@ -35,10 +35,10 @@ int main(int argc, char** argv)
line.push_back(byte); line.push_back(byte);
line_count++; line_count++;
// Print out lines that contain invalid UTF-8 bool expected_valid = (find(INVALID_LINES, INVALID_LINES_END, line_count) == INVALID_LINES_END);
// Print out lines that contain unexpected invalid UTF-8
if (!is_valid(line.begin(), line.end())) { if (!is_valid(line.begin(), line.end())) {
const unsigned* u = find(INVALID_LINES, INVALID_LINES_END, line_count); if (expected_valid)
if (u == INVALID_LINES_END)
cout << "Unexpected invalid utf-8 at line " << line_count << '\n'; cout << "Unexpected invalid utf-8 at line " << line_count << '\n';
// try fixing it: // try fixing it:
@ -47,5 +47,7 @@ int main(int argc, char** argv)
if (!is_valid(fixed_line.begin(), fixed_line.end())) if (!is_valid(fixed_line.begin(), fixed_line.end()))
cout << "replace_invalid() resulted in an invalid utf-8 at line " << line_count << '\n'; cout << "replace_invalid() resulted in an invalid utf-8 at line " << line_count << '\n';
} }
else if (!expected_valid)
cout << "Invalid utf-8 NOT detected at line " << line_count << '\n';
} }
} }