Exemple #1
0
int
main ()
{
  /* configure should already have checked that the locale is supported.  */
  if (setlocale (LC_ALL, "") == NULL)
    return 1;

  ASSERT (mbsspn ("Some text", "") == 0);

  ASSERT (mbsspn ("A long sentence", " ") == 0);
  ASSERT (mbsspn ("  xy", "aei ou") == 2);
  ASSERT (mbsspn ("eau", "aeiou") == 3);

  /* The following tests shows how mbsspn() is different from strspn().  */

  {
    const char input[] = "\303\266\303\274"; /* "öü" */
    ASSERT (mbsspn (input, "\303\266") == 2); /* "ö" */
    ASSERT (mbsspn (input, "\303\244") == 0); /* "ä" */
    ASSERT (mbsspn (input, "\303\274\303\266") == 4); /* "üö" */
    ASSERT (mbsspn (input, "\303\244\303\274") == 0); /* "äü" */
    ASSERT (mbsspn (input, "\303\244\303\266") == 2); /* "äö" */
  }

  {
    const char input[] = "\303\266\303\274"; /* "öü" */
    ASSERT (mbsspn (input, "\303") == 0); /* invalid multibyte sequence */
  }

  return 0;
}
Exemple #2
0
char *
mbstok_r (char *string, const char *delim, char **save_ptr)
{
  if (MB_CUR_MAX > 1)
    {
      if (string == NULL)
        {
          string = *save_ptr;
          if (string == NULL)
            return NULL; /* reminder that end of token sequence has been
                            reached */
        }

      /* Skip leading delimiters.  */
      string += mbsspn (string, delim);

      /* Found a token?  */
      if (*string == '\0')
        {
          *save_ptr = NULL;
          return NULL;
        }

      /* Move past the token.  */
      {
        char *token_end = mbspbrk (string, delim);

        if (token_end != NULL)
          {
            /* NUL-terminate the token.  */
            *token_end = '\0';
            *save_ptr = token_end + 1;
          }
        else
          *save_ptr = NULL;
      }

      return string;
    }
  else
    return strtok_r (string, delim, save_ptr);
}