-/** @brief Strip whitespace (or other characters) from the end of a string.
- *
- * Strips the whitespaces from the end of s.
- * By default (when char_list=nullptr), 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)) nullptr.
- * - "\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.
- */
-void xbt_str_rtrim(char *s, const char *char_list)
-{
- char *cur = s;
- const char *__char_list = " \t\n\r\x0B";
- char white_char[256] = { 1, 0 };
-
- if (not s)
- return;
-
- if (not char_list) {
- while (*__char_list) {
- white_char[(unsigned char) *__char_list++] = 1;
- }
- } else {
- while (*char_list) {
- white_char[(unsigned char) *char_list++] = 1;
- }
- }
-
- while (*cur)
- ++cur;
-
- while ((cur >= s) && white_char[(unsigned char) *cur])
- --cur;
-
- *++cur = '\0';
-}
-
-/** @brief Strip whitespace (or other characters) from the beginning of a string.
- *
- * Strips the whitespaces from the begining of s.
- * By default (when char_list=nullptr), 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)) nullptr.
- * - "\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.
- */
-void xbt_str_ltrim(char *s, const char *char_list)
-{
- char *cur = s;
- const char *__char_list = " \t\n\r\x0B";
- char white_char[256] = { 1, 0 };
-
- if (not s)
- return;
-
- if (not char_list) {
- while (*__char_list) {
- white_char[(unsigned char) *__char_list++] = 1;
- }
- } else {
- while (*char_list) {
- white_char[(unsigned char) *char_list++] = 1;
- }
- }
-
- while (*cur && white_char[(unsigned char) *cur])
- ++cur;
-
- memmove(s, cur, strlen(cur) + 1);
-}
-
-/** @brief Strip whitespace (or other characters) from the end and the begining of a string.
- *
- * Strips the whitespaces from both the beginning and the end of s.
- * By default (when char_list=nullptr), 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)) nullptr.
- * - "\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.
- */
-void xbt_str_trim(char *s, const char *char_list)
-{
- if (not s)
- return;
-
- xbt_str_rtrim(s, char_list);
- xbt_str_ltrim(s, char_list);
-}
-
-/** @brief Substitutes a char for another in a string
- *
- * @param str the string to modify
- * @param from char to search
- * @param to char to put instead
- * @param occurence number of changes to do (=0 means all)
- */
-void xbt_str_subst(char *str, char from, char to, int occurence)
-{
- char *p = str;
- while (*p != '\0') {
- if (*p == from) {
- *p = to;
- if (occurence == 1)
- return;
- occurence--;
- }
- p++;
- }
-}
-