Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Here split some special cases like: period (`terminal.integrated`),
// digit (`good2know`), dash (`wp-admin`) etc. Other consequence should
// be that these words are spelled both as split and as the whole.
var rother = XRegExp('([^\ \.0-9\-\(\)‘’]+)');
var rsep = /[\ \.0-9\-\(\)‘’]/;
var parts = [];
// We need a phantom split (e.g. for "2sth", "(sth)" case).
if (rsep.test(word)) {
parts.push({
word: '',
offset: 0
});
}
XRegExp.forEach(word, rother, (match, i) => {
parts.push({
word: match[0],
offset: match.index
});
});
return parts;
}
SpellRight.prototype.splitSnakeCase = function (word) {
// SnakeCase cases: HTML_Script, snake_Case, __test__.
var rsnake = XRegExp('([^_]+)');
var rsep = /_/;
var parts = [];
// We need a phantom split (e.g. for "_sth: case).
if (rsep.test(word)) {
parts.push({
word: '',
offset: 0
});
}
XRegExp.forEach(word, rsnake, (match, i) => {
parts.push({
word: match[0],
offset: match.index
});
});
return parts;
}
static getMatchesSimple(regex: RegExp, source: string): Match[] {
// Word boundary (\b) in JS is not unicode-aware, so words starting/ending with accentuated characters will not match
// use a normalized string to match, the return matches' values using the original one
// http://blog.stevenlevithan.com/archives/javascript-regex-and-unicode
// https://stackoverflow.com/questions/2881445/utf-8-word-boundary-regex-in-javascript
let normalized = StringUtility.removeDiacriticsFromWordBoundaries(source);
let matches = new Array();
XRegExp.forEach(normalized, regex, match => {
let groups: { [id: string]: { value: string, index: number, length: number, captures: string[] } } = {};
let lastGroup = '';
Object.keys(match).forEach(key => {
let groupKey = key.substr(0, key.lastIndexOf('__'));
lastGroup = groupKey;
if (!groups[groupKey]) {
groups[groupKey] = { value: '', index: 0, length: 0, captures: [] };
}
if (match[key]) {
let index = match.index + match[0].indexOf(match[key]);
let length = match[key].length;
let value = source.substr(index, length);
txt = xre.replace(txt, xre("T<([^/].*?)>", "sg"), "<span class="\"T\"">$1</span>");
txt = xre.replace(txt, xre("O<([^/].*?)>", "sg"), "<span class="\"O\"">$1</span>");
txt = xre.replace(txt, xre("C<([^/].*?)>", "sg"), "<code>$1</code>");
txt = xre.replace(txt, xre("I<([^/].*?):(\\d+)>", "sg"), "<img width="\"$2\"/" src="\"$1\"" style="\"float:">");
/* convert typography aspects */
txt = xre.replace(txt, xre("->", "sg"), "→");
txt = xre.replace(txt, xre("<-", "sg"), "←");
txt = xre.replace(txt, xre("--", "sg"), "—");
txt = xre.replace(txt, xre("(FIXME|TODO)", "sg"), "<span class="\"$1\"">$1</span>");
return txt;
}
/* parse first-level structure */
xre.forEach(txt, xre(
"([A-Z][^\\n]+)\\n" + // headline
"---+[ \\t]*\\n" + // underlining
"(.+?\\n)" + // body
"(?=[A-Z][^\\n]+?\\n" + // following headline
"---+[ \\t]*\\n" + // corresponding underlining
"|$)", // or at end file
"sg"), function (m) {
parse2(m[1], m[2]);
});
/* process first-level structure */
function parse2 (title, body) {
/* generate body headline */
html_spec += "<h2>" + mklink(1, title) + "</h2>\n";
/* start navigation entry */
SpellRight.prototype.splitCamelCase = function (word) {
// CamelCase cases: HTMLScript, camelCase, CamelCase, innerHTML,
// start0Case, snake_case, Snake_Case, HOMEToRent.
var rcamel = XRegExp('(^[\\p{Ll}.@\']+)|[0-9]+|[\\p{Lu}.@\'][\\p{Ll}.@\']+|[\\p{Lu}.@\']+(?=[\\p{Lu}.@\'][\\p{Ll}.@\']|[0-9])|[\\p{Lu}.@\']+');
var parts = [];
XRegExp.forEach(word, rcamel, (match, i) => {
parts.push({
word: match[0],
offset: match.index
});
});
return parts;
}
this.attributes["sfen"].split("/").forEach((e, y) => {
let x = 0
XRegExp.forEach(e, XRegExp("(?\\+?)(?\\S)"), (m, i) => {
if (/\d+/.test(m.piece)) {
x += Number(m.piece)
} else {
const soldier = new Soldier({
place: new Place([x, y]),
piece: Piece.fetch(m.piece),
promoted: (m.promoted === "+"),
location: this.__location_by_upper_or_lower_case(m.piece),
})
board.place_on(soldier)
x++
}
})
})
return board
this.regex.forEach((regex) => {
if (typeof regex === 'function') {
regex(this.output).forEach(function (match) {
this.push(match);
}.bind(this.currentMatch));
} else {
require('xregexp').forEach(this.output, regex, matchFunction.bind(this.currentMatch));
}
});
get hold_pieces() {
const _hold_pieces = super.hold_pieces
if (this.attributes["hold_pieces"] !== "-") {
XRegExp.forEach(this.attributes["hold_pieces"], XRegExp("(?\\d+)?(?\\S)"), (md, i) => {
const piece = Piece.fetch(md.piece_char)
let count = Number(md.count || 1)
const location = this.__location_by_upper_or_lower_case(md.piece_char)
count += _hold_pieces.get(location.key).get(piece.key) || 0
_hold_pieces.get(location.key).set(piece.key, count)
})
}
return _hold_pieces
}