forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.js
229 lines (199 loc) · 5.49 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
'use strict';
var Bytes = require("./bytes");
var Caml_int32 = require("./caml_int32");
var Caml_string = require("./caml_string");
var List = require("./list");
function make(n, c) {
return Caml_string.bytes_to_string(Bytes.make(n, c));
}
function init(n, f) {
return Caml_string.bytes_to_string(Bytes.init(n, f));
}
function copy(s) {
return Caml_string.bytes_to_string(Bytes.copy(Caml_string.bytes_of_string(s)));
}
function sub(s, ofs, len) {
return Caml_string.bytes_to_string(Bytes.sub(Caml_string.bytes_of_string(s), ofs, len));
}
function concat(sep, l) {
if (l) {
var hd = l[0];
var num = [0];
var len = [0];
List.iter(function (s) {
num[0] = num[0] + 1 | 0;
len[0] = len[0] + s.length | 0;
return /* () */0;
}, l);
var r = Caml_string.caml_create_string(len[0] + Caml_int32.imul(sep.length, num[0] - 1 | 0) | 0);
Caml_string.caml_blit_string(hd, 0, r, 0, hd.length);
var pos = [hd.length];
List.iter(function (s) {
Caml_string.caml_blit_string(sep, 0, r, pos[0], sep.length);
pos[0] = pos[0] + sep.length | 0;
Caml_string.caml_blit_string(s, 0, r, pos[0], s.length);
pos[0] = pos[0] + s.length | 0;
return /* () */0;
}, l[1]);
return Caml_string.bytes_to_string(r);
}
else {
return "";
}
}
function iter(f, s) {
return Bytes.iter(f, Caml_string.bytes_of_string(s));
}
function iteri(f, s) {
return Bytes.iteri(f, Caml_string.bytes_of_string(s));
}
function map(f, s) {
return Caml_string.bytes_to_string(Bytes.map(f, Caml_string.bytes_of_string(s)));
}
function mapi(f, s) {
return Caml_string.bytes_to_string(Bytes.mapi(f, Caml_string.bytes_of_string(s)));
}
function is_space(param) {
var switcher = param - 9 | 0;
if (switcher > 4 || switcher < 0) {
if (switcher !== 23) {
return /* false */0;
}
else {
return /* true */1;
}
}
else if (switcher !== 2) {
return /* true */1;
}
else {
return /* false */0;
}
}
function trim(s) {
if (s === "" || !(is_space(s.charCodeAt(0)) || is_space(s.charCodeAt(s.length - 1 | 0)))) {
return s;
}
else {
return Caml_string.bytes_to_string(Bytes.trim(Caml_string.bytes_of_string(s)));
}
}
function escaped(s) {
var needs_escape = function (_i) {
while(true) {
var i = _i;
if (i >= s.length) {
return /* false */0;
}
else {
var c = s.charCodeAt(i);
var exit = 0;
if (c >= 14) {
if (c !== 34) {
if (c !== 92) {
exit = 1;
}
else {
return /* true */1;
}
}
else {
return /* true */1;
}
}
else if (c >= 11) {
if (c >= 13) {
return /* true */1;
}
else {
exit = 1;
}
}
else if (c >= 8) {
return /* true */1;
}
else {
exit = 1;
}
if (exit === 1) {
if (Caml_string.caml_is_printable(c)) {
_i = i + 1 | 0;
continue ;
}
else {
return /* true */1;
}
}
}
};
};
if (needs_escape(0)) {
return Caml_string.bytes_to_string(Bytes.escaped(Caml_string.bytes_of_string(s)));
}
else {
return s;
}
}
function index(s, c) {
return Bytes.index(Caml_string.bytes_of_string(s), c);
}
function rindex(s, c) {
return Bytes.rindex(Caml_string.bytes_of_string(s), c);
}
function index_from(s, i, c) {
return Bytes.index_from(Caml_string.bytes_of_string(s), i, c);
}
function rindex_from(s, i, c) {
return Bytes.rindex_from(Caml_string.bytes_of_string(s), i, c);
}
function contains(s, c) {
return Bytes.contains(Caml_string.bytes_of_string(s), c);
}
function contains_from(s, i, c) {
return Bytes.contains_from(Caml_string.bytes_of_string(s), i, c);
}
function rcontains_from(s, i, c) {
return Bytes.rcontains_from(Caml_string.bytes_of_string(s), i, c);
}
function uppercase(s) {
return Caml_string.bytes_to_string(Bytes.uppercase(Caml_string.bytes_of_string(s)));
}
function lowercase(s) {
return Caml_string.bytes_to_string(Bytes.lowercase(Caml_string.bytes_of_string(s)));
}
function capitalize(s) {
return Caml_string.bytes_to_string(Bytes.capitalize(Caml_string.bytes_of_string(s)));
}
function uncapitalize(s) {
return Caml_string.bytes_to_string(Bytes.uncapitalize(Caml_string.bytes_of_string(s)));
}
var compare = Caml_string.caml_string_compare
var fill = Bytes.fill;
var blit = Bytes.blit_string;
exports.make = make;
exports.init = init;
exports.copy = copy;
exports.sub = sub;
exports.fill = fill;
exports.blit = blit;
exports.concat = concat;
exports.iter = iter;
exports.iteri = iteri;
exports.map = map;
exports.mapi = mapi;
exports.trim = trim;
exports.escaped = escaped;
exports.index = index;
exports.rindex = rindex;
exports.index_from = index_from;
exports.rindex_from = rindex_from;
exports.contains = contains;
exports.contains_from = contains_from;
exports.rcontains_from = rcontains_from;
exports.uppercase = uppercase;
exports.lowercase = lowercase;
exports.capitalize = capitalize;
exports.uncapitalize = uncapitalize;
exports.compare = compare;
/* No side effect */