xbt_str_ltrim(s, char_list);
}
-/** @brief Replace double whitespaces (but no other characters) from the string.
- *
- * The function modifies the string so that each time that several spaces appear,
- * they are replaced by a single space. It will only do so for spaces (ASCII 32, 0x20).
- *
- * @param s The string to strip. Modified in place.
- *
- */
-void xbt_str_strip_spaces(char *s)
-{
- char *p = s;
- int e = 0;
-
- if (!s)
- return;
-
- while (1) {
- if (!*p)
- goto end;
-
- if (*p != ' ')
- break;
-
- p++;
- }
-
- e = 1;
-
- do {
- if (e)
- *s++ = *p;
-
- if (!*++p)
- goto end;
-
- if (e ^ (*p != ' '))
- if ((e = !e))
- *s++ = ' ';
- } while (1);
-
-end:
- *s = '\0';
-}
-
/** @brief Substitutes a char for another in a string
*
* @param str the string to modify
return res;
}
-/* @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'
- */
-int xbt_str_start_with(const char* str, const char* start)
-{
- unsigned int i;
- size_t l_str = strlen(str);
- size_t l_start = strlen(start);
-
- if(l_start > l_str) return 0;
-
- for(i = 0; i< l_start; i++){
- if(str[i] != start[i]) return 0;
- }
-
- return 1;
-}
-
/** @brief Parse an integer out of a string, or raise an error
*
* The #str is passed as argument to your #error_msg, as follows:
XBT_TEST_UNIT("xbt_str_parse", test_parse, "Test the parsing functions")
{
xbt_ex_t e;
- int rint;
+ int rint = -9999;
test_parse_ok(xbt_str_parse_int, "Parse int", rint, "42", 42);
test_parse_ok(xbt_str_parse_int, "Parse 0 as an int", rint, "0", 0);
test_parse_ok(xbt_str_parse_int, "Parse -1 as an int", rint, "-1", -1);
test_parse_error(xbt_str_parse_int, "Parse '' as an int", rint, "");
test_parse_error(xbt_str_parse_int, "Parse cruft as an int", rint, "cruft");
- double rdouble;
+ double rdouble = -9999;
test_parse_ok(xbt_str_parse_double, "Parse 42 as a double", rdouble, "42", 42);
test_parse_ok(xbt_str_parse_double, "Parse 42.5 as a double", rdouble, "42.5", 42.5);
test_parse_ok(xbt_str_parse_double, "Parse 0 as a double", rdouble, "0", 0);