LocalFile::restore(): roll back the DB transaction if the file is missing
[mediawiki.git] / skins / htmldump / utf8.js
blobea3b890c64568d521b5438fbcb15fc4f3c86259f
1 /**
2 * Obtained from http://homepage3.nifty.com/aokura/jscript/index.html
3 * The webpage says, among other things:
4 * * ソースコードの全てあるいは一部を使用したことにより生じた損害に関しては一切責任を負いません。
5 * * ソースコードの使用、配布に制限はありません。ご自由にお使いください。
6 * * 動作チェックが不充分な場合もありますので、注意してください。
7 *
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 /**********************************************************************
17 * Unicode ⇔ UTF-8
19 * Copyright (c) 2005 AOK <soft@aokura.com>
21 **********************************************************************/
23 function _to_utf8(s) {
24 var c, d = "";
25 for (var i = 0; i < s.length; i++) {
26 c = s.charCodeAt(i);
27 if (c <= 0x7f) {
28 d += s.charAt(i);
29 } else if (c >= 0x80 && c <= 0x7ff) {
30 d += String.fromCharCode(((c >> 6) & 0x1f) | 0xc0);
31 d += String.fromCharCode((c & 0x3f) | 0x80);
32 } else {
33 d += String.fromCharCode((c >> 12) | 0xe0);
34 d += String.fromCharCode(((c >> 6) & 0x3f) | 0x80);
35 d += String.fromCharCode((c & 0x3f) | 0x80);
38 return d;
41 function _from_utf8(s) {
42 var c, d = "", flag = 0, tmp;
43 for (var i = 0; i < s.length; i++) {
44 c = s.charCodeAt(i);
45 if (flag == 0) {
46 if ((c & 0xe0) == 0xe0) {
47 flag = 2;
48 tmp = (c & 0x0f) << 12;
49 } else if ((c & 0xc0) == 0xc0) {
50 flag = 1;
51 tmp = (c & 0x1f) << 6;
52 } else if ((c & 0x80) == 0) {
53 d += s.charAt(i);
54 } else {
55 flag = 0;
57 } else if (flag == 1) {
58 flag = 0;
59 d += String.fromCharCode(tmp | (c & 0x3f));
60 } else if (flag == 2) {
61 flag = 3;
62 tmp |= (c & 0x3f) << 6;
63 } else if (flag == 3) {
64 flag = 0;
65 d += String.fromCharCode(tmp | (c & 0x3f));
66 } else {
67 flag = 0;
70 return d;