const uint32_t *
u32_next (ucs4_t *puc, const uint32_t *s)
{
  int count;

  count = u32_strmbtouc (puc, s);
  if (count > 0)
    return s + count;
  else
    {
#if CONFIG_UNICODE_SAFETY
      if (count < 0)
        *puc = 0xfffd;
#endif
      return NULL;
    }
}
Пример #2
0
int
main ()
{
  ucs4_t uc;
  int ret;

  /* Test NUL unit input.  */
  {
    static const uint32_t input[] = { 0 };
    uc = 0xBADFACE;
    ret = u32_strmbtouc (&uc, input);
    ASSERT (ret == 0);
    ASSERT (uc == 0);
  }

  /* Test ISO 646 unit input.  */
  {
    ucs4_t c;
    uint32_t buf[2];

    for (c = 1; c < 0x80; c++)
      {
        buf[0] = c;
        buf[1] = 0;
        uc = 0xBADFACE;
        ret = u32_strmbtouc (&uc, buf);
        ASSERT (ret == 1);
        ASSERT (uc == c);
      }
  }

  /* Test BMP unit input.  */
  {
    static const uint32_t input[] = { 0x20AC, 0 };
    uc = 0xBADFACE;
    ret = u32_strmbtouc (&uc, input);
    ASSERT (ret == 1);
    ASSERT (uc == 0x20AC);
  }

  /* Test non-BMP unit input.  */
  {
    static const uint32_t input[] = { 0x1D51F, 0 };
    uc = 0xBADFACE;
    ret = u32_strmbtouc (&uc, input);
    ASSERT (ret == 1);
    ASSERT (uc == 0x1D51F);
  }

#if CONFIG_UNICODE_SAFETY
  /* Test incomplete/invalid 1-unit input.  */
  {
    static const uint32_t input[] = { 0x340000, 0 };
    uc = 0xBADFACE;
    ret = u32_strmbtouc (&uc, input);
    ASSERT (ret == -1);
    ASSERT (uc == 0xBADFACE);
  }
#endif

  return 0;
}