Grammalecte  Check-in [6963981657]

Overview
Comment:[core][njs][js] textformatter: rename few functions and attributs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | njs | nodejs
Files: files | file ages | folders
SHA3-256: 69639816570429e73c2821ea71b252fe5fdf91d74ef4f78b0286d7bdcf58fc09
User & Date: olr on 2018-10-17 14:04:46
Other Links: branch diff | manifest | tags
Context
2018-10-17
14:21
[build][fr] build NodeJS package check-in: 401f29a39d user: olr tags: fr, build, nodejs
14:04
[core][njs][js] textformatter: rename few functions and attributs check-in: 6963981657 user: olr tags: core, njs, nodejs
13:56
[njs] Add note in client doc check-in: 694fbfbe9e user: IllusionPerdu tags: njs, nodejs
Changes

Modified gc_lang/fr/modules-js/textformatter.js from [16ec62288b] to [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;
}

Modified gc_lang/fr/nodejs/core/api.js from [a38bf9a7cd] to [a782304429].

236
237
238
239
240
241
242
243
244


245
246
247
248
249
250
251
252

253
254

255
256
257
258
259
260
261
262
263
264
265


266
267
268
269
270
271
272
236
237
238
239
240
241
242


243
244
245
246
247
248
249
250
251

252
253

254
255
256
257
258
259
260
261
262
263


264
265
266
267
268
269
270
271
272







-
-
+
+







-
+

-
+









-
-
+
+







        return this.oTextFormatter.formatText(sText);
    }

    setTfOptions(dOptions) {
        if (!this.isInit.TextFormatter) {
            this.load(["TextFormatter"]);
        }
        this.oTextFormatter.setUsedOptions(dOptions);
        return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions());
        this.oTextFormatter.setOptions(dOptions);
        return this._helpers.mapToObject(this.oTextFormatter.getOptions());
    }

    setTfOption(sOptName, bValue) {
        if (!this.isInit.TextFormatter) {
            this.load(["TextFormatter"]);
        }
        if (sOptName) {
            let optionsTF = this.oTextFormatter.getUsedOptions();
            let optionsTF = this.oTextFormatter.getOptions();
            optionsTF.set(sOptName, bValue);
            return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions());
            return this._helpers.mapToObject(this.oTextFormatter.getOptions());
        }
        return false;
    }

    resetTfOptions() {
        if (!this.isInit.TextFormatter) {
            this.load(["TextFormatter"]);
        }
        let optionsTF = this.oTextFormatter.getDefaultOptions();
        this.oTextFormatter.setUsedOptions(optionsTF);
        return this._helpers.mapToObject(this.oTextFormatter.getUsedOptions());
        this.oTextFormatter.setOptions(optionsTF);
        return this._helpers.mapToObject(this.oTextFormatter.getOptions());
    }

    //fonctions concernant plussieurs parties
    verifParagraph(sText, bSuggest = true){
        if (!this.isInit.Grammalecte || !this.isInit.Graphspell) {
            this.load(["Grammalecte"]);
        }