Content deleted Content added
join ';' instead of ',' |
〈218 words changed〉add Canada |
||
Line 93:
this.regexp_USstate = (
new RegExp('^(?:' + this.USstates.join('|') + ')$'));
// Canadian provinces
this.CAstates = [
'British Columbia', 'Alberta', 'Saskatchewan', 'Manitoba',
'Ontario', 'Quebec', 'New Brunswick', 'Nova Scotia',
'Prince Edward Island', 'Newfoundland and Labrador'];
this.regexp_CAsubstate = (
new RegExp('^([^,]+), (' + this.CAstates.join('|') + ')$'));
this.regexp_CAstate = (
new RegExp('^(?:' + this.CAstates.join('|') + ')$'));
}
Line 99 ⟶ 110:
if (wtext.match(/:/)) return null;
///////////////////////////////////////////////////////
// USA
if (wlink == wtext &&
wtext.match(location_canonicalize.regexp_USsubstate))
Line 134 ⟶ 147:
}
////////////////////////////////////////////////////////////
// TODO: Canada, India, etc.▼
// Canada
if (wlink == wtext &&
wtext.match(location_canonicalize.regexp_CAsubstate))
{
var city = RegExp.$1, state = RegExp.$2;
var wfull = '[[' + wtext + '|' + city + ']]';
// only add link to state and country if we haven't yet mentioned them.
if (!left.match('\\[\\['+state+'\\]\\]')) {
wfull += ', [['+state+']]';
if (!left.match(/\[\[Canada\]\]/)) {
wfull += ', [[Canada]]';
}
}
// get rid of any redundant subsequent [[USA]] link
right = right.replace(/^, *\[\[Canada\]\]/, '');
return { wfull: wfull, left: left, right: right};
}
if (wlink == wtext && wtext.match(location_canonicalize.regexp_CAstate)) {
// state link -- just make sure there's a [[Canada]] link if necessary
if (!left.match(/\[\[Canada\]\]/)) {
var wfull = '[['+wtext+']]';
wfull += ', [[Canada]]';
// get rid of any redundant subsequent [[Canada]] link
right = right.replace(/^, *\[\[Canada\]\]/, '');
return { wfull: wfull, left: left, right: right};
}
return null;
}
return null;
|