Grammalecte  Check-in [86c9c40cab]

Overview
Comment:[core] gc engine: new operator (@) for regex text processor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: 86c9c40cab4be357c1f6169ef80c17b19539ba42a3ddc8265e17e11588bf9213
User & Date: olr on 2019-01-02 12:56:09
Other Links: manifest | tags
Context
2019-01-02
13:58
[fr] html: purge des espaces insécables fins check-in: 0e847b75ad user: olr tags: trunk, fr
12:56
[core] gc engine: new operator (@) for regex text processor check-in: 86c9c40cab user: olr tags: trunk, core
12:55
[fr] nr: de sorte que, +ajustements divers check-in: 136beb2dc6 user: olr tags: trunk, fr
Changes

Modified gc_core/js/lang_core/gc_engine.js from [9248952883] to [8e4be3285b].

229
230
231
232
233
234
235



236
237
238
239
240
241
242
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245







+
+
+







        }
        if (this.sText.includes("'")) {
            this.sText = this.sText.replace(/'/g, "’");
        }
        if (this.sText.includes("‑")) {
            this.sText = this.sText.replace(/‑/g, "-"); // nobreakdash
        }
        if (this.sText.includes("@@")) {
            this.sText = this.sText.replace(/@@+/g, "");
        }

        // parse sentence
        for (let [iStart, iEnd] of gc_engine.getSentenceBoundaries(this.sText)) {
            try {
                this.sSentence = this.sText.slice(iStart, iEnd);
                this.sSentence0 = this.sText0.slice(iStart, iEnd);
                this.nOffsetWithinParagraph = iStart;
793
794
795
796
797
798
799
800
801


802
803
804
805
806
807
808
796
797
798
799
800
801
802


803
804
805
806
807
808
809
810
811







-
-
+
+







    rewriteText (sText, sRepl, iGroup, m, bUppercase) {
        // text processor: write sRepl in sText at iGroup position"
        let ln = m.end[iGroup] - m.start[iGroup];
        let sNew = "";
        if (sRepl === "*") {
            sNew = " ".repeat(ln);
        }
        else if (sRepl === ">" || sRepl === "_" || sRepl === "~") {
            sNew = sRepl + " ".repeat(ln-1);
        else if (sRepl === "_") {
            sNew = "_".repeat(ln);
        }
        else if (sRepl === "@") {
            sNew = "@".repeat(ln);
        }
        else if (sRepl.slice(0,1) === "=") {
            sNew = oEvalFunc[sRepl.slice(1)](sText, m);
            sNew = sNew + " ".repeat(ln-sNew.length);

Modified gc_core/py/lang_core/gc_engine.py from [621c240c96] to [7f3fb3a1a4].

258
259
260
261
262
263
264


265
266
267
268
269
270
271
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273







+
+







            sText = sText.replace(" ", ' ') # nbsp
        if " " in sText:
            sText = sText.replace(" ", ' ') # nnbsp
        if "'" in sText:
            sText = sText.replace("'", "’")
        if "‑" in sText:
            sText = sText.replace("‑", "-") # nobreakdash
        if "@@" in sText:
            sText = re.sub("@@+", "", sText)

        # parse sentences
        for iStart, iEnd in _getSentenceBoundaries(sText):
            if 4 < (iEnd - iStart) < 2000:
                try:
                    self.sSentence = sText[iStart:iEnd]
                    self.sSentence0 = self.sText0[iStart:iEnd]
685
686
687
688
689
690
691
692



693
694
695
696
697
698
699
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701
702
703







-
+
+
+








    def rewriteText (self, sText, sRepl, iGroup, m, bUppercase):
        "text processor: write <sRepl> in <sText> at <iGroup> position"
        nLen = m.end(iGroup) - m.start(iGroup)
        if sRepl == "*":
            sNew = " " * nLen
        elif sRepl == "_":
            sNew = sRepl + " " * (nLen-1)
            sNew = "_" * nLen
        elif sRepl == "@":
            sNew = "@" * nLen
        elif sRepl[0:1] == "=":
            sNew = globals()[sRepl[1:]](sText, m)
            sNew = sNew + " " * (nLen-len(sNew))
            if bUppercase and m.group(iGroup)[0:1].isupper():
                sNew = sNew.capitalize()
        else:
            sNew = m.expand(sRepl)