diff options
| author | SVN Migration <svn@php.net> | 2006-05-05 15:49:42 +0000 |
|---|---|---|
| committer | SVN Migration <svn@php.net> | 2006-05-05 15:49:42 +0000 |
| commit | 608baa409a04649e96691a93810130361fe3dff5 (patch) | |
| tree | ef8a236ac0acc846eb4f781c055258eaa5b510a0 /ext/json/utf8_to_utf16.c | |
| parent | 55f0daf65d4ce45837d91de36aea85669b6bc782 (diff) | |
| download | php-git-608baa409a04649e96691a93810130361fe3dff5.tar.gz | |
This commit was manufactured by cvs2svn to create branch 'PHP_5_2'.
Diffstat (limited to 'ext/json/utf8_to_utf16.c')
| -rw-r--r-- | ext/json/utf8_to_utf16.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/json/utf8_to_utf16.c b/ext/json/utf8_to_utf16.c new file mode 100644 index 0000000000..bc2d6f36d6 --- /dev/null +++ b/ext/json/utf8_to_utf16.c @@ -0,0 +1,56 @@ +/* utf8_to_utf16.c */ + +/* 2005-12-25 */ + +/* +Copyright (c) 2005 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "utf8_to_utf16.h" +#include "utf8_decode.h" + +int +utf8_to_utf16(unsigned short w[], char p[], int length) +{ + int c; + int the_index = 0; + json_utf8_decode utf8; + + utf8_decode_init(&utf8, p, length); + for (;;) { + c = utf8_decode_next(&utf8); + if (c < 0) { + return UTF8_END ? the_index : UTF8_ERROR; + } + if (c < 0x10000) { + w[the_index] = (unsigned short)c; + the_index += 1; + } else { + c &= 0xFFFF; + w[the_index] = (unsigned short)(0xD800 | (c >> 10)); + the_index += 1; + w[the_index] = (unsigned short)(0xDC00 | (c & 0x3FF)); + the_index += 1; + } + } +} |
