From b752e4c0bf35563ab1cae8af2940258327f1d415 Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 10 May 2007 14:02:14 +0000 Subject: [PATCH] Clarify from the API that the strings are modified in place by the trim functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3501 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/str.h | 6 +++--- src/xbt/xbt_str.c | 40 +++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/include/xbt/str.h b/include/xbt/str.h index 7ac8448316..36c4bdc54c 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -33,9 +33,9 @@ XBT_PUBLIC(long) getline(char **lineptr, size_t *n, FILE *stream); #endif /* Trim related functions */ -XBT_PUBLIC(char*) xbt_str_rtrim(char* s, const char* char_list); -XBT_PUBLIC(char*) xbt_str_ltrim( char* s, const char* char_list); -XBT_PUBLIC(char*) xbt_str_trim(char* s, const char* char_list); +XBT_PUBLIC(void) xbt_str_rtrim(char* s, const char* char_list); +XBT_PUBLIC(void) xbt_str_ltrim( char* s, const char* char_list); +XBT_PUBLIC(void) xbt_str_trim(char* s, const char* char_list); XBT_PUBLIC(xbt_dynar_t) xbt_str_split(char *s, const char *sep); XBT_PUBLIC(char *) xbt_str_join(xbt_dynar_t dynar, const char *sep); diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 9b4f244fa4..0897546e6c 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -26,8 +26,8 @@ static void free_string(void *d){ /** @brief Strip whitespace (or other characters) from the end of a string. * - * This function returns a string with whitespace stripped from the end of s. - * By default (without the second parameter char_list), xbt_str_rtrim() will strip these characters : + * Strips the whitespaces from the end of s. + * By default (when char_list=NULL), these characters get stripped: * * - " " (ASCII 32 (0x20)) space. * - "\t" (ASCII 9 (0x09)) tab. @@ -36,13 +36,11 @@ static void free_string(void *d){ * - "\0" (ASCII 0 (0x00)) NULL. * - "\x0B" (ASCII 11 (0x0B)) vertical tab. * - * @param s The string to strip. + * @param s The string to strip. Modified in place. * @param char_list A string which contains the characters you want to strip. * - * @return If the specified is NULL the function returns NULL. Otherwise the - * function returns the string with whitespace stripped from the end. */ -char* +void xbt_str_rtrim(char* s, const char* char_list) { char* cur = s; @@ -50,7 +48,7 @@ xbt_str_rtrim(char* s, const char* char_list) char white_char[256] = {1,0}; if(!s) - return NULL; + return; if(!char_list){ while(*__char_list) { @@ -69,13 +67,12 @@ xbt_str_rtrim(char* s, const char* char_list) --cur; *++cur = '\0'; - return s; } /** @brief Strip whitespace (or other characters) from the beginning of a string. * - * This function returns a string with whitespace stripped from the beginning of s. - * By default (without the second parameter char_list), xbt_str_ltrim() will strip these characters : + * Strips the whitespaces from the begining of s. + * By default (when char_list=NULL), these characters get stripped: * * - " " (ASCII 32 (0x20)) space. * - "\t" (ASCII 9 (0x09)) tab. @@ -84,13 +81,11 @@ xbt_str_rtrim(char* s, const char* char_list) * - "\0" (ASCII 0 (0x00)) NULL. * - "\x0B" (ASCII 11 (0x0B)) vertical tab. * - * @param s The string to strip. + * @param s The string to strip. Modified in place. * @param char_list A string which contains the characters you want to strip. * - * @return If the specified is NULL the function returns NULL. Otherwise the - * function returns the string with whitespace stripped from the beginning. */ -char* +void xbt_str_ltrim( char* s, const char* char_list) { char* cur = s; @@ -98,7 +93,7 @@ xbt_str_ltrim( char* s, const char* char_list) char white_char[256] = {1,0}; if(!s) - return NULL; + return; if(!char_list){ while(*__char_list) { @@ -113,13 +108,13 @@ xbt_str_ltrim( char* s, const char* char_list) while(*cur && white_char[(unsigned char)*cur]) ++cur; - return memmove(s,cur, strlen(cur)); + memmove(s,cur, strlen(cur)); } /** @brief Strip whitespace (or other characters) from the end and the begining of a string. * - * This returns a string with whitespace stripped from the end and the begining of s. - * By default (without the second parameter char_list), xbt_str_trim() will strip these characters : + * Strips the whitespaces from both the beginning and the end of s. + * By default (when char_list=NULL), these characters get stripped: * * - " " (ASCII 32 (0x20)) space. * - "\t" (ASCII 9 (0x09)) tab. @@ -131,16 +126,15 @@ xbt_str_ltrim( char* s, const char* char_list) * @param s The string to strip. * @param char_list A string which contains the characters you want to strip. * - * @return If the specified is NULL the function returns NULL. Otherwise the - * function returns the string with whitespace stripped from the end and the begining. */ -char* +void xbt_str_trim(char* s, const char* char_list ){ if(!s) - return NULL; + return; - return xbt_str_ltrim(xbt_str_rtrim(s,char_list),char_list); + xbt_str_rtrim(s,char_list); + xbt_str_ltrim(s,char_list); } /** @brief Replace double whitespaces (but no other characters) from the string. -- 2.20.1