示例#1
0
int
main ()
{
  static const uint8_t input[] =
    #define INPUT1_OFFSET 0
    #define INPUT1_LENGTH 13
    "Danilo \305\240egan"
    #define INPUT2_OFFSET 13
    #define INPUT2_LENGTH 14
    "Danilo S\314\214egan"
    #define INPUT3_OFFSET 27
    #define INPUT3_LENGTH 23
    "\320\224\320\260\320\275\320\270\320\273\320\276 \320\250\320\265\320\263\320\260\320\275"
    #define INPUT4_OFFSET 50
    #define INPUT4_LENGTH 9
    "\345\210\230\345\206\233\346\260\221"
    ;

  { /* "Danilo Šegan" */
    ASSERT (u8_width (input + INPUT1_OFFSET, INPUT1_LENGTH, "UTF-8") == 12);
  }

  { /* "Danilo Šegan" decomposed */
    ASSERT (u8_width (input + INPUT2_OFFSET, INPUT2_LENGTH, "UTF-8") == 12);
  }

  { /* "Данило Шеган" */
    ASSERT (u8_width (input + INPUT3_OFFSET, INPUT3_LENGTH, "UTF-8") == 12);
    ASSERT (u8_width (input + INPUT3_OFFSET, INPUT3_LENGTH, "EUC-JP") == 23);
  }

  { /* 刘军民 */
    ASSERT (u8_width (input + INPUT4_OFFSET, INPUT4_LENGTH, "UTF-8") == 6);
    ASSERT (u8_width (input + INPUT4_OFFSET, INPUT4_LENGTH, "GB2312") == 6);
  }

  return 0;
}
示例#2
0
int
u8_strwidth (const uint8_t *s, const char *encoding)
{
  return u8_width (s, u8_strlen (s), encoding);
}