bs-ajv
Version:
BucklesScript bindings to Ajv (Another JSON Validator)
204 lines (173 loc) • 5.17 kB
JavaScript
;
var List = require("./list.js");
var Bytes = require("./bytes.js");
var Caml_int32 = require("./caml_int32.js");
var Caml_string = require("./caml_string.js");
var Caml_primitive = require("./caml_primitive.js");
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 match = s.charCodeAt(i);
if (match >= 32) {
var switcher = match - 34 | 0;
if (switcher > 58 || switcher < 0) {
if (switcher >= 93) {
return /* true */1;
} else {
_i = i + 1 | 0;
continue ;
}
} else if (switcher > 57 || switcher < 1) {
return /* true */1;
} else {
_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_primitive.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 */