forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_string.js
183 lines (167 loc) · 4.37 KB
/
caml_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
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
'use strict';
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");
function js_string_of_char(prim) {
return String.fromCharCode(prim);
}
function add(prim, prim$1) {
return prim + prim$1;
}
function caml_string_get(s, i) {
if (i >= s.length || i < 0) {
throw [
Caml_builtin_exceptions.invalid_argument,
"index out of bounds"
];
}
else {
return s.charCodeAt(i);
}
}
function caml_create_string(len) {
if (len < 0) {
throw [
Caml_builtin_exceptions.invalid_argument,
"String.create"
];
}
else {
return new Array(len);
}
}
function caml_string_compare(s1, s2) {
if (s1 === s2) {
return 0;
}
else if (s1 < s2) {
return -1;
}
else {
return 1;
}
}
function caml_fill_string(s, i, l, c) {
if (l > 0) {
for(var k = i ,k_finish = (l + i | 0) - 1 | 0; k <= k_finish; ++k){
s[k] = c;
}
return /* () */0;
}
else {
return 0;
}
}
function caml_blit_string(s1, i1, s2, i2, len) {
if (len > 0) {
var off1 = s1.length - i1 | 0;
if (len <= off1) {
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
s2[i2 + i | 0] = s1.charCodeAt(i1 + i | 0);
}
return /* () */0;
}
else {
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1 <= i_finish$1; ++i$1){
s2[i2 + i$1 | 0] = s1.charCodeAt(i1 + i$1 | 0);
}
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2 <= i_finish$2; ++i$2){
s2[i2 + i$2 | 0] = /* "\000" */0;
}
return /* () */0;
}
}
else {
return 0;
}
}
function caml_blit_bytes(s1, i1, s2, i2, len) {
if (len > 0) {
var off1 = s1.length - i1 | 0;
if (len <= off1) {
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
s2[i2 + i | 0] = s1[i1 + i | 0];
}
return /* () */0;
}
else {
for(var i$1 = 0 ,i_finish$1 = off1 - 1 | 0; i$1 <= i_finish$1; ++i$1){
s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0];
}
for(var i$2 = off1 ,i_finish$2 = len - 1 | 0; i$2 <= i_finish$2; ++i$2){
s2[i2 + i$2 | 0] = /* "\000" */0;
}
return /* () */0;
}
}
else {
return 0;
}
}
function bytes_of_string(s) {
var len = s.length;
var res = new Array(len);
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
res[i] = s.charCodeAt(i);
}
return res;
}
function bytes_to_string(a) {
var bytes = a;
var i = 0;
var len = a.length;
var s = "";
var s_len = len;
if (i === 0 && len <= 4096 && len === bytes.length) {
return String.fromCharCode.apply(null,bytes);
}
else {
var offset = 0;
while(s_len > 0) {
var next = s_len < 1024 ? s_len : 1024;
var tmp_bytes = new Array(next);
caml_blit_bytes(bytes, offset, tmp_bytes, 0, next);
s = s + String.fromCharCode.apply(null,tmp_bytes);
s_len = s_len - next | 0;
offset = offset + next | 0;
};
return s;
}
}
function caml_string_of_char_array(chars) {
var len = chars.length;
var bytes = new Array(len);
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
bytes[i] = chars[i];
}
return bytes_to_string(bytes);
}
function caml_is_printable(c) {
var code = c;
if (code > 31) {
return +(code < 127);
}
else {
return /* false */0;
}
}
function caml_string_get16(s, i) {
return s.charCodeAt(i) + (s.charCodeAt(i + 1 | 0) << 8) | 0;
}
function caml_string_get32(s, i) {
return ((s.charCodeAt(i) + (s.charCodeAt(i + 1 | 0) << 8) | 0) + (s.charCodeAt(i + 2 | 0) << 16) | 0) + (s.charCodeAt(i + 3 | 0) << 24) | 0;
}
exports.add = add;
exports.bytes_of_string = bytes_of_string;
exports.bytes_to_string = bytes_to_string;
exports.caml_is_printable = caml_is_printable;
exports.caml_string_of_char_array = caml_string_of_char_array;
exports.caml_string_get = caml_string_get;
exports.caml_string_compare = caml_string_compare;
exports.caml_create_string = caml_create_string;
exports.caml_fill_string = caml_fill_string;
exports.caml_blit_string = caml_blit_string;
exports.caml_blit_bytes = caml_blit_bytes;
exports.caml_string_get16 = caml_string_get16;
exports.caml_string_get32 = caml_string_get32;
exports.js_string_of_char = js_string_of_char;
/* No side effect */