diff options
author | Leon Rische <leon.rische@me.com> | 2020-05-04 14:03:30 +0200 |
---|---|---|
committer | Leon Rische <leon.rische@me.com> | 2020-05-04 14:03:30 +0200 |
commit | ce08d32408f969c6b6e6de23b9f22258cd245fd3 (patch) | |
tree | 4023a162654c3418c80e00f1d6a6c031844337ef /awk/utils.awk | |
parent | 3cef1c6bef3fcec3fc01342b776a51644282090b (diff) |
Escape all strings in indexer
Diffstat (limited to 'awk/utils.awk')
-rw-r--r-- | awk/utils.awk | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/awk/utils.awk b/awk/utils.awk index 7384ea0..358f024 100644 --- a/awk/utils.awk +++ b/awk/utils.awk @@ -26,7 +26,30 @@ function or_default(var, def) { function combine_tags(tags1, tags2) { if (tags1 == "") { return tags2; + } else if (tags2 == "") { + return tags1; } else { return substr(tags1, 0, length(tags1) - 1) tags2 } } + +# Convert an ISO8601 timestamp to an Emacs timestamp +# (second_upper_16_bit, second_lower_16_bit) +function parse_time(time) { + # mktime expects a format of "YYYY MM DD HH MM SS" + # and doesn't care about the trailing space left by the "Z" + gsub(/[\-T:Z]/, " ", time); + + ts = mktime(time, 1); + ts_h = rshift(ts, 16); + ts_l = and(ts, 0xffff); + + return "(" ts_h " " ts_l ")"; +} + +# TODO: I'm sure there are cases not covered by this +function escape_string(str) { + gsub(/\\/, "\\\\", str); + gsub(/"/, "\\\"", str); + return "\"" str "\""; +} |