Introduction
Introduction Statistics Contact Development Disclaimer Help
sfeed_content: fix unescaping function - sfeed_curses - sfeed curses UI (now pa…
git clone git://git.codemadness.org/sfeed_curses
Log
Files
Refs
README
LICENSE
---
commit 3693c4b6d682bb0b888db657dcfc8fb9309acfd9
parent 015b434b8f0345665a9b6920f6dbbd361518904a
Author: Hiltjo Posthuma <[email protected]>
Date: Sat, 6 Mar 2021 11:14:18 +0100
sfeed_content: fix unescaping function
A sequence with an escaped \ before another sequence will be incorrectly
unescaped.
To reproduce it:
printf '\t\t\tcontent\\t\\\\n\nabc\tplain\n' | sfeed_content
This also slightly improves performance by not using a regex.
Diffstat:
M sfeed_content | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/sfeed_content b/sfeed_content
@@ -7,10 +7,19 @@
awk -F '\t' '
function unescape(s) {
- gsub("\\\\t", "\t", s);
- gsub("\\\\n", "\n", s);
- gsub("\\\\\\\\", "\\", s);
- return s;
+ for (data = ""; (idx = index(s, "\\")); s = substr(s, idx + 2)) {
+ prev = substr(s, 1, idx - 1)
+ c = substr(s, idx + 1, 1)
+ if (c == "t")
+ data = data prev "\t"
+ else if (c == "n")
+ data = data prev "\n"
+ else if (c == "\\")
+ data = data prev "\\"
+ else
+ data = data prev # ignore other.
+ }
+ return data s # rest
}
BEGIN {
htmlconv = "lynx -stdin -dump " \
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.