sm correctly read strings as utf8 even if JS_EncodeCharacters doesn't work as documented

This commit is contained in:
Aaron
2009-05-27 16:09:59 -04:00
parent 5d113ff1d0
commit 3b2ecb5ff0
2 changed files with 22 additions and 2 deletions

View File

@@ -86,10 +86,13 @@ namespace mongo {
if( srclen == 0 )
return "";
size_t len = srclen * 4;
size_t len = srclen * 6; // we only need *3, but see note on len below
char * dst = (char*)malloc( len );
len /= 2; // weird JS_EncodeCharacters api expects len in 16bit units but modifies it to represent size in 8bit units.
len /= 2;
// doc re weird JS_EncodeCharacters api claims len expected in 16bit
// units, but experiments suggest 8bit units expected. We allocate
// enough memory that either will work.
assert( JS_EncodeCharacters( _context , s , srclen , dst , &len) );