X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0ffe21abd220652547671c0de3cae515fb5fc6e2..b77b96a6fdd5563137a78a3d678bcbfa8bda66db:/src/xbt/xbt_str.c diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 920df6c642..a8d06e7bc1 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -6,9 +6,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#define DJB2_HASH_FUNCTION -//#define FNV_HASH_FUNCTION - #include "portable.h" #include "xbt/misc.h" #include "xbt/sysdep.h" @@ -21,12 +18,12 @@ * 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. - * - "\n" (ASCII 10 (0x0A)) line feed. - * - "\r" (ASCII 13 (0x0D)) carriage return. - * - "\0" (ASCII 0 (0x00)) NULL. - * - "\x0B" (ASCII 11 (0x0B)) vertical tab. + * - " " (ASCII 32 (0x20)) space. + * - "\t" (ASCII 9 (0x09)) tab. + * - "\n" (ASCII 10 (0x0A)) line feed. + * - "\r" (ASCII 13 (0x0D)) carriage return. + * - "\0" (ASCII 0 (0x00)) NULL. + * - "\x0B" (ASCII 11 (0x0B)) vertical tab. * * @param s The string to strip. Modified in place. * @param char_list A string which contains the characters you want to strip. @@ -65,12 +62,12 @@ void xbt_str_rtrim(char *s, const char *char_list) * 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. - * - "\n" (ASCII 10 (0x0A)) line feed. - * - "\r" (ASCII 13 (0x0D)) carriage return. - * - "\0" (ASCII 0 (0x00)) NULL. - * - "\x0B" (ASCII 11 (0x0B)) vertical tab. + * - " " (ASCII 32 (0x20)) space. + * - "\t" (ASCII 9 (0x09)) tab. + * - "\n" (ASCII 10 (0x0A)) line feed. + * - "\r" (ASCII 13 (0x0D)) carriage return. + * - "\0" (ASCII 0 (0x00)) NULL. + * - "\x0B" (ASCII 11 (0x0B)) vertical tab. * * @param s The string to strip. Modified in place. * @param char_list A string which contains the characters you want to strip. @@ -106,12 +103,12 @@ void xbt_str_ltrim(char *s, const char *char_list) * 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. - * - "\n" (ASCII 10 (0x0A)) line feed. - * - "\r" (ASCII 13 (0x0D)) carriage return. - * - "\0" (ASCII 0 (0x00)) NULL. - * - "\x0B" (ASCII 11 (0x0B)) vertical tab. + * - " " (ASCII 32 (0x20)) space. + * - "\t" (ASCII 9 (0x09)) tab. + * - "\n" (ASCII 10 (0x0A)) line feed. + * - "\r" (ASCII 13 (0x0D)) carriage return. + * - "\0" (ASCII 0 (0x00)) NULL. + * - "\x0B" (ASCII 11 (0x0B)) vertical tab. * * @param s The string to strip. * @param char_list A string which contains the characters you want to strip. @@ -226,12 +223,12 @@ char *xbt_str_varsubst(const char *str, xbt_dict_t patterns) * * By default (with sep=NULL), these characters are used as separator: * - * - " " (ASCII 32 (0x20)) space. - * - "\t" (ASCII 9 (0x09)) tab. - * - "\n" (ASCII 10 (0x0A)) line feed. - * - "\r" (ASCII 13 (0x0D)) carriage return. - * - "\0" (ASCII 0 (0x00)) NULL. - * - "\x0B" (ASCII 11 (0x0B)) vertical tab. + * - " " (ASCII 32 (0x20)) space. + * - "\t" (ASCII 9 (0x09)) tab. + * - "\n" (ASCII 10 (0x0A)) line feed. + * - "\r" (ASCII 13 (0x0D)) carriage return. + * - "\0" (ASCII 0 (0x00)) NULL. + * - "\x0B" (ASCII 11 (0x0B)) vertical tab. */ xbt_dynar_t xbt_str_split(const char *s, const char *sep) @@ -906,85 +903,26 @@ char *xbt_str_from_file(FILE * file) return res; } -/** - * @brief Returns the hash code of a string. - */ -XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, - int str_len) -{ - -#ifdef DJB2_HASH_FUNCTION - /* fast implementation of djb2 algorithm */ - int c; - register unsigned int hash = 5381; - - while (str_len--) { - c = *str++; - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - } -# elif defined(FNV_HASH_FUNCTION) - register unsigned int hash = 0x811c9dc5; - unsigned char *bp = (unsigned char *) str; /* start of buffer */ - unsigned char *be = bp + str_len; /* beyond end of buffer */ - - while (bp < be) { - /* multiply by the 32 bit FNV magic prime mod 2^32 */ - hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + - (hash << 24); - - /* xor the bottom with the current octet */ - hash ^= (unsigned int) *bp++; - } - -# else - register unsigned int hash = 0; - - while (str_len--) { - hash += (*str) * (*str); - str++; - } -#endif - - return hash; -} - -/** - * @brief Returns the hash code of a string. +/* @brief Retrun 1 if string 'str' starts with string 'start' + * + * \param str a string + * \param start the string to search in str + * + * \return 1 if 'str' starts with 'start' */ -XBT_INLINE unsigned int xbt_dict_hash(const char *str) +int xbt_str_start_with(const char* str, const char* start) { -#ifdef DJB2_HASH_FUNCTION - /* fast implementation of djb2 algorithm */ - int c; - register unsigned int hash = 5381; - - while ((c = *str++)) { - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - } - -# elif defined(FNV_HASH_FUNCTION) - register unsigned int hash = 0x811c9dc5; + int i; + size_t l_str = strlen(str); + size_t l_start = strlen(start); - while (*str) { - /* multiply by the 32 bit FNV magic prime mod 2^32 */ - hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + - (hash << 24); + if(l_start > l_str) return 0; - /* xor the bottom with the current byte */ - hash ^= (unsigned int) *str++; + for(i = 0; i< l_start; i++){ + if(str[i] != start[i]) return 0; } -# else - register unsigned int hash = 0; - - while (*str) { - hash += (*str) * (*str); - str++; - } -#endif - return hash; + return 1; } #ifdef SIMGRID_TEST