Skip to content

Commit

Permalink
fix signature and test for UTF-8 functions
Browse files Browse the repository at this point in the history
On the advise of 8680, the unicode string was replaced by the hex
transcription of the corresponding codepoints (which he kindly
provided).
This might help to pass the overzealous encoding check of clang.

This commit also fixes a discrepancy between the signature of u8index in
declaration and definition.
  • Loading branch information
aquileia committed Mar 22, 2014
1 parent 2f6a6a7 commit 246f599
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/serialization/string_utils.cpp
Expand Up @@ -1074,7 +1074,7 @@ utf8::string lowercase(const utf8::string& s)
return s;
}

unsigned int index(const utf8::string& str, const unsigned int index)
size_t index(const utf8::string& str, const size_t index)
{
// chr counts characters, i is the codepoint index
// remark: several functions rely on the fallback to str.length()
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_serialization.cpp
Expand Up @@ -34,12 +34,12 @@ BOOST_AUTO_TEST_CASE( utils_join_test )

BOOST_CHECK( utils::join(fruit) == "apples,oranges,lemons" );

utf8::string unicode = "ünicod€ check";
utf8::string unicode = "\xC3\xBCnicod\xE2\x82\xAC check"; // "ünicod€ check" in UTF-8
BOOST_CHECK( utf8::size(unicode) == 13 );

int euro = utf8::index(unicode,6);
BOOST_CHECK( str.substr(euro,utf8::index(unicode,7)-euro) == "" );
BOOST_CHECK( unicode.substr(euro,utf8::index(unicode,7)-euro) == "\xE2\x82\xAC" ); // € sign

BOOST_CHECK( utf8::truncate(unicode,3) == "üni");
BOOST_CHECK( utf8::truncate(unicode,3) == "\xC3\xBCni"); // "üni"
}

0 comments on commit 246f599

Please sign in to comment.