summaryrefslogtreecommitdiff
path: root/awk/utils.awk
blob: 7384ea0cf575f96edcf7696b759e194e6a9cb43f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Helper functions

# Remove all whitespace in str
function trim(str) {
    gsub(/[ \t]/, "", str);
    return str;
}

# Remove all whitespace around str
function trim_surrounding(str) {
    gsub(/^[ \t]*/, "", str);
    gsub(/[ \t]*$/, "", str);
    return str;
}

# Time n days before the current time
function time_days_ago(n) {
    return strftime("%FT%TZ", systime() - 24 * 60 * 60 * n, 1);
}

function or_default(var, def) {
    return (var != "") ? var : def;
}

# Combine two tag strings
function combine_tags(tags1, tags2) {
    if (tags1 == "") {
        return tags2;
    } else {
        return substr(tags1, 0, length(tags1) - 1) tags2
    }
}