diff options
| Commit | eff5393a6c45a02cd0c703c62fac52b6c7733307 (patch) | |
|---|---|---|
| Author | 2023-04-28 23:24:59 +0300 | |
| Committer | 2023-04-28 23:24:59 +0300 | |
| Files | 892af9016d16058f906d1e7cf6c5d0095008c438 /awk-edits/#strings.awk | |
| syndamia.com-eff5393a6c45a02cd0c703c62fac52b6c7733307.tar syndamia.com-eff5393a6c45a02cd0c703c62fac52b6c7733307.tar.gz syndamia.com-eff5393a6c45a02cd0c703c62fac52b6c7733307.zip | ||
| Parent | 973c5dcaaa0273a4050cff5e81b2ef14262bc39d (diff) | |
[Syntax-highlighting] Added UNFINISHED support for lookaround
1 files changed, 32 insertions, 0 deletions
| -rw-r--r-- | awk-edits/#strings.awk | 32 |
diff --git a/awk-edits/#strings.awk b/awk-edits/#strings.awk index a34757e..cc469e8 100644 --- a/awk-edits/#strings.awk +++ b/awk-edits/#strings.awk @@ -43,3 +43,35 @@ function gesub(regexp, exregexp, replacement, target) { return result target; } + +# glsub(lbregexp, regexp, largexp, replacement [, empt, target]) +# Aka global sub with non-capturing look-around (lookbehind and lookahead) +function glsub(lbregexp, regexp, laregexp, replacement, empt, target) { + if (!length(target)) { + target = $0; + } + if (empt >= 2) { + RSTART = 1; + RLENGTH = 0; + empt -= 2; + } + + result = ""; + subst = ""; + while ((RSTART == 1 && RLENGTH == 0 && length(result) == 0) || match(target, lbregexp)) { + result = result substr(target, 1, RSTART + RLENGTH - 1); + target = substr(target, RSTART + RLENGTH); + match(target, regexp); + if (RSTART == 1) { + subst = substr(target, RSTART, RLENGTH); + target = substr(target, RSTART + RLENGTH); + match(target, laregexp); + if ((empt == 1 && length(target) == 0) || RSTART == 1) { + sub(/.*/, replacement, subst); + } + result = result subst; + } + } + + return result target; +} |