diff --git a/sh/core/code.awk b/sh/core/code.awk index 10ca584..44890b5 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -36,37 +36,44 @@ function doc_reset() { function extract(string, type) { if (type == "alias") { split(string, array, "#=") - return trim(array[2]) + return strip(array[2]) } else if (type == "command") { split(string, array, "#/") - return trim(array[2]) + return strip(array[2]) } else if (type == "doc") { split(string, array, "#") - return trim(array[2]) + return strip(array[2]) } else if (type == "function") { split(string, array, "(") - return trim(array[1]) + return strip(array[1]) } else if (type == "module") { split(string, array, "#\\.") - return trim(array[2]) + return strip(array[2]) } else if (type == "shebang") { split(string, array, "#!") - return trim(array[2]) + return strip(array[2]) } else if ((type == "constant") || (type == "variable")) { split(string, array, "=") - return trim(array[1]) + return strip(array[1]) } } +function strip(string, tmp) { + tmp = string + sub("^[\t ]*", "", tmp) + sub("[\t ]*$", "", tmp) + return tmp +} + function strip_first(string, sep, tmp) { tmp = string sub(sep, "", tmp) - return trim(tmp) + return strip(tmp) } function strip_from(string, sep, tmp) { split(string, tmp, sep) - return trim(tmp[1]) + return strip(tmp[1]) } function strip_function(string, tmp) { @@ -77,13 +84,6 @@ function strip_value(string, tmp) { return strip_from(string, "=") } -function trim(string) { - text = string - sub("^[\t ]*", "", text) - sub("[\t ]*$", "", text) - return text -} - # → begin BEGIN {