Grammalecte  Check-in [c70980cc3c]

Overview
Comment:[core][js] Textformater more usable
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | nodejs
Files: files | file ages | folders
SHA3-256: c70980cc3cc5fab01c33b236fe54cab033423a6b44c0415cc5c34da87955257e
User & Date: IllusionPerdu on 2018-10-12 14:20:29
Other Links: branch diff | manifest | tags
Context
2018-10-12
14:22
[core][js] Textformater fix syntax change check-in: 4afd98aa33 user: IllusionPerdu tags: core, nodejs
14:20
[core][js] Textformater more usable check-in: c70980cc3c user: IllusionPerdu tags: core, nodejs
13:35
[core][js] Textformater add functions check-in: f16a92cab4 user: IllusionPerdu tags: core, nodejs
Changes

Modified gc_lang/fr/modules-js/textformatter.js from [f30182bb9d] to [c18f31aacd].

256
257
258
259
260
261
262
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
256
257
258
259
260
261
262


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







-
-






+
+




-
+

-
+
+












-
+

-
+







    ["etc", true],
    ["missing_hyphens", true],
    ["ma_word", true],
    ["ma_1letter_lowercase", false],
    ["ma_1letter_uppercase", false]
]);

const dTFOptions = dTFDefaultOptions.gl_shallowCopy();


class TextFormatter {

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

    formatText (sText, dOpt=null) {
        if (dOpt !== null) {
            dTFOptions.gl_updateOnlyExistingKeys(dOpt);
            this._optionsUsed.gl_updateOnlyExistingKeys(dOpt);
        }
        for (let [sOptName, bVal] of dTFOptions) {
        for (let [sOptName, bVal] of this._optionsUsed) {
            //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) {
            dTFOptions.gl_updateOnlyExistingKeys(dOpt);
            this._optionsUsed.gl_updateOnlyExistingKeys(dOpt);
        }
        for (let [sOptName, bVal] of dTFOptions) {
        for (let [sOptName, bVal] of this._optionsUsed) {
            if (bVal && oReplTable[sOptName]) {
                for (let [zRgx, sRep] of oReplTable[sOptName]) {
                    nCount += (sText.match(zRgx) || []).length;
                    sText = sText.replace(zRgx, sRep);
                }
            }
        }
321
322
323
324
325
326
327

328


















329
330
331
332
333

334
335
336
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

352
353
354
355







+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+



        } else if (this.bDebug){
            console.log("# Error. TF: there is no option “" + sRuleName+ "”.");
        }
        return [sText, nCount];
    }

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

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

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

    getReplTable(){
        return oReplTable;
    }
}


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