Content deleted Content added
Pathoschild (talk | contribs) add code documentation, tweaked docs on regex method |
Pathoschild (talk | contribs) use 'token' terminology consistently |
||
Line 44:
* The tokens can be either capturing or non-capturing. The capturing
* tokens make their output available for later processing. Most of the
* capturing
*
* Internally, the routine maintains information about several dates, so
Line 61 ⟶ 60:
* provided as alias to @XX for convenience.
*
* AVAILABLE REGEX
*
* Note: The capturing tokens start with an uppercase letter whereas the
* equivalent non-capturing tokens start with a lowercase letter.
Line 93 ⟶ 92:
* • @@ : Matches a literal @.
*
* AVAILABLE REPLACEMENT STRING
*
* Days:
* • @SD : Outputs a day in numeric format without leading zero (1-31).
Line 131 ⟶ 130:
* of which is an object defining the nth date as parsed by the routine. Each
* object contains numeric values of days, months and years as 'd', 'm' and 'y'
* properties respectively. Each value can be -1 if a
*
* should return true if the replacement should be done, false otherwise.
*
Line 180 ⟶ 179:
var Formats = [
{ type : ParamType.SD, group : Group.DAY,
{ type : ParamType.ZD, group : Group.DAY,
{ type : ParamType.DD, group : Group.DAY,
{ type : ParamType.DAY,group : Group.DAY,
{ type : ParamType.SM, group : Group.MONTH,
{ type : ParamType.ZM, group : Group.MONTH,
{ type : ParamType.MM, group : Group.MONTH,
{
type : ParamType.FMONTH, group : Group.MONTH,
match : /(January|February|March|April|May|June|July|August|September|October|November|December)/
},
{
type : ParamType.MONTH, group : Group.MONTH,
match : /(January|February|March|April|May|June|July|August|September|October|November|December|Jan\.|Jan|Feb\.|Feb|Mar\.|Mar|Apr\.|Apr|May|Jun\.|Jun|Jul\.|Jul|Aug\.|Aug|Sep\.|Sept\.|Sept|Sep|Oct\.|Oct|Nov\.|Nov|Dec\.|Dec)/
},
{ //must be after month entry
type : ParamType.MON, group : Group.MONTH,
match : /(Jan\.|Jan|Feb\.|Feb|Mar\.|Mar|Apr\.|Apr|May|Jun\.|Jun|Jul\.|Jul|Aug\.|Aug|Sep\.|Sept\.|Sept|Sep|Oct\.|Oct|Nov\.|Nov|Dec\.|Dec)/
},
{ type : ParamType.YYYY, group : Group.YEAR,
{ type : ParamType.YYNN, group : Group.YEAR,
{ type : ParamType.YY, group : Group.YEAR,
{ type : ParamType.YEAR, group : Group.YEAR,
];
var NCFormats = [
{
{
{
{
{
{
{
{
match : /(?:January|February|March|April|May|June|July|August|September|October|November|December)/
},
{
match : /(?:January|February|March|April|May|June|July|August|September|October|November|December|Jan\.|Jan|Feb\.|Feb|Mar\.|Mar|Apr\.|Apr|May|Jun\.|Jun|Jul\.|Jul|Aug\.|Aug|Sep\.|Sept\.|Sept|Sep|Oct\.|Oct|Nov\.|Nov|Dec\.|Dec)/
},
{ //must be after month entry
match : /(?:Jan\.|Jan|Feb\.|Feb|Mar\.|Mar|Apr\.|Apr|May|Jun\.|Jun|Jul\.|Jul|Aug\.|Aug|Sep\.|Sept\.|Sept|Sep|Oct\.|Oct|Nov\.|Nov|Dec\.|Dec)/
},
{
{
{
{
// misc
{
];
Line 248 ⟶ 247:
}
// get positions of all capturing
var
for (var i = 0; i < Formats.length; i++) {
var index = -1;
while (1) {
index = reg.indexOf(Formats[i].
if (index == -1)
break;
if (params_by_index[index] === undefined) {
if (
alert("DATE SCRIPT: unsupported number of dates from the same group");
return;
Line 265 ⟶ 264:
param.index = index;
param.type = Formats[i].type;
param.num =
params_by_index[index] = param;
}
}
Line 279 ⟶ 278:
param_desc.sort(function(a,b) {return a.index - b.index;});
//replace
for (var i = 0; i < Formats.length; i++) {
reg = reg.split(Formats[i].
}
for (var i = 0; i < NCFormats.length; i++) {
reg = reg.split(NCFormats[i].
}
reg = reg.split("@@").join("@");
|