From b953c4c67cfc6f0de38526e97eb5fc6031d61c81 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sun, 28 Feb 2010 22:48:16 +0300 Subject: s3: Move source3/iniparser to lib/iniparser to allow sharing between s3/s4 Signed-off-by: Stefan Metzmacher --- lib/iniparser/src/strlib.c | 211 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 lib/iniparser/src/strlib.c (limited to 'lib/iniparser/src/strlib.c') diff --git a/lib/iniparser/src/strlib.c b/lib/iniparser/src/strlib.c new file mode 100644 index 0000000000..f0d85aea58 --- /dev/null +++ b/lib/iniparser/src/strlib.c @@ -0,0 +1,211 @@ + +/*-------------------------------------------------------------------------*/ +/** + @file strlib.c + @author N. Devillard + @date Jan 2001 + @version $Revision: 1.9 $ + @brief Various string handling routines to complement the C lib. + + This modules adds a few complementary string routines usually missing + in the standard C library. +*/ +/*--------------------------------------------------------------------------*/ + +/* + $Id: strlib.c,v 1.9 2006-09-27 11:04:11 ndevilla Exp $ + $Author: ndevilla $ + $Date: 2006-09-27 11:04:11 $ + $Revision: 1.9 $ +*/ + +/*--------------------------------------------------------------------------- + Includes + ---------------------------------------------------------------------------*/ + +#include +#include + +#include "strlib.h" + +/*--------------------------------------------------------------------------- + Defines + ---------------------------------------------------------------------------*/ +#define ASCIILINESZ 1024 + +/*--------------------------------------------------------------------------- + Function codes + ---------------------------------------------------------------------------*/ + + +/*-------------------------------------------------------------------------*/ +/** + @brief Convert a string to lowercase. + @param s String to convert. + @return ptr to statically allocated string. + + This function returns a pointer to a statically allocated string + containing a lowercased version of the input string. Do not free + or modify the returned string! Since the returned string is statically + allocated, it will be modified at each function call (not re-entrant). + */ +/*--------------------------------------------------------------------------*/ + +char * strlwc(const char * s) +{ + static char l[ASCIILINESZ+1]; + int i ; + + if (s==NULL) return NULL ; + memset(l, 0, ASCIILINESZ+1); + i=0 ; + while (s[i] && i l) { + if (!isspace((int)*(last-1))) + break ; + last -- ; + } + *last = (char)0; + return l ; +} + + + +/*-------------------------------------------------------------------------*/ +/** + @brief Remove blanks at the beginning and the end of a string. + @param s String to parse. + @return ptr to statically allocated string. + + This function returns a pointer to a statically allocated string, + which is identical to the input string, except that all blank + characters at the end and the beg. of the string have been removed. + Do not free or modify the returned string! Since the returned string + is statically allocated, it will be modified at each function call + (not re-entrant). + */ +/*--------------------------------------------------------------------------*/ +char * strstrip(char * s) +{ + static char l[ASCIILINESZ+1]; + char * last ; + + if (s==NULL) return NULL ; + + while (isspace((int)*s) && *s) s++; + + memset(l, 0, ASCIILINESZ+1); + strcpy(l, s); + last = l + strlen(l); + while (last > l) { + if (!isspace((int)*(last-1))) + break ; + last -- ; + } + *last = (char)0; + + return (char*)l ; +} + +/* Test code */ +#ifdef TEST +int main(int argc, char * argv[]) +{ + char * str ; + + str = "\t\tI'm a lumberkack and I'm OK " ; + printf("lowercase: [%s]\n", strlwc(str)); + printf("uppercase: [%s]\n", strupc(str)); + printf("skipped : [%s]\n", strskp(str)); + printf("cropped : [%s]\n", strcrop(str)); + printf("stripped : [%s]\n", strstrip(str)); + + return 0 ; +} +#endif +/* vim: set ts=4 et sw=4 tw=75 */ -- cgit