rokojori-godot/rokojori-cpp-generator/builds/library/Text.js

50 lines
1.5 KiB
JavaScript

export class MatchResult {
}
export class Text {
static makeSticky(regexp) {
if (regexp.sticky) {
return regexp;
}
var source = regexp.source;
var flags = regexp.flags;
if (flags.indexOf("y") === -1) {
flags += "y";
}
return new RegExp(source, flags);
}
static makeGlobal(regexp) {
if (regexp.global) {
return regexp;
}
var source = regexp.source;
var flags = regexp.flags;
if (flags.indexOf("g") === -1) {
flags += "g";
}
return new RegExp(source, flags);
}
static getMatches(source, regex) {
regex = this.makeGlobal(regex);
let offset = 0;
let matches = [];
while (offset < source.length) {
regex.lastIndex = offset;
let result = regex.exec(source);
let match = result ? result[0] : null;
if (result && result.index != offset && match.length > 0) {
offset = result.index + match.length;
matches.push({ match: match, index: result.index });
}
else {
return matches;
}
}
return matches;
}
static insertText(sourceText, insertText, insertPosition) {
let before = sourceText.substring(0, insertPosition);
let after = sourceText.substring(insertPosition, sourceText.length);
return before + insertText + after;
}
}
//# sourceMappingURL=Text.js.map