Commit c12d6c05 authored by Aleksey Konovalov's avatar Aleksey Konovalov

Fixed bug with processing \U+0000 symbol. Added tests

parent e12862a9
...@@ -193,7 +193,7 @@ namespace djinni ...@@ -193,7 +193,7 @@ namespace djinni
static LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c) static LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c)
{ {
return {jniEnv, jniStringFromWString(jniEnv, c.c_str())}; return {jniEnv, jniStringFromWString(jniEnv, c)};
} }
}; };
......
...@@ -413,7 +413,7 @@ static inline bool is_low_surrogate(char16_t c) { return (c >= 0xDC00) && (c < ...@@ -413,7 +413,7 @@ static inline bool is_low_surrogate(char16_t c) { return (c >= 0xDC00) && (c <
/* /*
* Like utf8_decode_check, but for UTF-16. * Like utf8_decode_check, but for UTF-16.
*/ */
static offset_pt utf16_decode_check(const std::u16string & str, std::u16string::size_type i) { static offset_pt utf16_decode_check(const char16_t * str, std::u16string::size_type i) {
if (is_high_surrogate(str[i]) && is_low_surrogate(str[i+1])) { if (is_high_surrogate(str[i]) && is_low_surrogate(str[i+1])) {
// High surrogate followed by low surrogate // High surrogate followed by low surrogate
char32_t pt = (((str[i] - 0xD800) << 10) | (str[i+1] - 0xDC00)) + 0x10000; char32_t pt = (((str[i] - 0xD800) << 10) | (str[i+1] - 0xDC00)) + 0x10000;
...@@ -426,7 +426,7 @@ static offset_pt utf16_decode_check(const std::u16string & str, std::u16string:: ...@@ -426,7 +426,7 @@ static offset_pt utf16_decode_check(const std::u16string & str, std::u16string::
} }
} }
static char32_t utf16_decode(const std::u16string & str, std::u16string::size_type & i) { static char32_t utf16_decode(const char16_t * str, std::u16string::size_type & i) {
offset_pt res = utf16_decode_check(str, i); offset_pt res = utf16_decode_check(str, i);
if (res.offset < 0) { if (res.offset < 0) {
i += 1; i += 1;
...@@ -472,7 +472,7 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) { ...@@ -472,7 +472,7 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) {
std::string out; std::string out;
out.reserve(str.length() * 3 / 2); // estimate out.reserve(str.length() * 3 / 2); // estimate
for (std::u16string::size_type i = 0; i < str.length(); ) for (std::u16string::size_type i = 0; i < str.length(); )
utf8_encode(utf16_decode(str, i), out); utf8_encode(utf16_decode(str.data(), i), out);
return out; return out;
} }
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
namespace testsuite { namespace testsuite {
static const std::wstring str1 = L"some string with unicode \u263A, \U0001F4A9 symbols"; static const wchar_t s1[] = L"some string with unicode \u0000, \u263A, \U0001F4A9 symbols";
static const std::wstring str1(s1, sizeof(s1) / sizeof(*s1) - 1);
static const std::wstring str2 = L"another string with unicode \u263B, \U0001F4A8 symbols"; static const std::wstring str2 = L"another string with unicode \u263B, \U0001F4A8 symbols";
WcharTestRec WcharTestHelpers::get_record() WcharTestRec WcharTestHelpers::get_record()
......
...@@ -4,7 +4,7 @@ import junit.framework.TestCase; ...@@ -4,7 +4,7 @@ import junit.framework.TestCase;
public class WcharTest extends TestCase { public class WcharTest extends TestCase {
private static final String STR1 = "some string with unicode \u263A, \uD83D\uDCA9 symbols"; private static final String STR1 = "some string with unicode \u0000, \u263A, \uD83D\uDCA9 symbols";
private static final String STR2 = "another string with unicode \u263B, \uD83D\uDCA8 symbols"; private static final String STR2 = "another string with unicode \u263B, \uD83D\uDCA8 symbols";
public void test() { public void test() {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
- (void)test - (void)test
{ {
NSString *str1 = @"some string with unicode \u263A, \U0001F4A9 symbols"; NSString *str1 = @"some string with unicode \u0000, \u263A, \U0001F4A9 symbols";
NSString *str2 = @"another string with unicode \u263B, \U0001F4A8 symbols"; NSString *str2 = @"another string with unicode \u263B, \U0001F4A8 symbols";
XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1); XCTAssertEqualObjects([[DBWcharTestHelpers getRecord] s], str1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment