3333
3434local CslLocale = require (" packages.bibtex.csl.locale" )
3535
36- local superfolding = require (" packages.bibtex.csl.utils.superfolding" )
3736local endash = luautf8 .char (0x2013 )
3837local emdash = luautf8 .char (0x2014 )
3938
@@ -70,18 +69,18 @@ function CslEngine:_init (style, locale, extras)
7069
7170 -- Cache for some small string operations (e.g. XML escaping)
7271 -- to avoid repeated processing.
73- self .cache = {}
72+ self ._cache = {}
7473
7574 -- Early lookups for often used localized punctuation marks
7675 self .punctuation = {
77- open_quote = self : _render_term (" open-quote" ) or luautf8 .char (0x201C ), -- 0x201C curly left quote
78- close_quote = self : _render_term (" close-quote" ) or luautf8 .char (0x201D ), -- 0x201D curly right quote
79- open_inner_quote = self : _render_term (" open-inner-quote" ) or luautf8 .char (0x2018 ), -- 0x2018 curly left single quote
80- close_inner_quote = self : _render_term (" close-inner-quote" ) or luautf8 .char (0x2019 ), -- 0x2019 curly right single quote
81- page_range_delimiter = self : _render_term (" page-range-delimiter" ) or endash ,
82- [" ," ] = self : _render_term (" comma" ) or " ," ,
83- [" ;" ] = self : _render_term (" semicolon" ) or " ;" ,
84- [" :" ] = self : _render_term (" colon" ) or " :" ,
76+ open_quote = self . locale : term (" open-quote" ) or luautf8 .char (0x201C ), -- 0x201C curly left quote
77+ close_quote = self . locale : term (" close-quote" ) or luautf8 .char (0x201D ), -- 0x201D curly right quote
78+ open_inner_quote = self . locale : term (" open-inner-quote" ) or luautf8 .char (0x2018 ), -- 0x2018 curly left single quote
79+ close_inner_quote = self . locale : term (" close-inner-quote" ) or luautf8 .char (0x2019 ), -- 0x2019 curly right single quote
80+ page_range_delimiter = self . locale : term (" page-range-delimiter" ) or endash ,
81+ [" ," ] = self . locale : term (" comma" ) or " ," ,
82+ [" ;" ] = self . locale : term (" semicolon" ) or " ;" ,
83+ [" :" ] = self . locale : term (" colon" ) or " :" ,
8584 }
8685
8786 -- Small utility for page ranges, see text processing for <text variable="page">
268267
269268-- INTERNAL HELPERS
270269
271- function CslEngine :_render_term (name , form , plural )
272- local t = self .locale :term (name , form , plural )
273- if t then
274- if self .cache [t ] then
275- return self .cache [t ]
276- end
277- t = self :_xmlEscape (t )
278- -- The CSL specification states, regarding terms:
279- -- "Superscripted Unicode characters can be used for superscripting."
280- -- We replace the latter with their normal form, wrapped in a command.
281- -- The result is cached in the term object to avoid repeated processing.
282- -- (Done after XML escaping as superfolding may add commands.)
283- t = superfolding (t )
284- self .cache [t ] = t
285- end
286- return t
287- end
288-
289270function CslEngine :_render_text_specials (value )
290271 -- Extensions for italic and math...
291272 -- CAVEAT: the implementation is fairly naive.
@@ -323,8 +304,8 @@ function CslEngine:_xmlEscape (t)
323304end
324305
325306function CslEngine :_punctuation_extra (t )
326- if self .cache [t ] then
327- return self .cache [t ]
307+ if self ._cache [t ] then
308+ return self ._cache [t ]
328309 end
329310 if self .extras .localizedPunctuation then
330311 -- non-standard: localized punctuation
@@ -333,7 +314,7 @@ function CslEngine:_punctuation_extra (t)
333314 end )
334315 end
335316 t = self :_xmlEscape (t )
336- self .cache [t ] = t
317+ self ._cache [t ] = t
337318 return t
338319end
339320
@@ -532,7 +513,7 @@ function CslEngine:_text (options, content, entry)
532513 SU .error (" CSL macro " .. options .macro .. " not found" )
533514 end
534515 elseif options .term then
535- t = self : _render_term (options .term , options .form , SU .boolean (options .plural , false ))
516+ t = self . locale : term (options .term , options .form , SU .boolean (options .plural , false ))
536517 elseif options .variable then
537518 variable = options .variable
538519 t = entry [variable ]
@@ -609,7 +590,7 @@ function CslEngine:_a_day (options, day, month) -- month needed to get gender fo
609590 local genderForm
610591 if month then
611592 local monthKey = (" month-%02d" ):format (month )
612- local _ , gender = self : _render_term (monthKey )
593+ local _ , gender = self . locale : term (monthKey )
613594 genderForm = gender or " neuter"
614595 end
615596 if SU .boolean (self .locale .styleOptions [" limit-day-ordinals-to-day-1" ], false ) then
@@ -632,7 +613,7 @@ function CslEngine:_a_month (options, month)
632613 t = (" %02d" ):format (month )
633614 else -- short or long (default)
634615 local monthKey = (" month-%02d" ):format (month )
635- t = self : _render_term (monthKey , form or " long" )
616+ t = self . locale : term (monthKey , form or " long" )
636617 end
637618 t = self :_render_stripPeriods (t , options )
638619 return t
@@ -647,7 +628,7 @@ function CslEngine:_a_season (options, season)
647628 SU .warn (" CSL season formatting as a number is ignored" )
648629 else
649630 local seasonKey = (" season-%02d" ):format (season )
650- t = self : _render_term (seasonKey , form or " long" )
631+ t = self . locale : term (seasonKey , form or " long" )
651632 end
652633 t = self :_render_stripPeriods (t , options )
653634 return t
@@ -802,7 +783,7 @@ function CslEngine:_number (options, content, entry)
802783 value = value and value .value
803784 end
804785 if value then
805- local _ , gender = self : _render_term (variable )
786+ local _ , gender = self . locale : term (variable )
806787 local genderForm = gender or " neuter"
807788
808789 -- FIXME TODO: Some complex stuff about name ranges, commas, etc. in the spec.
@@ -876,7 +857,7 @@ function CslEngine:_substitute (options, content, entry)
876857end
877858
878859function CslEngine :_name_et_al (options )
879- local t = self : _render_term (options .term or " et-al" )
860+ local t = self . locale : term (options .term or " et-al" )
880861 t = self :_render_formatting (t , options )
881862 return t
882863end
@@ -1230,25 +1211,25 @@ function CslEngine:_names (options, content, entry)
12301211 if and_opt == " symbol" then
12311212 and_word = " &"
12321213 elseif and_opt == " text" then
1233- and_word = self : _render_term (" and" )
1214+ and_word = self . locale : term (" and" )
12341215 end
12351216 local name_delimiter = name_node .options .delimiter or inherited_opts [" names-delimiter" ] or " , "
12361217 -- local delimiter_precedes_et_al = name_node.options["delimiter-precedes-et-al"] -- FIXME NOT IMPLEMENTED
12371218 local delimiter_precedes_last = name_node .options [" delimiter-precedes-last" ]
12381219 or inherited_opts [" delimiter-precedes-last" ]
12391220 or " contextual"
12401221
1241- if name_delimiter and not self .cache [name_delimiter ] then
1222+ if name_delimiter and not self ._cache [name_delimiter ] then
12421223 name_delimiter = self :_xmlEscape (name_delimiter )
1243- self .cache [name_delimiter ] = name_delimiter
1224+ self ._cache [name_delimiter ] = name_delimiter
12441225 end
12451226
12461227 local resolved = {
12471228 variable = SU .required (name_node .options , " variable" , " CSL names" ),
12481229 et_al_min = et_al_min ,
12491230 et_al_use_first = et_al_use_first ,
12501231 and_word = and_word ,
1251- name_delimiter = name_delimiter and self .cache [name_delimiter ],
1232+ name_delimiter = name_delimiter and self ._cache [name_delimiter ],
12521233 is_label_first = is_label_first ,
12531234 label_opts = label_opts ,
12541235 et_al_opts = et_al_opts ,
@@ -1292,7 +1273,7 @@ function CslEngine:_label (options, content, entry)
12921273 end
12931274 end
12941275 end
1295- value = self : _render_term (variable , options .form or " long" , plural )
1276+ value = self . locale : term (variable , options .form or " long" , plural )
12961277 value = self :_render_stripPeriods (value , options )
12971278 value = self :_render_textCase (value , options )
12981279 value = self :_render_formatting (value , options )
0 commit comments