diff options
| author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-31 10:14:38 +0000 |
|---|---|---|
| committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-31 10:14:38 +0000 |
| commit | af3eec49e06486c95749eca01613824c2d49c512 (patch) | |
| tree | eb4a076875f13a6f651362c36661f973c3162e61 /enc | |
| parent | 99a9915b04100c353fd8d79e6940ce5bde9fb290 (diff) | |
| download | ruby-af3eec49e06486c95749eca01613824c2d49c512.tar.gz ruby-af3eec49e06486c95749eca01613824c2d49c512.tar.xz ruby-af3eec49e06486c95749eca01613824c2d49c512.zip | |
* enc/utf_16{be,le}.c (utf16{be,le}_code_to_mbc):
fix codepoint to bytes.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc')
| -rw-r--r-- | enc/utf_16be.c | 14 | ||||
| -rw-r--r-- | enc/utf_16le.c | 15 |
2 files changed, 12 insertions, 17 deletions
diff --git a/enc/utf_16be.c b/enc/utf_16be.c index 2ef319963..f80711d9b 100644 --- a/enc/utf_16be.c +++ b/enc/utf_16be.c @@ -132,14 +132,12 @@ utf16be_code_to_mbc(OnigCodePoint code, UChar *buf, UChar* p = buf; if (code > 0xffff) { - unsigned int plane, high; - - plane = code >> 16; - *p++ = (plane >> 2) + 0xd8; - high = (code & 0xff00) >> 8; - *p++ = ((plane & 0x03) << 6) + (high >> 2); - *p++ = (high & 0x02) + 0xdc; - *p = (UChar )(code & 0xff); + unsigned int high = (code >> 10) + 0xD7C0; + unsigned int low = (code & 0x3FF) + 0xDC00; + *p++ = (high >> 8) & 0xFF; + *p++ = high & 0xFF; + *p++ = (low >> 8) & 0xFF; + *p++ = low & 0xFF; return 4; } else { diff --git a/enc/utf_16le.c b/enc/utf_16le.c index 33bfe08f4..c3712f4e1 100644 --- a/enc/utf_16le.c +++ b/enc/utf_16le.c @@ -126,15 +126,12 @@ utf16le_code_to_mbc(OnigCodePoint code, UChar *buf, UChar* p = buf; if (code > 0xffff) { - unsigned int plane, high; - - plane = code >> 16; - high = (code & 0xff00) >> 8; - - *p++ = ((plane & 0x03) << 6) + (high >> 2); - *p++ = (plane >> 2) + 0xd8; - *p++ = (UChar )(code & 0xff); - *p = (high & 0x02) + 0xdc; + unsigned int high = (code >> 10) + 0xD7C0; + unsigned int low = (code & 0x3FF) + 0xDC00; + *p++ = high & 0xFF; + *p++ = (high >> 8) & 0xFF; + *p++ = low & 0xFF; + *p++ = (low >> 8) & 0xFF; return 4; } else { |
