From 0aee953bf61e97a05fab66e7ba306e1e4a282386 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 1 Jun 2010 06:47:02 +0000 Subject: [PATCH] Update to citeproc-js 1.0.18 From Frank's announcement: This release fixes a small issue in disambiguation, which could cause initials or full given names to be retained where they are not necessary to achieve disambiguation, under certain fairly rare conditions. This also includes a very small change to the regexp used to identify numeric content in numeric fields, support for RTF and plain text output (courtesy of Simon), and a modification to the ./test.py script, adding a -E option that dumps a version of the processor with embedded E4X support, suitable for drop-in inclusion in current Zotero 2.1. --- chrome/content/zotero/xpcom/citeproc.js | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js index edb91b9c0..5afb4bce5 100644 --- a/chrome/content/zotero/xpcom/citeproc.js +++ b/chrome/content/zotero/xpcom/citeproc.js @@ -87,7 +87,7 @@ var CSL = { STRICT: 1, PREFIX_PUNCTUATION: /[.;:]\s*$/, SUFFIX_PUNCTUATION: /^\s*[.;:,\(\)]/, - NUMBER_REGEXP: /(?:^\d+|\d+$|\d{3,})/, // avoid evaluating "F.2d" as numeric + NUMBER_REGEXP: /(?:^\d+|\d+$)/, QUOTED_REGEXP_START: /^"/, QUOTED_REGEXP_END: /^"$/, NAME_INITIAL_REGEXP: /^([A-Z\u0080-\u017f\u0400-\u042f])([a-zA-Z\u0080-\u017f\u0400-\u052f]*|)/, @@ -1384,7 +1384,7 @@ CSL.dateParser = function (txt) { }; CSL.Engine = function (sys, style, lang, xmlmode) { var attrs, langspec, localexml, locale; - this.processor_version = "1.0.17"; + this.processor_version = "1.0.18"; this.csl_version = "1.0"; this.sys = sys; this.sys.xml = new CSL.System.Xml.Parsing(); @@ -7493,7 +7493,7 @@ CSL.Registry.NameReg = function (state) { }; var debug = false; CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candidate_list) { - var ambigs, reg_token, keypos, id_vals, a, base, token, pos, len, tokens, str, maxvals, minval, testpartner, otherstr, base_return, ret, id, key; + var ambigs, reg_token, keypos, id_vals, a, base, token, pos, len, tokens, str, maxvals, minval, testpartner, otherstr, base_return, ret, id, key, givensbase, remainder, last_remainder; if (!candidate_list) { ambigs = this.ambigcites[akey].slice(); this.ambigcites[akey] = []; @@ -7526,6 +7526,12 @@ CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candida maxvals = CSL.getMaxVals.call(state); minval = CSL.getMinVal.call(state); base = CSL.getAmbigConfig.call(state); + givensbase = []; + for (pos = 0, len = base.givens.length; pos < len; pos += 1) { + givensbase.push(base.givens[pos].slice()); + } + remainder = tokens.length; + last_remainder = this.checkerator.seen.length; while (CSL.runCheckerator.call(this.checkerator)) { token = this.checkerator.tokens[this.checkerator.pos]; if (this.ambigcites[akey].indexOf(token.id) > -1) { @@ -7558,7 +7564,13 @@ CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candida } } if (CSL.evaluateCheckeratorClashes.call(this.checkerator)) { - base_return = CSL.decrementCheckeratorNames.call(this, state, base); + remainder = tokens.length - this.checkerator.seen.length; + if (remainder === 1 && last_remainder === 0) { + base_return = CSL.decrementCheckeratorGivenNames.call(this, state, base, givensbase, token.id); + } else { + base_return = CSL.decrementCheckeratorNames.call(this, state, base, givensbase); + } + last_remainder = remainder; this.registerAmbigToken(akey, token.id, base_return); this.checkerator.seen.push(token.id); continue; @@ -7763,7 +7775,17 @@ CSL.incrementCheckeratorAmbigLevel = function () { } } }; -CSL.decrementCheckeratorNames = function (state, base) { +CSL.decrementCheckeratorGivenNames = function (state, base, givensbase, id) { + var base_return, ids, pos, len; + ids = this.checkerator.ids; + this.checkerator.ids = ids.slice(0,ids.indexOf(id)).concat(ids.slice(ids.indexOf(id) + 1)); + base_return = CSL.cloneAmbigConfig(base); + for (pos = 0, len = base_return.givens.length; pos < len; pos += 1) { + base_return.givens[pos] = givensbase.slice(); + } + return base_return; +}; +CSL.decrementCheckeratorNames = function (state, base, givensbase) { var base_return, do_me, i, j, pos, len, ppos, llen; base_return = CSL.cloneAmbigConfig(base); do_me = false; @@ -7771,8 +7793,8 @@ CSL.decrementCheckeratorNames = function (state, base) { for (pos = len; pos > -1; pos += -1) { llen = base_return.givens[pos].length - 1; for (ppos = llen; ppos > -1; ppos += -1) { - if (base_return.givens[pos][ppos] === 2) { - do_me = true; + if (base_return.givens[pos][ppos] > givensbase[pos][ppos]) { + do_me = true; } } } @@ -7781,7 +7803,7 @@ CSL.decrementCheckeratorNames = function (state, base) { for (pos = len; pos > -1; pos += -1) { llen = base_return.givens[pos].length - 1; for (ppos = llen; ppos > -1; ppos += -1) { - if (base_return.givens[pos][ppos] === 2) { + if (base_return.givens[pos][ppos] > givensbase[pos][ppos]) { i = -1; break; } @@ -7826,4 +7848,4 @@ CSL.getModes = function () { CSL.Registry.CitationReg = function (state) { this.citationById = {}; this.citationByIndex = []; -}; +}; \ No newline at end of file