Grammalecte  Diff

Differences From Artifact [16ec62288b]:

To Artifact [920d8b7cad]:


263
264
265
266
267
268
269
270

271
272
273
274
275

276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293

294
295
296
297
298
299
300
263
264
265
266
267
268
269

270
271
272
273
274

275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290

291
292

293
294
295
296
297
298
299
300







-
+




-
+

-
+













-
+

-
+








class TextFormatter {

    constructor (bDebug=false) {
        this.sLang = "fr";
        this.bDebug = bDebug;
        //don't change this in external ;)
        this._optionsUsed = dTFDefaultOptions.gl_shallowCopy();
        this.dOptions = dTFDefaultOptions.gl_shallowCopy();
    }

    formatText (sText, dOpt=null) {
        if (dOpt !== null) {
            this._optionsUsed.gl_updateOnlyExistingKeys(dOpt);
            this.dOptions.gl_updateOnlyExistingKeys(dOpt);
        }
        for (let [sOptName, bVal] of this._optionsUsed) {
        for (let [sOptName, bVal] of this.dOptions) {
            //console.log(oReplTable);
            if (bVal && oReplTable[sOptName]) {
                for (let [zRgx, sRep] of oReplTable[sOptName]) {
                    sText = sText.replace(zRgx, sRep);
                }
            }
        }
        return sText;
    }

    formatTextCount (sText, dOpt=null) {
        let nCount = 0;
        if (dOpt !== null) {
            this._optionsUsed.gl_updateOnlyExistingKeys(dOpt);
            this.dOptions.gl_updateOnlyExistingKeys(dOpt);
        }
        for (let [sOptName, bVal] of this._optionsUsed) {
        for (let [sOptName, bVal] of this.dOptions) {
            if (bVal && oReplTable[sOptName]) {
                for (let [zRgx, sRep] of oReplTable[sOptName]) {
                    nCount += (sText.match(zRgx) || []).length;
                    sText = sText.replace(zRgx, sRep);
                }
            }
        }
378
379
380
381
382
383
384
385

386
387

388
389
390

391
392

393
394
395
396
397
398
399
400
401
402
403
404
405
406
378
379
380
381
382
383
384

385
386

387
388
389

390
391

392
393
394
395
396




397
398
399
400
401
402







-
+

-
+


-
+

-
+




-
-
-
-






    }

    getDefaultOptions () {
        //we return a copy to make sure they are no modification in external
        return dTFDefaultOptions.gl_shallowCopy();
    }

    getUsedOptions () {
    getOptions () {
        //we return a copy to make sure they are no modification in external
        return this._optionsUsed.gl_shallowCopy();
        return this.dOptions.gl_shallowCopy();
    }

    setUsedOptions (dOpt=null) {
    setOptions (dOpt=null) {
        if (dOpt !== null) {
            this._optionsUsed.gl_updateOnlyExistingKeys(dOpt);
            this.dOptions.gl_updateOnlyExistingKeys(dOpt);
        } else if (this.bDebug){
            console.log("# Error. TF: no option to change.");
        }
    }

    getReplTable(){
        return oReplTable;
    }
}


if (typeof(exports) !== 'undefined') {
    exports.TextFormatter = TextFormatter;
}