-
Notifications
You must be signed in to change notification settings - Fork 0
/
String.js
155 lines (128 loc) · 3.27 KB
/
String.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 1991-2022 Amebis
Copyright © 2016 GÉANT
*/
/*@cc_on @*/
/*@if (! @__STRING_JS__) @*/
/*@set @__STRING_JS__ = true @*/
var _S_stat = null;
function _S(str)
{
if (!_S_stat) {
_S_stat = {
"re_apost": new RegExp("'", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(_S_stat.re_apost, "''");
}
var _MSI_stat = null;
function _MSI(str)
{
if (!_MSI_stat) {
_MSI_stat = {
"re_nonid": new RegExp("[^a-zA-Z0-9_\\.]", "g"),
"re_noninitial": new RegExp("^([^a-zA-Z_])", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(_MSI_stat.re_nonid, "_").replace(_MSI_stat.re_noninitial, "_\\1");
}
var LF2CRLF_stat = null;
function LF2CRLF(str)
{
if (!LF2CRLF_stat) {
LF2CRLF_stat = {
"re_lf": new RegExp("\n", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(LF2CRLF_stat.re_lf, "\r\n");
}
var CRLF2LF_stat = null;
function CRLF2LF(str)
{
if (!CRLF2LF_stat) {
CRLF2LF_stat = {
"re_crlf": new RegExp("\r\n", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(CRLF2LF_stat.re_crlf, "\n");
}
var Trim_stat = null;
function Trim(str)
{
if (!Trim_stat) {
Trim_stat = {
"re_lspace": new RegExp("\\s+$", "g"),
"re_rspace": new RegExp("^\\s+", "g")
};
}
if (str == null) return null;
switch (typeof(str)) {
case "string": break;
case "undefined": return null;
default: try { str = str.toString(); } catch (err) { return null; }
}
return str.replace(Trim_stat.re_lspace, "").replace(Trim_stat.re_rspace, "");
}
function Time2Str(date)
{
var
time = new Array(date.getHours(), date.getMinutes(), date.getSeconds()),
i, str = "";
for (i = 0; i < 3; i++) {
if (i) str += ":";
if (time[i] < 10) str += "0";
str += time[i];
}
return str;
}
function CodePageToId(codepage)
{
switch (codepage) {
case 0: {
var wsh = new ActiveXObject("WScript.Shell");
return CodePageToId(parseInt(wsh.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP"), 10));
}
case 932 : return "shift-jis";
case 936 : return "gb2312";
case 949 : return "euc-kr";
case 950 : return "big5";
case 874 :
case 1250 :
case 1251 :
case 1252 :
case 1253 :
case 1254 :
case 1255 :
case 1256 :
case 1257 :
case 1258 : return "windows-" + codepage.toString(10);
case 65001: return "utf-8";
default : throw new Error("Unsupported code page.");
}
}
/*@end @*/