示例#1
0
文件: word.c 项目: baohaojun/dico
static int
word_sel(int cmd, dico_key_t key, const char *dict_word)
{
    int rc = 0;
    char const *key_word = key->word;
    struct dico_tokbuf tb;
    int i;
    
    switch (cmd) {
    case DICO_SELECT_BEGIN:
	break;

    case DICO_SELECT_RUN:
	dico_tokenize_begin(&tb);
	if (dico_tokenize_string(&tb, (char*) dict_word)) {
	    dico_tokenize_end(&tb);
	    return 0;
	}
	for (i = 0; i < tb.tb_tokc; i++)
	    if (utf8_strcasecmp(tb.tb_tokv[i], (char*) key_word) == 0) {
		rc = 1;
		break;
	    }
	dico_tokenize_end(&tb);
	break;

    case DICO_SELECT_END:
	break;
    }
    return rc;
}
示例#2
0
/* Returns the attribute in SET whose name matches NAME
   case-insensitively, or a null pointer if SET does not contain
   an attribute with that name. */
struct attribute *
attrset_lookup (struct attrset *set, const char *name)
{
  struct attribute *attr;
  HMAP_FOR_EACH_WITH_HASH (attr, struct attribute, node,
                           utf8_hash_case_string (name, 0), &set->map)
    if (!utf8_strcasecmp (attribute_get_name (attr), name))
      break;
  return attr;
}
示例#3
0
文件: utf8.c 项目: baohaojun/dico
static int
op_strcasecmp(int argc, char **argv)
{
    char *opname = *argv++;
    argc--;
    if (argc != 2) {
	dico_log(L_ERR, 0, "%s requires two arguments", opname);
	return 1;
    }
    printf("%d\n", utf8_strcasecmp(argv[0], argv[1]));
    return 0;
}
示例#4
0
/* Checks that SET contains STRING. */
static void
check_set_contains (struct stringi_set *set, const char *string)
{
  struct stringi_set_node *node;

  check (stringi_set_contains (set, string));
  check (!stringi_set_insert (set, string));
  check (!stringi_set_insert_nocopy (set, xstrdup (string)));

  node = stringi_set_find_node (set, string);
  check (node != NULL);
  check (!utf8_strcasecmp (string, stringi_set_node_get_string (node)));
}
示例#5
0
文件: word.c 项目: baohaojun/dico
static int
first_sel(int cmd, dico_key_t key, const char *dict_word)
{
    int rc = 0;
    char const *key_word = key->word;
    struct dico_tokbuf tb;
    
    switch (cmd) {
    case DICO_SELECT_BEGIN:
	break;

    case DICO_SELECT_RUN:
	dico_tokenize_begin(&tb);
	if (dico_tokenize_string(&tb, (char*) dict_word) == 0 && tb.tb_tokc) 
	    rc = utf8_strcasecmp(tb.tb_tokv[0], (char*) key_word) == 0;
	dico_tokenize_end(&tb);
	break;

    case DICO_SELECT_END:
	break;
    }
    return rc;
}
示例#6
0
/* Checks that SET contains the CNT strings in DATA, that its structure is
   correct, and that certain operations on SET produce the expected results. */
static void
check_stringi_set (struct stringi_set *set, const int data[], size_t cnt)
{
  size_t i;

  check (stringi_set_is_empty (set) == (cnt == 0));
  check (stringi_set_count (set) == cnt);

  for (i = 0; i < cnt; i++)
    {
      const char *s;
      char copy[16];
      char *p;

      s = make_string (data[i]);
      check_set_contains (set, s);

      strcpy (copy, s);
      for (p = copy; *p != '\0'; p++)
        {
          assert (isupper (*p));
          *p = tolower (*p);
          check_set_contains (set, copy);
        }
    }

  check (!stringi_set_contains (set, "xxx"));
  check (stringi_set_find_node (set, "") == NULL);

  if (cnt == 0)
    {
      check (stringi_set_first (set) == NULL);
      free (stringi_set_get_array (set));
    }
  else
    {
      const struct stringi_set_node *node;
      char **array;
      int *data_copy;
      int left;

      array = stringi_set_get_array (set);
      data_copy = xmemdup (data, cnt * sizeof *data);
      left = cnt;
      for (node = stringi_set_first (set), i = 0; i < cnt;
           node = stringi_set_next (set, node), i++)
        {
          const char *s = stringi_set_node_get_string (node);
          size_t j;

          check (s == array[i]);

          for (j = 0; j < left; j++)
            if (!utf8_strcasecmp (s, make_string (data_copy[j])))
              {
                data_copy[j] = data_copy[--left];
                goto next;
              }
          check_die ();

        next: ;
        }
      check (node == NULL);
      free (data_copy);
      free (array);

      array = stringi_set_get_sorted_array (set);
      for (i = 0; i < cnt; i++)
        {
          if (i > 0)
            check (utf8_strcasecmp (array[i - 1], array[i]) < 0);
          check (stringi_set_contains (set, array[i]));
        }
      free (array);
    }
}