Lines 33-38
using namespace beecrypt::lang;
Link Here
|
33 |
#include <unicode/ustdio.h> |
33 |
#include <unicode/ustdio.h> |
34 |
#include <unicode/ustring.h> |
34 |
#include <unicode/ustring.h> |
35 |
|
35 |
|
|
|
36 |
static_assert(sizeof(jchar) == sizeof(UChar), "jchar and UChar sizes mismatch"); |
37 |
|
36 |
String::String(array<jchar>& swapWith) |
38 |
String::String(array<jchar>& swapWith) |
37 |
{ |
39 |
{ |
38 |
assert(swapWith.size() <= Integer::MAX_VALUE); |
40 |
assert(swapWith.size() <= Integer::MAX_VALUE); |
Lines 56-62
String::String()
Link Here
|
56 |
|
58 |
|
57 |
String::String(char c) : _value(1) |
59 |
String::String(char c) : _value(1) |
58 |
{ |
60 |
{ |
59 |
u_charsToUChars(&c, _value.data(), 1); |
61 |
u_charsToUChars(&c, reinterpret_cast<UChar*>(_value.data()), 1); |
60 |
} |
62 |
} |
61 |
|
63 |
|
62 |
String::String(jchar c) : _value(&c, 1) |
64 |
String::String(jchar c) : _value(&c, 1) |
Lines 67-73
String::String(const char* value) : _value(::strlen(value))
Link Here
|
67 |
{ |
69 |
{ |
68 |
assert(_value.size() <= Integer::MAX_VALUE); |
70 |
assert(_value.size() <= Integer::MAX_VALUE); |
69 |
|
71 |
|
70 |
u_charsToUChars(value, _value.data(), _value.size()); |
72 |
u_charsToUChars(value, reinterpret_cast<UChar*>(_value.data()), _value.size()); |
71 |
} |
73 |
} |
72 |
|
74 |
|
73 |
String::String(const jchar* value, int offset, int length) : _value(value+offset, length) |
75 |
String::String(const jchar* value, int offset, int length) : _value(value+offset, length) |
Lines 449-455
std::ostream& beecrypt::lang::operator<<(std::ostream& stream, const String& str
Link Here
|
449 |
if (U_FAILURE(status)) |
451 |
if (U_FAILURE(status)) |
450 |
throw RuntimeException("ucnv_open failed"); |
452 |
throw RuntimeException("ucnv_open failed"); |
451 |
|
453 |
|
452 |
int need = ucnv_fromUChars(loc, 0, 0, src.data(), src.size(), &status); |
454 |
int need = ucnv_fromUChars(loc, 0, 0, reinterpret_cast<const UChar*>(src.data()), src.size(), &status); |
453 |
if (U_FAILURE(status)) |
455 |
if (U_FAILURE(status)) |
454 |
if (status != U_BUFFER_OVERFLOW_ERROR) |
456 |
if (status != U_BUFFER_OVERFLOW_ERROR) |
455 |
throw RuntimeException("ucnv_fromUChars failed"); |
457 |
throw RuntimeException("ucnv_fromUChars failed"); |
Lines 458-464
std::ostream& beecrypt::lang::operator<<(std::ostream& stream, const String& str
Link Here
|
458 |
|
460 |
|
459 |
status = U_ZERO_ERROR; |
461 |
status = U_ZERO_ERROR; |
460 |
|
462 |
|
461 |
ucnv_fromUChars(loc, out, need+1, src.data(), src.size(), &status); |
463 |
ucnv_fromUChars(loc, out, need+1, reinterpret_cast<const UChar*>(src.data()), src.size(), &status); |
462 |
if (U_FAILURE(status)) |
464 |
if (U_FAILURE(status)) |
463 |
throw RuntimeException("ucnv_fromUChars failed"); |
465 |
throw RuntimeException("ucnv_fromUChars failed"); |
464 |
|
466 |
|