From 5c9cbf5ea152f501ae976e0e0b4ef5ee98afdfba Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期四, 11 六月 2020 19:20:40 +0800 Subject: [PATCH] pdate --- common/usg_common.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/common/usg_common.c b/common/usg_common.c index 4b0f76e..6ba65ae 100644 --- a/common/usg_common.c +++ b/common/usg_common.c @@ -76,3 +76,41 @@ fputs(buf, stderr); fflush(NULL); /* flushes all stdio output streams */ } + +char *ltrim(char *str, const char *seps) +{ + size_t totrim; + if (seps == NULL) { + seps = "\t\n\v\f\r "; + } + totrim = strspn(str, seps); + if (totrim > 0) { + size_t len = strlen(str); + if (totrim == len) { + str[0] = '\0'; + } + else { + memmove(str, str + totrim, len + 1 - totrim); + } + } + return str; +} + +char *rtrim(char *str, const char *seps) +{ + int i; + if (seps == NULL) { + seps = "\t\n\v\f\r "; + } + i = strlen(str) - 1; + while (i >= 0 && strchr(seps, str[i]) != NULL) { + str[i] = '\0'; + i--; + } + return str; +} + +char *trim(char *str, const char *seps) +{ + return ltrim(rtrim(str, seps), seps); +} \ No newline at end of file -- Gitblit v1.8.0