Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions include/hxString.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
#ifdef HXCPP_PARANOID
unsigned int result = calcHash();

unsigned int have = (((unsigned int *)__s)[-1] & HX_GC_CONST_ALLOC_BIT) ?
((unsigned int *)__s)[-2] : *((unsigned int *)(__s+length+1) );
unsigned int have = (((unsigned int *)__s)[-1] & HX_GC_CONST_ALLOC_BIT) ? ((unsigned int *)__s)[-2] :
isUTF16Encoded() ? *((unsigned int *)(__w+length+1)) : *((unsigned int *)(__s+length+1));

if ( have != result )
{
Expand All @@ -247,6 +247,13 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
return ((unsigned int *)__s)[-2];
#endif
}
if (isUTF16Encoded()) {
#ifdef __EMSCRIPTEN__
return *((emscripten_align1_int *)(__w+length+1));
#else
return *((unsigned int *)(__w+length+1));
#endif
}
#ifdef __EMSCRIPTEN__
return *((emscripten_align1_int *)(__s+length+1) );
#else
Expand Down
11 changes: 7 additions & 4 deletions src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,10 @@ unsigned int String::calcSubHash(int start, int inLen) const
if (isUTF16Encoded())
{
const char16_t *w = __w + start;
for(int i=0;i<inLen;i++)
const char16_t *end = w + inLen;
while (w < end)
{
int c = w[i];
int c = Char16Advance(w, false);
if( c <= 0x7F )
{
ADD_HASH(c);
Expand Down Expand Up @@ -977,9 +978,11 @@ unsigned int String::calcHash() const
#ifdef HX_SMART_STRINGS
if (isUTF16Encoded())
{
for(int i=0;i<length;i++)
const char16_t *w = __w;
const char16_t *end = w + length;
while (w < end)
{
int c = __w[i];
int c = Char16Advance(w, false);
if( c <= 0x7F )
{
ADD_HASH(c);
Expand Down
22 changes: 22 additions & 0 deletions test/haxe/TestStringHash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,26 @@ class TestStringHash extends Test
Assert.pass();
}

public function testUnicode()
{
for (literal in ["á", "👍"]) {
var fromJson:String = haxe.Json.parse('\"$literal\"');
var fromBytes = haxe.io.Bytes.ofString(literal).toString();

Assert.equals(literal, fromJson);
Assert.equals(fromJson, fromBytes);
Assert.equals(literal, fromBytes);

var m = new Map<String, Int>();
m[literal] = 1;

Assert.isTrue(m.exists(literal));
Assert.isTrue(m.exists(fromJson));
Assert.isTrue(m.exists(fromBytes));

Assert.equals(1, m[literal]);
Assert.equals(1, m[fromJson]);
Assert.equals(1, m[fromBytes]);
}
}
}
Loading