Funkce Charles Lodera ze skriptu transliterate.js
/*
Copyright 2019 Charles Loder
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* My functions */
/* This creates comments there where are non hebrew characters
The comments are defined by curly braces.
The text in braces will not be parsed.
The braces must be preceded & followed by space
or some word separator.
*/
String.prototype.splitAndReplaceBraces = function () {
var alpnum = /([\u1-\u0589, \u05F3-\uFB19, \uFB50-\uFFFF]+)/g;
var remove_braces = /{(\w|[ \s]+)}/g;
var flip_left = /{([ \.;,!\?:])/g;
var flip_right = /([ \.,;!\?:])}/g;
if (comments.checked && alphanum.checked)
return this.replace(alpnum,'{$1}'). // add braces
replace(remove_braces, '$1'). // remove braces with a single character or whitespaces
replace(flip_left, '$1{'). // flip word separator
replace(flip_right, '}$1'). // flip word separator
replace(/{}/g, ''); // the "," can create "{}," or ":" can create "{}", so I simplify to "," or ":"
return;
};
String.prototype.splitFirst = function () {
if (comments.checked)
return this.match(/\{[^{]*\}|[^ ]+/g)
else
return this;
};
String.prototype.splitSecond = function () {
if ( comments.checked && this.charAt(0)=='{' )
return [this.valueOf()]
else
return this.split('');
};
// var test = "{31} one two"
// console.log(test.splitSecond);
Komentáře
Okomentovat