Example #1
0
void
boundary_set_from_string (boundary *bound, char *loc_str)
{
  /* Must search in reverse since the file name field may
   * contain `.' or `:'.  */
  char *delim = mbsrchr (loc_str, '.');
  aver (delim);
  *delim = '\0';
  bound->column = atoi (delim+1);
  delim = mbsrchr (loc_str, ':');
  aver (delim);
  *delim = '\0';
  bound->line = atoi (delim+1);
  bound->file = uniqstr_new (loc_str);
}
int
main ()
{
  /* configure should already have checked that the locale is supported.  */
  if (setlocale (LC_ALL, "") == NULL)
    return 1;

  /* Tests with a character < 0x30.  */
  {
    const char input[] = "\312\276\300\375 \312\276\300\375 \312\276\300\375"; /* "示例 示例 示例" */
    const char *result = mbsrchr (input, ' ');
    ASSERT (result == input + 9);
  }

  {
    const char input[] = "\312\276\300\375"; /* "示例" */
    const char *result = mbsrchr (input, ' ');
    ASSERT (result == NULL);
  }

  /* Tests with a character >= 0x30.  */
  {
    const char input[] = "\272\305123\324\313\320\320\241\243"; /* "号123运行。" */
    const char *result = mbsrchr (input, '2');
    ASSERT (result == input + 3);
  }

  /* This test shows how mbschr() is different from strchr().  */
  {
    const char input[] = "\203\062\332\066123\324\313\203\062\332\066\320\320\241\243"; /* "씋123运씋行。" */
    const char *result = mbsrchr (input, '2');
    ASSERT (result == input + 5);
  }

  return 0;
}