-
Notifications
You must be signed in to change notification settings - Fork 277
Explicit unsigned -> uint16_t casts to avoid conversion warnings #2543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
680227e
8d93087
0146874
9b9aecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,22 @@ Author: Vojtech Forejt, forejtv@diffblue.com | |
|
||
\*******************************************************************/ | ||
|
||
#include <cassert> | ||
#include <testing-utils/catch.hpp> | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <codecvt> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <locale> | ||
|
||
#include <util/unicode.h> | ||
|
||
// the u8 prefix is only available from VS 2015 onwards | ||
#if !defined(_MSC_VER) || _MSC_VER >= 1900 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check with @kroening but I think this is our minimum compiler on MS environments anyhow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, at least AppVeyor's VS seems to be older than that (it does not support the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do a PR that upgrades AppVeyor to 2013. There are no stakeholders that I know of that still care about VS 2013. |
||
|
||
// This unit test compares our implementation with codecvt implementation, | ||
// checking bit-by-bit equivalence of results. | ||
|
||
bool paranoid_wstr_equals(const std::wstring &a, const std::wstring &b) | ||
static bool paranoid_wstr_equals(const std::wstring &a, const std::wstring &b) | ||
{ | ||
if(a.size() != b.size()) | ||
return false; | ||
|
@@ -35,7 +37,10 @@ bool paranoid_wstr_equals(const std::wstring &a, const std::wstring &b) | |
} | ||
|
||
// helper print function, can be called for debugging problem | ||
void wstr_print(const std::wstring &a, const std::wstring &b) | ||
#if 0 | ||
#include <iostream> | ||
|
||
static void wstr_print(const std::wstring &a, const std::wstring &b) | ||
{ | ||
int endi=(a.size()>b.size())?a.size():b.size(); | ||
const unsigned char | ||
|
@@ -49,46 +54,46 @@ void wstr_print(const std::wstring &a, const std::wstring &b) | |
} | ||
std::cout << '\n'; | ||
} | ||
#endif | ||
|
||
void compare_utf8_to_utf16_big_endian(std::string& in) | ||
static bool compare_utf8_to_utf16(const std::string &in) | ||
{ | ||
std::wstring s1=utf8_to_utf16_big_endian(in); | ||
const std::wstring s1 = utf8_to_utf16_native_endian(in); | ||
|
||
typedef std::codecvt_utf8_utf16<wchar_t> codecvt_utf8_utf16t; | ||
std::wstring_convert<codecvt_utf8_utf16t> converter; | ||
std::wstring s2=converter.from_bytes(in); | ||
|
||
assert(paranoid_wstr_equals(s1, s2)); | ||
return paranoid_wstr_equals(s1, s2); | ||
} | ||
|
||
void compare_utf8_to_utf16_little_endian(std::string& in) | ||
TEST_CASE("unicode0", "[core][util][unicode]") | ||
{ | ||
std::wstring s1=utf8_to_utf16_little_endian(in); | ||
|
||
const std::codecvt_mode mode=std::codecvt_mode::little_endian; | ||
const unsigned long maxcode=0x10ffff; | ||
const std::string s = u8"abc"; | ||
REQUIRE(compare_utf8_to_utf16(s)); | ||
} | ||
|
||
typedef std::codecvt_utf8_utf16<wchar_t, maxcode, mode> codecvt_utf8_utf16t; | ||
std::wstring_convert<codecvt_utf8_utf16t> converter; | ||
std::wstring s2=converter.from_bytes(in); | ||
TEST_CASE("unicode1", "[core][util][unicode]") | ||
{ | ||
const std::string s = u8"\u0070\u00DF\u00E0\u00EF\u00F0\u00F7\u00F8"; | ||
REQUIRE(compare_utf8_to_utf16(s)); | ||
} | ||
|
||
assert(paranoid_wstr_equals(s1, s2)); | ||
TEST_CASE("unicode2", "[core][util][unicode]") | ||
{ | ||
const std::string s = u8"$¢€𐍈"; | ||
REQUIRE(compare_utf8_to_utf16(s)); | ||
} | ||
|
||
int main() | ||
TEST_CASE("unicode3", "[core][util][unicode]") | ||
{ | ||
std::string s; | ||
s=u8"\u0070\u00DF\u00E0\u00EF\u00F0\u00F7\u00F8"; | ||
compare_utf8_to_utf16_big_endian(s); | ||
compare_utf8_to_utf16_little_endian(s); | ||
s=u8"$¢€𐍈"; | ||
compare_utf8_to_utf16_big_endian(s); | ||
compare_utf8_to_utf16_little_endian(s); | ||
s=u8"𐐏𤭢"; | ||
compare_utf8_to_utf16_big_endian(s); | ||
compare_utf8_to_utf16_little_endian(s); | ||
s=u8"дȚȨɌṡʒʸͼἨѶݔݺ→⅒⅀▤▞╢◍⛳⻥龍ンㄗㄸ"; | ||
compare_utf8_to_utf16_big_endian(s); | ||
compare_utf8_to_utf16_little_endian(s); | ||
const std::string s = u8"𐐏𤭢"; | ||
REQUIRE(compare_utf8_to_utf16(s)); | ||
} | ||
|
||
TEST_CASE("unicode4", "[core][util][unicode]") | ||
{ | ||
const std::string s = u8"дȚȨɌṡʒʸͼἨѶݔݺ→⅒⅀▤▞╢◍⛳⻥龍ンㄗㄸ"; | ||
REQUIRE(compare_utf8_to_utf16(s)); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that everything is "native endian", does that need to be mentioned in the name of the function?
It's implicit in any function that takes numbers as arguments.