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

  ASSERT (mbspbrk ("Some text", "") == NULL);

  {
    const char input[] = "A long sentence";
    ASSERT (mbspbrk (input, "aeiou") == input + 3);
    ASSERT (mbspbrk (input, "iI") == NULL);
  }

  /* The following tests shows how mbspbrk() is different from strpbrk().  */

  {
    const char input[] = "B\303\266se B\303\274bchen"; /* "Böse Bübchen" */
    ASSERT (mbspbrk (input, "\303\244\303\274") == input + 7); /* "äü" */
  }

  {
    const char input[] = "B\303\266se B\303\274bchen"; /* "Böse Bübchen" */
    ASSERT (mbspbrk (input, "\303") == NULL); /* invalid multibyte sequence */
  }

  return 0;
}
Esempio n. 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);
}
Esempio n. 3
0
char *
mbssep (char **stringp, const char *delim)
{
    if (MB_CUR_MAX > 1)
    {
        char *start = *stringp;
        char *ptr;

        if (start == NULL)
            return NULL;

        /* No need to optimize the cases of 0 or 1 delimiters specially,
           since mbspbrk already optimizes them.  */

        ptr = mbspbrk (start, delim);

        if (ptr == NULL)
        {
            *stringp = NULL;
            return start;
        }
        else
        {
            mbui_iterator_t iter;

            mbui_init (iter, ptr);
            if (!mbui_avail (iter))
                abort ();
            mbui_advance (iter);
            *ptr = '\0';
            *stringp = (char *) mbui_cur_ptr (iter);
            return start;
        }
    }
    else
        return strsep (stringp, delim);
}