コード例 #1
0
const uint16_t *
u16_next (ucs4_t *puc, const uint16_t *s)
{
  int count;

  count = u16_strmbtouc (puc, s);
  if (count > 0)
    return s + count;
  else
    {
      if (count < 0)
        *puc = 0xfffd;
      return NULL;
    }
}
コード例 #2
0
ファイル: test-u16-strmbtouc.c プロジェクト: ajnelson/gnulib
int
main ()
{
  ucs4_t uc;
  int ret;

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

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

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

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

  /* Test 2-units character input.  */
  {
    static const uint16_t input[] = { 0xD835, 0xDD1F, 0 };
    uc = 0xBADFACE;
    ret = u16_strmbtouc (&uc, input);
    ASSERT (ret == 2);
    ASSERT (uc == 0x1D51F);
  }

  /* Test incomplete/invalid 1-unit input.  */
  {
    static const uint16_t input[] = { 0xD835, 0 };
    uc = 0xBADFACE;
    ret = u16_strmbtouc (&uc, input);
    ASSERT (ret == -1);
    ASSERT (uc == 0xBADFACE);
  }
  {
    static const uint16_t input[] = { 0xDD1F, 0 };
    uc = 0xBADFACE;
    ret = u16_strmbtouc (&uc, input);
    ASSERT (ret == -1);
    ASSERT (uc == 0xBADFACE);
  }

  return 0;
}