From 96d9b6cdb3521d16238694c399fc796e71d8ec9a Mon Sep 17 00:00:00 2001
From: Frank Bennett
Date: Fri, 22 Feb 2019 17:13:12 +0900
Subject: [PATCH] More syntax fixes
---
src/.jshintrc | 2 +-
src/util_dateparser.js | 27 ++++---
src/util_dates.js | 6 +-
src/util_disambig.js | 6 +-
src/util_flipflop.js | 161 +++++++++++++++----------------------
src/util_locale.js | 3 +-
src/util_locale_sniff.js | 5 +-
src/util_modules.js | 12 ++-
src/util_name_particles.js | 20 +++--
src/util_names.js | 8 +-
src/util_names_common.js | 1 -
src/util_names_divide.js | 6 +-
src/util_names_etal.js | 2 +-
src/util_names_join.js | 2 +-
src/util_names_output.js | 2 +-
src/util_names_render.js | 61 ++++++--------
src/util_nodes.js | 20 ++---
src/util_number.js | 85 +++++++++++---------
src/util_page.js | 4 +-
src/util_parallel.js | 12 +--
src/util_processor.js | 15 ++--
src/util_publishers.js | 2 -
src/util_static_locator.js | 6 +-
src/util_substitute.js | 45 ++++++-----
src/util_transform.js | 66 +++++++--------
25 files changed, 270 insertions(+), 309 deletions(-)
diff --git a/src/.jshintrc b/src/.jshintrc
index 839112e9b..0b025240d 100644
--- a/src/.jshintrc
+++ b/src/.jshintrc
@@ -27,7 +27,7 @@
// Code Complexity
- "maxparams" : 6, // max number of formal parameters allowed per function
+ "maxparams" : 8, // max number of formal parameters allowed per function
"maxdepth" : 9, // control how nested do you want your blocks to be
"maxstatements" : 370, // max number of statements allowed per function
"maxcomplexity" : 128, // control cyclomatic complexity throughout your code
diff --git a/src/util_dateparser.js b/src/util_dateparser.js
index ddfd35726..e327a1c7c 100644
--- a/src/util_dateparser.js
+++ b/src/util_dateparser.js
@@ -1,7 +1,7 @@
/*global CSL: true */
-CSL.DateParser = new function () {
+CSL.DateParser = function () {
/*
* Fixed values
@@ -24,9 +24,12 @@ CSL.DateParser = new function () {
}
var epochMatchStrings = [];
+ var epochMap = {};
for (var i=0,ilen=epochPairs.length; iReturns the result as a string.
*/
-CSL.Util.Dates.year.imperial = function (state, num, end, makeShort) {
+CSL.Util.Dates.year.imperial = function (state, num, end) {
var year = "";
if (!num) {
if ("boolean" === typeof num) {
@@ -79,7 +79,7 @@ CSL.Util.Dates.year.imperial = function (state, num, end, makeShort) {
}
if (state.transform.abbrevs['default']['number'][normalizedKey]) {
label = state.transform.abbrevs['default']['number'][normalizedKey];
- };
+ }
year = label + (num - offset);
}
return year;
@@ -153,7 +153,7 @@ CSL.Util.Dates.normalizeMonth = function (num, useSeason) {
ret = num;
}
return ret;
-}
+};
CSL.Util.Dates.month = {};
diff --git a/src/util_disambig.js b/src/util_disambig.js
index c0f4f1c7f..69cddb24a 100644
--- a/src/util_disambig.js
+++ b/src/util_disambig.js
@@ -1,7 +1,7 @@
/*global CSL: true */
CSL.ambigConfigDiff = function(a, b) {
- var ret, pos, len, ppos, llen;
+ var pos, len, ppos, llen;
// return of true means the ambig configs differ
if (a.names.length !== b.names.length) {
//print(" (1)");
@@ -32,8 +32,8 @@ CSL.ambigConfigDiff = function(a, b) {
return 0;
};
-CSL.cloneAmbigConfig = function (config, oldconfig, tainters) {
- var i, ilen, j, jlen, k, klen, param;
+CSL.cloneAmbigConfig = function (config, oldconfig) {
+ var i, ilen, j, jlen, param;
var ret = {};
ret.names = [];
ret.givens = [];
diff --git a/src/util_flipflop.js b/src/util_flipflop.js
index c195f980e..222ca1cb1 100644
--- a/src/util_flipflop.js
+++ b/src/util_flipflop.js
@@ -9,7 +9,6 @@
// 2. Second pass: tags
CSL.Util.FlipFlopper = function(state) {
- this.processTags = processTags;
/**
* INTERNAL
@@ -126,10 +125,10 @@ CSL.Util.FlipFlopper = function(state) {
"false": "true"
}
}
- }
+ };
- _nestingData["(\""] = _nestingData[" \""]
- _nestingData["(\'"] = _nestingData[" \'"]
+ _nestingData["(\""] = _nestingData[" \""];
+ _nestingData["(\'"] = _nestingData[" \'"];
var localeOpenQuote = state.getTerm("open-quote");
var localeCloseQuote = state.getTerm("close-quote");
@@ -150,47 +149,19 @@ CSL.Util.FlipFlopper = function(state) {
_nestingData[localeOpenInnerQuote].closer = localeCloseInnerQuote;
}
- var _nestingQuoteReverse = function() {
- var ret = {};
- var keys = Object.keys(_nestingData);
- for (var i = 0, l = keys.length; i < l; i++) {
- var key = keys[i];
- if (_nestingData[key].type === "quote") {
- ret[_nestingData[key].closer] = _nestingData[key];
- }
- }
- return ret;
- }();
-
- var _nestingDataAttr = function() {
- var ret = {};
- var keys = Object.keys(_nestingData);
- for (var i = 0, l = keys.length; i < l; i++) {
- var key = keys[i];
- if (_nestingData[key].type === "nocase") continue;
- var attr = _nestingData[key].attr;
- var outer = _nestingData[key].outer;
- var inner = _nestingData[key].flipflop[_nestingData[key].outer];
- ret[attr + "/" + outer] = _nestingData[key];
- ret[attr + "/" + inner] = _nestingData[key];
- }
- return ret;
- }();
-
function _setOuterQuoteForm(quot) {
var flip = {
" \'": " \"",
" \"": " \'",
"(\"": "(\'",
"(\'": "(\""
- }
+ };
_nestingData[quot].outer = "true";
_nestingData[flip[quot]].outer = "inner";
}
function _getNestingOpenerParams(opener) {
var openers = [];
- var closer;
var keys = Object.keys(_nestingData);
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
@@ -199,11 +170,13 @@ CSL.Util.FlipFlopper = function(state) {
}
}
var ret = _nestingData[opener];
- ret.opener = new RegExp("^(?:" + openers.map(function(str){return str.replace("(", "\\(")}).join("|") + ")");
+ ret.opener = new RegExp("^(?:" + openers.map(function(str){
+ return str.replace("(", "\\(");
+ }).join("|") + ")");
return ret;
}
- var _nestingParams = function() {
+ var _nestingParams = (function() {
var ret = {};
var keys = Object.keys(_nestingData);
for (var i = 0, l = keys.length; i < l; i++) {
@@ -211,9 +184,9 @@ CSL.Util.FlipFlopper = function(state) {
ret[key] = _getNestingOpenerParams(key);
}
return ret;
- }()
+ }());
- var _tagRex = function() {
+ var _tagRex = (function() {
var openers = [];
var closers = [];
var vals = {};
@@ -227,28 +200,20 @@ CSL.Util.FlipFlopper = function(state) {
closers.push(closer);
}
- var all = openers.concat(closers).map(function(str){return str.replace("(", "\\(")}).join("|");
+ var all = openers.concat(closers).map(function(str){
+ return str.replace("(", "\\(");
+ }).join("|");
return {
matchAll: new RegExp("((?:" + all + "))", "g"),
splitAll: new RegExp("(?:" + all + ")", "g"),
- open: new RegExp("(^(?:" + openers.map(function(str){return str.replace("(", "\\(")}).join("|") + ")$)"),
+ open: new RegExp("(^(?:" + openers.map(function(str){
+ return str.replace("(", "\\(");
+ }).join("|") + ")$)"),
close: new RegExp("(^(?:" + closers.join("|") + ")$)"),
- }
- }();
+ };
+ }());
- function _nestingFix (tag, pos) {
- return _pushNestingState(tag, pos);
- }
-
- function _pushNestingState(tag, pos) {
- if (tag.match(_tagRex.open)) {
- return _tryOpen(tag, pos);
- } else {
- return _tryClose(tag, pos);
- }
- }
-
function _tryOpen(tag, pos) {
var params = _nestingState[_nestingState.length - 1];
if (!params || tag.match(params.opener)) {
@@ -260,7 +225,7 @@ CSL.Util.FlipFlopper = function(state) {
});
return false;
} else {
- _nestingState.pop()
+ _nestingState.pop();
_nestingState.push({
type: _nestingParams[tag].type,
opener: _nestingParams[tag].opener,
@@ -276,14 +241,14 @@ CSL.Util.FlipFlopper = function(state) {
function _tryClose(tag, pos) {
var params = _nestingState[_nestingState.length - 1];
if (params && tag === params.closer) {
- _nestingState.pop()
+ _nestingState.pop();
if (params.type === "nocase") {
return {
nocase: {
open: params.pos,
close: pos
}
- }
+ };
} else {
return false;
}
@@ -300,6 +265,18 @@ CSL.Util.FlipFlopper = function(state) {
}
}
+ function _pushNestingState(tag, pos) {
+ if (tag.match(_tagRex.open)) {
+ return _tryOpen(tag, pos);
+ } else {
+ return _tryClose(tag, pos);
+ }
+ }
+
+ function _nestingFix (tag, pos) {
+ return _pushNestingState(tag, pos);
+ }
+
function _doppelString(str) {
var forcedSpaces = [];
// Normalize markup
@@ -319,7 +296,7 @@ CSL.Util.FlipFlopper = function(state) {
for (var i=0,ilen=match.length-1;i -1) {
- match[i+1] = " " + match[i+1]
+ match[i+1] = " " + match[i+1];
forcedSpaces.push(true);
} else {
forcedSpaces.push(false);
@@ -330,25 +307,12 @@ CSL.Util.FlipFlopper = function(state) {
tags: match,
strings: split,
forcedSpaces: forcedSpaces
- }
+ };
}
- function _undoppelString(obj) {
- var lst = obj.strings.slice(-1);
- for (var i=obj.tags.length-1; i>-1; i+=-1) {
- lst.push(obj.tags[i]);
- lst.push(obj.strings[i]);
- }
- lst.reverse();
- return lst.join("|");
- }
-
- var _TagReg = function(blob) {
- this.set = set;
- this.pair = pair;
- this.pop = pop;
+ var TagReg = function(blob) {
var _stack = [];
- function set(tag) {
+ this.set = function (tag) {
var attr = _nestingData[tag].attr;
var decor = null;
for (var i=_stack.length-1;i>-1;i--) {
@@ -359,11 +323,13 @@ CSL.Util.FlipFlopper = function(state) {
}
}
if (!decor) {
- var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(blob.alldecor)
+ var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(blob.alldecor);
outer:
for (var i=allTheDecor.length-1;i>-1;i--) {
var decorset = allTheDecor[i];
- if (!decorset) continue;
+ if (!decorset) {
+ continue;
+ }
for (var j=decorset.length-1;j>-1;j--) {
var _decor = decorset[j];
if (_decor[0] === attr) {
@@ -379,14 +345,14 @@ CSL.Util.FlipFlopper = function(state) {
decor = [attr, _nestingData[tag].flipflop[decor[1]]];
}
_stack.push(decor);
- }
- function pair() {
+ };
+ this.pair = function () {
return _stack[_stack.length-1];
- }
- function pop() {
+ };
+ this.pop = function () {
_stack.pop();
- }
- }
+ };
+ };
function _apostropheForce(tag, str) {
if (tag === "\'") {
@@ -400,14 +366,13 @@ CSL.Util.FlipFlopper = function(state) {
}
function _undoppelToQueue(blob, doppel, leadingSpace) {
- var TOP = blob;
var firstString = true;
- var tagReg = new _TagReg(blob);
+ var tagReg = new TagReg(blob);
blob.blobs = [];
function Stack (blob) {
this.stack = [blob];
this.latest = blob;
- this.addStyling = function(str, decor, forcedSpace) {
+ this.addStyling = function(str, decor) {
if (firstString) {
if (str.slice(0, 1) === " ") {
str = str.slice(1);
@@ -436,10 +401,12 @@ CSL.Util.FlipFlopper = function(state) {
if (decor[0] === "@class" && decor[1] === "nodecor") {
var newdecorset = [];
var seen = {};
- var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(newblob.alldecor)
+ var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(newblob.alldecor);
for (var i=allTheDecor.length-1;i>-1;i--) {
var _decorset = allTheDecor[i];
- if (!_decorset) continue;
+ if (!_decorset) {
+ continue;
+ }
for (var j=_decorset.length-1;j>-1;j--) {
var _olddecor = _decorset[j];
if (["@font-weight", "@font-style", "@font-variant"].indexOf(_olddecor[0]) > -1
@@ -447,7 +414,7 @@ CSL.Util.FlipFlopper = function(state) {
if (decor[1] !== "normal") {
newblob.decorations.push([_olddecor[0], "normal"]);
- newdecorset.push([_olddecor[0], "normal"])
+ newdecorset.push([_olddecor[0], "normal"]);
}
seen[_olddecor[0]] = true;
}
@@ -477,11 +444,11 @@ CSL.Util.FlipFlopper = function(state) {
this.latest.blobs.push(child);
}
}
- }
+ };
this.popStyling = function() {
this.stack.pop();
- }
- };
+ };
+ }
var stack = new Stack(blob);
if (doppel.strings.length) {
var str = doppel.strings[0];
@@ -508,16 +475,18 @@ CSL.Util.FlipFlopper = function(state) {
* PUBLIC
*/
- function processTags(blob) {
+ this.processTags = function (blob) {
var str = blob.blobs;
var leadingSpace = false;
if (str.slice(0, 1) === " " && !str.match(/^\s+[\'\"]/)) {
leadingSpace = true;
}
- var rex = new RegExp("(" + CSL.ROMANESQUE_REGEXP.source + ")\u2019(" + CSL.ROMANESQUE_REGEXP.source + ")", "g")
+ var rex = new RegExp("(" + CSL.ROMANESQUE_REGEXP.source + ")\u2019(" + CSL.ROMANESQUE_REGEXP.source + ")", "g");
var str = " " + str.replace(rex, "$1\'$2");
var doppel = _doppelString(str);
- if (doppel.tags.length === 0) return;
+ if (doppel.tags.length === 0) {
+ return;
+ }
var quoteFormSeen = false;
// ZZZ
// It is inside THIS loop that we can convert the nocase and nodecor
@@ -577,7 +546,7 @@ CSL.Util.FlipFlopper = function(state) {
}
// Stray tags are neutralized here
for (var i=_nestingState.length-1;i>-1;i--) {
- var tagPos = _nestingState[i].pos
+ var tagPos = _nestingState[i].pos;
var tag = doppel.tags[tagPos];
if (tag === " \'" || tag === "\'") {
@@ -613,5 +582,5 @@ CSL.Util.FlipFlopper = function(state) {
//print(JSON.stringify(doppel, null, 2))
//print(_undoppelString(doppel));
_undoppelToQueue(blob, doppel, leadingSpace);
- }
-}
+ };
+};
diff --git a/src/util_locale.js b/src/util_locale.js
index c7a4ecd0f..c8c38ccd3 100644
--- a/src/util_locale.js
+++ b/src/util_locale.js
@@ -84,7 +84,7 @@ CSL.Engine.prototype.localeConfigure = function (langspec, beShy) {
// below.
//
CSL.Engine.prototype.localeSet = function (myxml, lang_in, lang_out) {
- var blob, locale, nodes, attributes, pos, ppos, term, form, termname, styleopts, attr, date, attrname, len, genderform, target, i, ilen;
+ var blob, locale, nodes, attributes, pos, term, form, termname, styleopts, date, attrname, len, genderform, target, i, ilen;
lang_in = lang_in.replace("_", "-");
lang_out = lang_out.replace("_", "-");
@@ -171,7 +171,6 @@ CSL.Engine.prototype.localeSet = function (myxml, lang_in, lang_out) {
termname = "sub-verbo";
}
if (termname.slice(0,7) === "ordinal") {
- var termstring = myxml.getNodeValue(term);
if (termname === "ordinal") {
ordinals101_toggle = true;
} else {
diff --git a/src/util_locale_sniff.js b/src/util_locale_sniff.js
index 1b3eda2ca..ce84b2fa1 100644
--- a/src/util_locale_sniff.js
+++ b/src/util_locale_sniff.js
@@ -12,7 +12,9 @@ CSL.getLocaleNames = function (myxml, preferredLocale) {
}
}
}
-
+
+ var localeIDs = ["en-US"];
+
function sniffLocaleOnOneNodeName(nodeName) {
var nodes = stylexml.getNodesByName(stylexml.dataObj, nodeName);
for (var i=0,ilen=nodes.length;i -1) {
- space = "\u00a0"
+ space = "\u00a0";
}
if (has_hyphenated_non_dropping_particle) {
@@ -707,9 +694,8 @@ CSL.NameOutput.prototype._givenName = function (name, pos, i) {
// If "form" is long, initialize-with exists (and initialize is not false) it's 1
// If "form" is long, and initialize_with does not exist, it's 2.
var formIsShort = this.state.inheritOpt(this.name, "form", "name-form", "long") !== "long";
- var initializeIsTurnedOn = !(this.state.inheritOpt(this.name, "initialize") === false);
+ var initializeIsTurnedOn = this.state.inheritOpt(this.name, "initialize") !== false;
var hasInitializeWith = "string" === typeof this.state.inheritOpt(this.name, "initialize-with") && !name.block_initialize;
- var inBibliography = this.state.tmp.area.slice(0, 12) === "bibliography";
var defaultLevel;
var useLevel;
if (name["full-form-always"]) {
@@ -778,8 +764,8 @@ CSL.NameOutput.prototype._nameSuffix = function (name) {
return false;
};
-CSL.NameOutput.prototype._getLongStyle = function (name, v, i) {
- var long_style, short_style;
+CSL.NameOutput.prototype._getLongStyle = function (name) {
+ var long_style;
if (name["short"].length) {
if (this.institutionpart["long-with-short"]) {
long_style = this.institutionpart["long-with-short"];
@@ -806,7 +792,6 @@ CSL.NameOutput.prototype._getShortStyle = function () {
};
CSL.NameOutput.prototype._parseName = function (name) {
- var m, idx;
if (!name["parse-names"] && "undefined" !== typeof name["parse-names"]) {
return name;
}
@@ -875,7 +860,7 @@ CSL.NameOutput.prototype.getName = function (name, slotLocaleset, fallback, stop
if (slotLocaleset !== 'locale-orig') {
foundTag = false;
if (name.multi) {
- var langTags = this.state.opt[slotLocaleset]
+ var langTags = this.state.opt[slotLocaleset];
for (var i = 0, ilen = langTags.length; i < ilen; i += 1) {
langTag = langTags[i];
if (name.multi._key[langTag]) {
@@ -955,15 +940,15 @@ CSL.NameOutput.prototype.getName = function (name, slotLocaleset, fallback, stop
usedOrig = !foundTag;
}
return {name:name,usedOrig:usedOrig};
-}
+};
CSL.NameOutput.prototype.getNameParams = function (langTag) {
var ret = {};
var langspec = CSL.localeResolve(this.Item.language, this.state.opt["default-locale"][0]);
var try_locale = this.state.locale[langspec.best] ? langspec.best : this.state.opt["default-locale"][0];
- var name_as_sort_order = this.state.locale[try_locale].opts["name-as-sort-order"]
- var name_as_reverse_order = this.state.locale[try_locale].opts["name-as-reverse-order"]
- var name_never_short = this.state.locale[try_locale].opts["name-never-short"]
+ var name_as_sort_order = this.state.locale[try_locale].opts["name-as-sort-order"];
+ var name_as_reverse_order = this.state.locale[try_locale].opts["name-as-reverse-order"];
+ var name_never_short = this.state.locale[try_locale].opts["name-never-short"];
var field_lang_bare = langTag.split("-")[0];
if (name_as_sort_order && name_as_sort_order[field_lang_bare]) {
ret["static-ordering"] = true;
@@ -981,7 +966,7 @@ CSL.NameOutput.prototype.getNameParams = function (langTag) {
ret["block-initialize"] = true;
}
return ret;
-}
+};
CSL.NameOutput.prototype.setRenderedName = function (name) {
if (this.state.tmp.area === "bibliography") {
@@ -993,7 +978,7 @@ CSL.NameOutput.prototype.setRenderedName = function (name) {
}
this.state.tmp.rendered_name.push(strname);
}
-}
+};
CSL.NameOutput.prototype.fixupInstitution = function (name, varname, listpos) {
@@ -1033,7 +1018,7 @@ CSL.NameOutput.prototype.fixupInstitution = function (name, varname, listpos) {
name["short"] = [];
}
return name;
-}
+};
CSL.NameOutput.prototype.getStaticOrder = function (name, refresh) {
@@ -1055,7 +1040,7 @@ CSL.NameOutput.prototype.getStaticOrder = function (name, refresh) {
}
}
return static_ordering_val;
-}
+};
CSL.NameOutput.prototype._splitInstitution = function (value, v, i) {
@@ -1110,7 +1095,7 @@ CSL.NameOutput.prototype._splitInstitution = function (value, v, i) {
return ret;
};
-CSL.NameOutput.prototype._trimInstitution = function (subunits, v, i) {
+CSL.NameOutput.prototype._trimInstitution = function (subunits, v) {
//
var use_first = false;
var append_last = false;
diff --git a/src/util_nodes.js b/src/util_nodes.js
index f41247e3b..f149f96d7 100644
--- a/src/util_nodes.js
+++ b/src/util_nodes.js
@@ -20,7 +20,7 @@ CSL.tokenExec = function (token, Item, item) {
this.tmp.jump.replace("fail");
return token.fail;
}
- }
+ };
if (token.test) {
next = record.call(this,token.test(Item, item));
}
@@ -44,7 +44,7 @@ CSL.tokenExec = function (token, Item, item) {
* Called on the state object.
*/
CSL.expandMacro = function (macro_key_token, target) {
- var mkey, start_token, key, end_token, navi, macro_nodes, newoutput, mergeoutput, end_of_macro, func;
+ var mkey, macro_nodes, end_of_macro, func;
mkey = macro_key_token.postponed_macro;
@@ -60,7 +60,7 @@ CSL.expandMacro = function (macro_key_token, target) {
}
if (hasDate) {
mkey = mkey + "@" + this.build.current_default_locale;
- func = function (state, Item) {
+ func = function (state) {
if (state.tmp.extension) {
state.tmp["doing-macro-with-date"] = true;
}
@@ -95,14 +95,14 @@ CSL.expandMacro = function (macro_key_token, target) {
CSL.configureMacro.call(this, mytarget);
}
if (!this.build.extension) {
- var func = function(macro_name) {
+ var func = (function(macro_name) {
return function (state, Item, item) {
var next = 0;
while (next < state.macros[macro_name].length) {
next = CSL.tokenExec.call(state, state.macros[macro_name][next], Item, item);
}
- }
- }(mkey);
+ };
+ }(mkey));
var text_node = new CSL.Token("text", CSL.SINGLETON);
text_node.execs.push(func);
target.push(text_node);
@@ -112,7 +112,7 @@ CSL.expandMacro = function (macro_key_token, target) {
end_of_macro = new CSL.Token("group", CSL.END);
if (hasDate) {
- func = function (state, Item) {
+ func = function (state) {
if (state.tmp.extension) {
state.tmp["doing-macro-with-date"] = false;
}
@@ -137,7 +137,7 @@ CSL.getMacroTarget = function (mkey) {
this.macros[mkey] = mytarget;
}
return mytarget;
-}
+};
CSL.buildMacro = function (mytarget, macro_nodes) {
var builder = CSL.makeBuilder(this, mytarget);
@@ -148,13 +148,13 @@ CSL.buildMacro = function (mytarget, macro_nodes) {
mynode = macro_nodes[0];
}
builder(mynode);
-}
+};
CSL.configureMacro = function (mytarget) {
if (!this.build.extension) {
this.configureTokenList(mytarget);
}
-}
+};
/**
diff --git a/src/util_number.js b/src/util_number.js
index 9e7f2cd21..c2d5fc04b 100644
--- a/src/util_number.js
+++ b/src/util_number.js
@@ -169,10 +169,9 @@ CSL.Util.Suffixator.prototype.format = function (N) {
};
-CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) {
+CSL.Engine.prototype.processNumber = function (node, ItemObject, variable) {
//print("** processNumber() ItemObject[variable]="+ItemObject[variable]);
- var val, m, i, ilen, j, jlen;
- var debug = false;
+ var val;
var me = this;
@@ -205,7 +204,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
// }
// ]
- function normalizeFieldValue(str, defaultLabel) {
+ function normalizeFieldValue(str) {
str = str.trim();
var m = str.match(/^([^ ]+)/);
if (m && !CSL.STATUTE_SUBDIV_STRINGS[m[1]]) {
@@ -255,7 +254,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
}
info.joiningSuffix = joiningSuffix.replace(/\s*-\s*/, "-");
return info;
- };
+ }
function fixupSubsections(elems) {
// This catches things like p. 12a-c, recombining content to yield
@@ -315,8 +314,8 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
for (var j=lst.length-1;j>0;j--) {
if (lst[j-1] && (!lst[j].match(/^[0-9]+([-;,:a-zA-Z]*)$/) || !lst[j-1].match(/^[0-9]+([-;,:a-zA-Z]*)$/))) {
lst[j-1] = lst[j-1] + m[j-1] + lst[j];
- lst = lst.slice(0,j).concat(lst.slice(j+1))
- m = m.slice(0,j-1).concat(m.slice(j))
+ lst = lst.slice(0,j).concat(lst.slice(j+1));
+ m = m.slice(0,j-1).concat(m.slice(j));
}
}
// merge bad leading label into content
@@ -329,7 +328,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
if (i === 0) {
m = m.slice(1);
lst[0] = lst[0] + " " + slug + " " + lst[1];
- lst = lst.slice(0,1).concat(lst.slice(2))
+ lst = lst.slice(0,1).concat(lst.slice(2));
}
} else {
origLabel = slug;
@@ -446,7 +445,9 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
}
function setPluralsAndNumerics(values) {
- if (values.length === 0) return;
+ if (values.length === 0) {
+ return;
+ }
var groupStartPos = 0;
var groupCount = 1;
@@ -481,6 +482,10 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
}
}
+ function stripHyphenBackslash(joiningSuffix) {
+ return joiningSuffix.replace("\\-", "-");
+ }
+
function setStyling(values) {
var masterNode = CSL.Util.cloneToken(node);
var masterStyling = new CSL.Token();
@@ -490,7 +495,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
// Add to styling
masterStyling.decorations = masterStyling.decorations.concat(masterNode.decorations.slice(j, j+1));
// Remove from node
- masterNode.decorations = masterNode.decorations.slice(0, j).concat(masterNode.decorations.slice(j+1))
+ masterNode.decorations = masterNode.decorations.slice(0, j).concat(masterNode.decorations.slice(j+1));
}
}
masterStyling.strings.prefix = masterNode.strings.prefix;
@@ -525,10 +530,25 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
return masterStyling;
}
- function stripHyphenBackslash(joiningSuffix) {
- return joiningSuffix.replace("\\-", "-");
+ function checkTerm(variable, val) {
+ var ret = true;
+ if (variable === "locator") {
+ var label;
+ if (val.origLabel) {
+ label = val.origLabel;
+ } else {
+ label = val.label;
+ }
+ ret = !!me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[label]);
+ }
+ return ret;
}
+ function checkPage(variable, val) {
+ return variable === "page"
+ || (variable === "locator" && (["p."].indexOf(val.label) > -1 || ["p."].indexOf(val.origLabel) > -1));
+ }
+
function fixupRangeDelimiter(variable, val, rangeDelimiter, isNumeric) {
var isPage = checkPage(variable, val);
var hasTerm = checkTerm(variable, val);
@@ -554,27 +574,10 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
return rangeDelimiter;
}
- function checkPage(variable, val) {
- return variable === "page"
- || (variable === "locator" && (["p."].indexOf(val.label) > -1 || ["p."].indexOf(val.origLabel) > -1));
- }
-
- function checkTerm(variable, val) {
- var ret = true;
- if (variable === "locator") {
- var label;
- if (val.origLabel) {
- label = val.origLabel;
- } else {
- label = val.label;
- }
- ret = !!me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[label]);
- }
- return ret;
- }
-
function manglePageNumbers(values, i, currentInfo) {
- if (i<1) return;
+ if (i<1) {
+ return;
+ }
if (currentInfo.count !== 2) {
return;
}
@@ -619,14 +622,18 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type)
function fixRanges(values) {
- if (!node) return;
- if (["page", "page-first", "chapter-number", "collection-number", "edition", "issue", "number", "number-of-pages", "number-of-volumes", "volume", "locator"].indexOf(variable) === -1) return;
+ if (!node) {
+ return;
+ }
+ if (["page", "page-first", "chapter-number", "collection-number", "edition", "issue", "number", "number-of-pages", "number-of-volumes", "volume", "locator"].indexOf(variable) === -1) {
+ return;
+ }
var currentInfo = {
count: 0,
label: null,
lastHadRangeDelimiter: false
- }
+ };
for (var i=0,ilen=values.length; i -1) {
return;
@@ -415,7 +415,7 @@ CSL.Parallel.prototype.CloseVariable = function () {
* tracking array, and evaluate maybe.
*/
CSL.Parallel.prototype.CloseCite = function () {
- var x, pos, len, has_issued, use_journal_info, volume_pos, container_title_pos, section_pos;
+ var x, pos, len, use_journal_info, volume_pos, container_title_pos, section_pos;
if (this.use_parallels && (this.force_collapse || this.try_cite)) {
use_journal_info = false;
if (!this.cite.front_collapse["container-title"]) {
@@ -505,8 +505,8 @@ CSL.Parallel.prototype.CloseCite = function () {
* Move variables tracking array into the array of
* composed sets.
*/
-CSL.Parallel.prototype.ComposeSet = function (next_output_in_progress) {
- var cite, pos, master, len;
+CSL.Parallel.prototype.ComposeSet = function () {
+ var cite, pos, len;
if (this.use_parallels && (this.force_collapse || this.try_cite)) {
// a bit loose here: zero-length sets relate to one cite,
// apparently.
@@ -675,4 +675,4 @@ CSL.Parallel.prototype.purgeGroupsIfParallel = function (original_condition) {
}
this.parallel_conditional_blobs_list.pop();
}
-}
+};
diff --git a/src/util_processor.js b/src/util_processor.js
index a37032797..eaf628ce1 100644
--- a/src/util_processor.js
+++ b/src/util_processor.js
@@ -115,12 +115,9 @@ CSL.setDecorations = function (state, attributes) {
};
CSL.Doppeler = function(rexStr, stringMangler) {
- var mx, lst, len, pos, m, buf1, buf2, idx, ret, myret;
- this.split = split;
- this.join = join;
var matchRex = new RegExp("(" + rexStr + ")", "g");
var splitRex = new RegExp(rexStr, "g");
- function split(str) {
+ this.split = function (str) {
// Normalize markup
if (stringMangler) {
str = stringMangler(str);
@@ -148,9 +145,9 @@ CSL.Doppeler = function(rexStr, stringMangler) {
tags: match,
strings: split,
origStrings: split.slice()
- }
- }
- function join(obj) {
+ };
+ };
+ this.join = function (obj) {
var lst = obj.strings.slice(-1);
for (var i=obj.tags.length-1; i>-1; i--) {
lst.push(obj.tags[i]);
@@ -158,8 +155,8 @@ CSL.Doppeler = function(rexStr, stringMangler) {
}
lst.reverse();
return lst.join("");
- }
-}
+ };
+};
CSL.Engine.prototype.normalDecorIsOrphan = function (blob, params) {
//print("params: "+JSON.stringify(params));
diff --git a/src/util_publishers.js b/src/util_publishers.js
index 634f0c11f..42e604e9d 100644
--- a/src/util_publishers.js
+++ b/src/util_publishers.js
@@ -73,7 +73,6 @@ CSL.PublisherOutput.prototype.composeElements = function () {
CSL.PublisherOutput.prototype.composePublishers = function () {
var blobs;
for (var i = 0, ilen = this["publisher-list"].length; i < ilen; i += 1) {
- var ordered_list = [];
blobs = [this[this.varlist[0] + "-list"][i], this[this.varlist[1] + "-list"][i]];
this["publisher-list"][i] = this._join(blobs, this.group_tok.strings.delimiter);
}
@@ -82,7 +81,6 @@ CSL.PublisherOutput.prototype.composePublishers = function () {
CSL.PublisherOutput.prototype.joinPublishers = function () {
var blobs = this["publisher-list"];
- var delim = this.name_delimiter;
var publishers = this._join(blobs, this.group_tok.strings["subgroup-delimiter"], this.and_blob.single, this.and_blob.multiple, this.group_tok);
this.state.output.append(publishers, "literal");
};
diff --git a/src/util_static_locator.js b/src/util_static_locator.js
index fdf7d7a06..3ead52aec 100644
--- a/src/util_static_locator.js
+++ b/src/util_static_locator.js
@@ -70,7 +70,7 @@ CSL.Engine.prototype.remapSectionVariable = function (inputList) {
// And that's it. Pre-parse complete.
}
}
-}
+};
CSL.Engine.prototype.setNumberLabels = function (Item) {
@@ -93,13 +93,11 @@ CSL.Engine.prototype.setNumberLabels = function (Item) {
var firstlabel = CSL.STATUTE_SUBDIV_STRINGS[firstword];
if (firstlabel) {
// Get list and match
- var m = value.match(CSL.STATUTE_SUBDIV_GROUPED_REGEX);
var splt = value.split(CSL.STATUTE_SUBDIV_PLAIN_REGEX);
if (splt.length > 1) {
// Convert matches to localized form
var lst = [];
for (var j=1, jlen=splt.length; j < jlen; j += 1) {
- var subdiv = m[j - 1].replace(/^\s*/, "");
lst.push(splt[j].replace(/\s*$/, "").replace(/^\s*/, ""));
}
// Preemptively save to shadow_numbers
@@ -115,4 +113,4 @@ CSL.Engine.prototype.setNumberLabels = function (Item) {
this.tmp.shadow_numbers["number"].numeric = true;
}
}
-}
+};
diff --git a/src/util_substitute.js b/src/util_substitute.js
index 312d5e35c..95195c498 100644
--- a/src/util_substitute.js
+++ b/src/util_substitute.js
@@ -2,7 +2,7 @@
CSL.Util.substituteStart = function (state, target) {
var element_trace, display, bib_first, func, choose_start, if_start, nodetypes;
- func = function (state, Item) {
+ func = function (state) {
for (var i = 0, ilen = this.decorations.length; i < ilen; i += 1) {
if ("@strip-periods" === this.decorations[i][0] && "true" === this.decorations[i][1]) {
state.tmp.strip_periods += 1;
@@ -26,10 +26,9 @@ CSL.Util.substituteStart = function (state, target) {
if (state.tmp.element_trace.value() === "author" || "names" === this.name) {
if (item && item["author-only"]) {
state.tmp.element_trace.push("do-not-suppress-me");
- } else if (item && item["suppress-author"]) {
- // This is better handled by namesOutput()
- //state.tmp.element_trace.push("suppress-me");
}
+ // The counterpart, suppress-author, is better handled by namesOutput()
+ //state.tmp.element_trace.push("suppress-me");
} else {
if (item && item["author-only"]) {
state.tmp.element_trace.push("suppress-me");
@@ -94,7 +93,7 @@ CSL.Util.substituteStart = function (state, target) {
// macro if we have acquired a name value.
// check for variable
- func = function (Item,item) {
+ func = function () {
if (state.tmp.can_substitute.value()) {
return true;
}
@@ -120,13 +119,15 @@ CSL.Util.substituteStart = function (state, target) {
if (item) {
position = item.position;
}
- if (!position) position = 0;
+ if (!position) {
+ position = 0;
+ }
var positionMap = [
"first",
"subsequent",
"ibid",
"ibid-with-locator"
- ]
+ ];
var noteNumber = 0;
if (item && item.noteIndex) {
noteNumber = item.noteIndex;
@@ -157,27 +158,27 @@ CSL.Util.substituteStart = function (state, target) {
};
state.output.current.value().params = params;
}
- }
+ };
this.execs.push(func);
}
};
CSL.Util.substituteEnd = function (state, target) {
- var func, bib_first_end, bib_other, if_end, choose_end, toplevel, hasval, author_substitute, str;
+ var func, bib_first_end, bib_other, if_end, choose_end, author_substitute, str;
if (state.sys.variableWrapper
&& (this.hasVariable || (this.variables_real && this.variables_real.length))) {
- func = function (state,Item) {
+ func = function (state) {
if (!state.tmp.just_looking && !state.tmp.suppress_decorations) {
state.output.endTag("variable_entry");
}
- }
+ };
this.execs.push(func);
}
- func = function (state, Item) {
+ func = function (state) {
for (var i = 0, ilen = this.decorations.length; i < ilen; i += 1) {
if ("@strip-periods" === this.decorations[i][0] && "true" === this.decorations[i][1]) {
state.tmp.strip_periods += -1;
@@ -190,7 +191,7 @@ CSL.Util.substituteEnd = function (state, target) {
state.build.render_nesting_level += -1;
if (state.build.render_nesting_level === 0) {
if (state.build.cls) {
- func = function (state, Item) {
+ func = function (state) {
state.output.endTag("bib_first");
};
this.execs.push(func);
@@ -198,7 +199,7 @@ CSL.Util.substituteEnd = function (state, target) {
} else if (state.build.area === "bibliography" && state.bibliography.opt["second-field-align"]) {
bib_first_end = new CSL.Token("group", CSL.END);
// first func end
- func = function (state, Item) {
+ func = function (state) {
if (!state.tmp.render_seen) {
state.output.endTag("bib_first"); // closes bib_first
}
@@ -207,7 +208,7 @@ CSL.Util.substituteEnd = function (state, target) {
target.push(bib_first_end);
bib_other = new CSL.Token("group", CSL.START);
bib_other.decorations = [["@display", "right-inline"]];
- func = function (state, Item) {
+ func = function (state) {
if (!state.tmp.render_seen) {
state.tmp.render_seen = true;
state.output.startTag("bib_other", bib_other);
@@ -227,9 +228,15 @@ CSL.Util.substituteEnd = function (state, target) {
if ("names" === this.name || ("text" === this.name && this.variables_real !== "title")) {
author_substitute = new CSL.Token("text", CSL.SINGLETON);
func = function (state, Item) {
- if (state.tmp.area !== "bibliography") return;
- if ("string" !== typeof state.bibliography.opt["subsequent-author-substitute"]) return;
- if (this.variables_real && !Item[this.variables_real]) return;
+ if (state.tmp.area !== "bibliography") {
+ return;
+ }
+ if ("string" !== typeof state.bibliography.opt["subsequent-author-substitute"]) {
+ return;
+ }
+ if (this.variables_real && !Item[this.variables_real]) {
+ return;
+ }
if (state.tmp.substituted_variable !== this.variables_real) {
return;
}
@@ -301,7 +308,7 @@ CSL.Util.substituteEnd = function (state, target) {
if (("text" === this.name && !this.postponed_macro) || ["number", "date", "names"].indexOf(this.name) > -1) {
// element trace
- func = function (state, Item) {
+ func = function (state) {
state.tmp.element_trace.pop();
};
this.execs.push(func);
diff --git a/src/util_transform.js b/src/util_transform.js
index 5f4101765..ad89701ff 100644
--- a/src/util_transform.js
+++ b/src/util_transform.js
@@ -52,12 +52,9 @@
*/
CSL.Transform = function (state) {
- var debug = false, abbreviations, token, fieldname, abbrev_family, opt;
-
// Abbreviation families
this.abbrevs = {};
this.abbrevs["default"] = new state.sys.AbbreviationSegments();
- this.getTextSubField = getTextSubField;
function getCountryOrJurisdiction(variable, normalizedKey, quashCountry) {
var value = "";
@@ -79,7 +76,7 @@ CSL.Transform = function (state) {
}
// Internal function
- function abbreviate(state, tok, Item, altvar, basevalue, family_var, use_field, form) {
+ function abbreviate(state, tok, Item, altvar, basevalue, family_var, use_field) {
var value = "";
var myabbrev_family = CSL.FIELD_CATEGORY_REMAP[family_var];
var preferredJurisdiction;
@@ -160,7 +157,7 @@ CSL.Transform = function (state) {
}
function getFieldLocale(Item,field) {
- var ret = state.opt["default-locale"][0].slice(0, 2)
+ var ret = state.opt["default-locale"][0].slice(0, 2);
var localeRex;
if (state.opt.development_extensions.strict_text_case_locales) {
localeRex = new RegExp("^([a-zA-Z]{2})(?:$|-.*| .*)");
@@ -185,11 +182,11 @@ CSL.Transform = function (state) {
ret = ret.toLowerCase();
}
return ret;
- };
+ }
// Internal functions
function getTextSubField (Item, field, locale_type, use_default, stopOrig) {
- var m, lst, opt, o, oo, pos, key, ret, len, myret, opts;
+ var opt, o, ret, opts;
var usedOrig = stopOrig;
var usingOrig = false;
@@ -204,7 +201,6 @@ CSL.Transform = function (state) {
opts = state.opt[locale_type];
var hasVal = false;
- var jurisdictionName = false;
if (locale_type === 'locale-orig') {
if (stopOrig) {
ret = {name:"", usedOrig:stopOrig};
@@ -258,12 +254,12 @@ CSL.Transform = function (state) {
}
return ret;
}
-
+ this.getTextSubField = getTextSubField;
+
// Setter for abbreviation lists
// This initializes a single abbreviation based on known
// data.
function loadAbbreviation(jurisdiction, category, orig, itemType) {
- var pos, len;
if (!jurisdiction) {
jurisdiction = "default";
}
@@ -318,8 +314,27 @@ CSL.Transform = function (state) {
return false;
}
+
+ // The name transform code is placed here to keep similar things
+ // in one place. Obviously this module could do with a little
+ // tidying up.
+ function quashCheck(value) {
+ var m = value.match(/^!([-,_a-z]+)>>>/);
+ if (m) {
+ var fields = m[1].split(",");
+ value = value.slice(m[0].length);
+ for (var i = 0, ilen = fields.length; i < ilen; i += 1) {
+ if (state.tmp.done_vars.indexOf(fields[i]) === -1) {
+ state.tmp.done_vars.push(fields[i]);
+ }
+ }
+ }
+ return value;
+ }
+ this.quashCheck = quashCheck;
+
// Return function appropriate to selected options
- function getOutputFunction(variables, family_var, abbreviation_fallback, alternative_varname, transform_fallback) {
+ function getOutputFunction(variables, family_var, abbreviation_fallback, alternative_varname) {
// var mytoken;
// Set the primary_locale and secondary_locale lists appropriately.
@@ -334,8 +349,8 @@ CSL.Transform = function (state) {
localesets = state.opt['cite-lang-prefs'][langPrefs];
}
- return function (state, Item, item, usedOrig) {
- var primary, primary_locale, secondary, secondary_locale, tertiary, tertiary_locale, primary_tok, group_tok, key;
+ return function (state, Item, item) {
+ var primary, primary_locale, secondary, secondary_locale, tertiary, tertiary_locale, primary_tok;
if (!variables[0] || (!Item[variables[0]] && !Item[alternative_varname])) {
return null;
}
@@ -449,7 +464,7 @@ CSL.Transform = function (state) {
}
}
if (!hasItalic) {
- primary_tok.decorations.push(["@font-style", "italic"])
+ primary_tok.decorations.push(["@font-style", "italic"]);
}
}
@@ -480,7 +495,7 @@ CSL.Transform = function (state) {
// Remove quotes
for (var i = secondary_tok.decorations.length - 1; i > -1; i += -1) {
if (['@quotes/true', '@font-style/italic', '@font-style/oblique', '@font-weight/bold'].indexOf(secondary_tok.decorations[i].join('/')) > -1) {
- secondary_tok.decorations = secondary_tok.decorations.slice(0, i).concat(secondary_tok.decorations.slice(i + 1))
+ secondary_tok.decorations = secondary_tok.decorations.slice(0, i).concat(secondary_tok.decorations.slice(i + 1));
}
}
if (secondary_locale !== "en" && secondary_tok.strings["text-case"] === "title") {
@@ -515,7 +530,7 @@ CSL.Transform = function (state) {
// Remove quotes
for (var i = tertiary_tok.decorations.length - 1; i > -1; i += -1) {
if (['@quotes/true', '@font-style/italic', '@font-style/oblique', '@font-weight/bold'].indexOf(tertiary_tok.decorations[i].join('/')) > -1) {
- tertiary_tok.decorations = tertiary_tok.decorations.slice(0, i).concat(tertiary_tok.decorations.slice(i + 1))
+ tertiary_tok.decorations = tertiary_tok.decorations.slice(0, i).concat(tertiary_tok.decorations.slice(i + 1));
}
}
if (tertiary_locale !== "en" && tertiary_tok.strings["text-case"] === "title") {
@@ -546,23 +561,4 @@ CSL.Transform = function (state) {
};
}
this.getOutputFunction = getOutputFunction;
-
- // The name transform code is placed here to keep similar things
- // in one place. Obviously this module could do with a little
- // tidying up.
-
- function quashCheck(value) {
- var m = value.match(/^!([-,_a-z]+)>>>/);
- if (m) {
- var fields = m[1].split(",");
- value = value.slice(m[0].length);
- for (var i = 0, ilen = fields.length; i < ilen; i += 1) {
- if (state.tmp.done_vars.indexOf(fields[i]) === -1) {
- state.tmp.done_vars.push(fields[i]);
- }
- }
- }
- return value;
- }
- this.quashCheck = quashCheck;
};