From dac626c14eaff40ee37182cfdd66daafc8fef4ad Mon Sep 17 00:00:00 2001 From: Martin Nilsson <mani@lysator.liu.se> Date: Thu, 17 Feb 2000 19:05:16 +0100 Subject: [PATCH] Added trim_whites and trim_all_whites. Rev: lib/modules/String.pmod:1.9 --- lib/modules/String.pmod | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/modules/String.pmod b/lib/modules/String.pmod index e68abc905c..58a573165d 100644 --- a/lib/modules/String.pmod +++ b/lib/modules/String.pmod @@ -171,3 +171,27 @@ int fuzzymatch(string a, string b) return fuzz; } + +string trim_whites( string what ) +{ + if (stringp (what)) { + sscanf(what, "%*[ \t]%s", what); + string rev = reverse(what); + sscanf(rev, "%*[ \t]%s", rev); + return what[..strlen(rev) - 1]; + } + + return what; +} + +string trim_all_whites( string what ) +{ + if (stringp (what)) { + sscanf(what, "%*[ \t\r\n]%s", what); + string rev = reverse(what); + sscanf(rev, "%*[ \t\r\n]%s", rev); + return what[..strlen(rev) - 1]; + } + + return what; +} -- GitLab