2 * Obtained from http://homepage3.nifty.com/aokura/jscript/index.html
3 * The webpage says, among other things:
4 * * ソースコードの全てあるいは一部を使用したことにより生じた損害に関しては一切責任を負いません。
5 * * ソースコードの使用、配布に制限はありません。ご自由にお使いください。
6 * * 動作チェックが不充分な場合もありますので、注意してください。
8 * Which, loosely translated, means:
9 * * The author takes no responsibility for damage which occurs due to the use of this code.
10 * * There is no restriction on the use and distribution of the source code. Please use freely.
11 * * Please be careful, testing may have been insufficient.
15 /**********************************************************************
19 * Copyright (c) 2005 AOK <soft@aokura.com>
21 **********************************************************************/
23 function _to_utf8(s
) {
25 for (var i
= 0; i
< s
.length
; i
++) {
29 } else if (c
>= 0x80 && c
<= 0x7ff) {
30 d
+= String
.fromCharCode(((c
>> 6) & 0x1f) | 0xc0);
31 d
+= String
.fromCharCode((c
& 0x3f) | 0x80);
33 d
+= String
.fromCharCode((c
>> 12) | 0xe0);
34 d
+= String
.fromCharCode(((c
>> 6) & 0x3f) | 0x80);
35 d
+= String
.fromCharCode((c
& 0x3f) | 0x80);
41 function _from_utf8(s
) {
42 var c
, d
= "", flag
= 0, tmp
;
43 for (var i
= 0; i
< s
.length
; i
++) {
46 if ((c
& 0xe0) == 0xe0) {
48 tmp
= (c
& 0x0f) << 12;
49 } else if ((c
& 0xc0) == 0xc0) {
51 tmp
= (c
& 0x1f) << 6;
52 } else if ((c
& 0x80) == 0) {
57 } else if (flag
== 1) {
59 d
+= String
.fromCharCode(tmp
| (c
& 0x3f));
60 } else if (flag
== 2) {
62 tmp
|= (c
& 0x3f) << 6;
63 } else if (flag
== 3) {
65 d
+= String
.fromCharCode(tmp
| (c
& 0x3f));