Index: gc_lang/fr/modules-js/textformatter.js ================================================================== --- gc_lang/fr/modules-js/textformatter.js +++ gc_lang/fr/modules-js/textformatter.js @@ -1,14 +1,14 @@ // Grammalecte - text formatter /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ -/* global exports */ +/* global exports, console */ "use strict"; -${map} +//!${map} // Latin letters: http://unicode-table.com/fr/ // 0-9 // A-Z @@ -263,12 +263,13 @@ const dTFOptions = dTFDefaultOptions.gl_shallowCopy(); class TextFormatter { - constructor () { + constructor (bDebug=false) { this.sLang = "fr"; + this.bDebug = bDebug; } formatText (sText, dOpt=null) { if (dOpt !== null) { dTFOptions.gl_updateOnlyExistingKeys(dOpt); @@ -280,10 +281,50 @@ } } } return sText; } + + formatTextCount (sText, dOpt=null) { + let nCount = 0; + if (dOpt !== null) { + dTFOptions.gl_updateOnlyExistingKeys(dOpt); + } + for (let [sOptName, bVal] of dTFOptions) { + if (bVal && oReplTable[sOptName]) { + for (let [zRgx, sRep] of oReplTable[sOptName]) { + nCount += (sText.match(zRgx) || []).length; + sText = sText.replace(zRgx, sRep); + } + } + } + return [sText, nCount]; + } + + formatTextRule (sText, sRuleName) { + if (oReplTable[sRuleName]) { + for (let [zRgx, sRep] of oReplTable[sRuleName]) { + sText = sText.replace(zRgx, sRep); + } + } else if (this.bDebug){ + console.log("# Error. TF: there is no option “" + sRuleName+ "”."); + } + return sText; + } + + formatTextRuleCount (sText, sRuleName) { + let nCount = 0; + if (oReplTable[sRuleName]) { + for (let [zRgx, sRep] of oReplTable[sRuleName]) { + nCount += (sText.match(zRgx) || []).length; + sText = sText.replace(zRgx, sRep); + } + } else if (this.bDebug){ + console.log("# Error. TF: there is no option “" + sRuleName+ "”."); + } + return [sText, nCount]; + } getDefaultOptions () { return dTFDefaultOptions; } }