8be2a5d14b01e092a92db5b926ac4963d6882287 tdreszer Fri Apr 15 16:58:58 2011 -0700 Added routine to find the last non-whitespace char in a string diff --git src/lib/common.c src/lib/common.c index b3d235c..25edcd3 100644 --- src/lib/common.c +++ src/lib/common.c @@ -1375,30 +1375,45 @@ eLen = strlen(end); offset = sLen - eLen; if (offset < 0) return FALSE; return sameString(string+offset, end); } char lastChar(char *s) /* Return last character in string. */ { if (s == NULL || s[0] == 0) return 0; return s[strlen(s)-1]; } +char *lastNonWhitespaceChar(char *s) +// Return pointer to last character in string that is not whitespace. +{ +if (s == NULL || s[0] == 0) + return NULL; + +char *sPos = s + (strlen(s) - 1); +for (;sPos >= s;sPos--) + { + if (!isspace(*sPos)) + return sPos; + } +return NULL; +} + char *matchingCharBeforeInLimits(char *limit, char *s, char c) /* Look for character c sometime before s, but going no further than limit. * Return NULL if not found. */ { while (--s >= limit) if (*s == c) return s; return NULL; } char *memMatch(char *needle, int nLen, char *haystack, int hLen) /* Returns first place where needle (of nLen chars) matches * haystack (of hLen chars) */ { char c = *needle++;