Fix for [3167987]: prior moves it before start
git-svn-id: http://svn.code.sf.net/p/utfcpp/code@116 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
parent
7fcdf850d9
commit
045624abd7
2 changed files with 22 additions and 18 deletions
|
@ -161,13 +161,17 @@ namespace utf8
|
||||||
|
|
||||||
template <typename octet_iterator>
|
template <typename octet_iterator>
|
||||||
uint32_t prior(octet_iterator& it, octet_iterator start)
|
uint32_t prior(octet_iterator& it, octet_iterator start)
|
||||||
{
|
{
|
||||||
octet_iterator end = it;
|
// can't do much if it == start
|
||||||
|
if (it == start)
|
||||||
|
throw not_enough_room();
|
||||||
|
|
||||||
|
octet_iterator end = it;
|
||||||
|
// Go back until we hit either a lead octet or start
|
||||||
while (internal::is_trail(*(--it)))
|
while (internal::is_trail(*(--it)))
|
||||||
if (it < start)
|
if (it == start)
|
||||||
throw invalid_utf8(*it); // error - no lead byte in the sequence
|
throw invalid_utf8(*it); // error - no lead byte in the sequence
|
||||||
octet_iterator temp = it;
|
return peek_next(it, end);
|
||||||
return next(temp, end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated in versions that include "prior"
|
/// Deprecated in versions that include "prior"
|
||||||
|
|
|
@ -22,8 +22,8 @@ int main(int argc, char** argv)
|
||||||
// Open the test file
|
// Open the test file
|
||||||
ifstream fs8(test_file_path.c_str());
|
ifstream fs8(test_file_path.c_str());
|
||||||
if (!fs8.is_open()) {
|
if (!fs8.is_open()) {
|
||||||
cout << "Could not open " << test_file_path << endl;
|
cout << "Could not open " << test_file_path << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read it line by line
|
// Read it line by line
|
||||||
|
@ -32,20 +32,20 @@ int main(int argc, char** argv)
|
||||||
while (!fs8.eof()) {
|
while (!fs8.eof()) {
|
||||||
string line;
|
string line;
|
||||||
while ((byte = static_cast<char>(fs8.get())) != '\n' && !fs8.eof())
|
while ((byte = static_cast<char>(fs8.get())) != '\n' && !fs8.eof())
|
||||||
line.push_back(byte);
|
line.push_back(byte);
|
||||||
|
|
||||||
line_count++;
|
line_count++;
|
||||||
// Print out lines that contain invalid UTF-8
|
// Print out lines that contain 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);
|
const unsigned* u = find(INVALID_LINES, INVALID_LINES_END, line_count);
|
||||||
if (u == INVALID_LINES_END)
|
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:
|
||||||
string fixed_line;
|
string fixed_line;
|
||||||
replace_invalid(line.begin(), line.end(), back_inserter(fixed_line));
|
replace_invalid(line.begin(), line.end(), back_inserter(fixed_line));
|
||||||
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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue