aboutsummaryrefslogtreecommitdiff
path: root/include/dico/utf8.h
blob: ad0d43d1f516a2a62fc689371791bf646d6a8bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* This file is part of GNU Dico.
   Copyright (C) 2008, 2010, 2012, 2016 Sergey Poznyakoff

   GNU Dico is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GNU Dico is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Dico.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef __dico_utf8_h
#define __dico_utf8_h

#include <ctype.h>

size_t utf8_char_width(const char *p);
size_t utf8_strlen (const char *s);
size_t utf8_strbytelen (const char *s);

struct utf8_iterator {
    char *string;
    char *curptr;
    unsigned curwidth;
};

#define utf8_iter_isascii(itr) \
 ((itr).curwidth == 1 && isascii((itr).curptr[0]))

int utf8_iter_end_p(struct utf8_iterator *itr);
int utf8_iter_first(struct utf8_iterator *itr, char *ptr);
int utf8_iter_next(struct utf8_iterator *itr);

int utf8_mbtowc_internal (void *data, int (*read) (void*), unsigned int *pwc);
int utf8_wctomb (char *r, unsigned int wc);

int utf8_symcmp(char *a, char *b);
int utf8_symcasecmp(char *a, char *b);
int utf8_strcasecmp(char *a, char *b);
int utf8_strncasecmp(char *a, char *b, size_t maxlen);

unsigned utf8_wc_toupper (unsigned wc);
int utf8_toupper (char *s);
unsigned utf8_wc_tolower (unsigned wc);
int utf8_tolower (char *s);
size_t utf8_wc_strlen (const unsigned *s);
unsigned *utf8_wc_strdup (const unsigned *s);
size_t utf8_wc_hash_string (const unsigned *ws, size_t n_buckets);
int utf8_wc_strcmp (const unsigned *a, const unsigned *b);
int utf8_wc_strncmp(const unsigned *a, const unsigned *b, size_t n);
int utf8_wc_strcasecmp(const unsigned *a, const unsigned *b);
int utf8_wc_strncasecmp(const unsigned *a, const unsigned *b, size_t n);

int utf8_wc_to_mbstr(const unsigned *wordbuf, size_t wordlen, char **sptr);

int utf8_mbstr_to_wc(const char *str, unsigned **wptr, size_t *plen);
int utf8_mbstr_to_norm_wc(const char *str, unsigned **nptr, size_t *plen);

int utf8_quote (const char *str, char **sptr);
unsigned *utf8_wc_quote (const unsigned *s);

const unsigned *utf8_wc_strchr(const unsigned *str, unsigned chr);
const unsigned *utf8_wc_strchr_ci(const unsigned *str, unsigned chr);

enum utf8_strpat_result {
    strpat_found,
    strpat_not_found,
    strpat_error
};

enum utf8_strpat_result utf8_wc_strpat(const unsigned *text,
				       const unsigned *pattern,
				       size_t *return_offset);


const unsigned *utf8_wc_strstr(const unsigned *haystack,
			       const unsigned *needle);

void utf8_wc_strupper(unsigned *str);
void utf8_wc_strlower(unsigned *str);

#define DICO_LEV_NORM    0x1
#define DICO_LEV_DAMERAU 0x2

int dico_levenshtein_distance(const char *a, const char *b, int flags);
#define DICO_SOUNDEX_SIZE 5
int dico_soundex(const char *s, char codestr[DICO_SOUNDEX_SIZE]);

#endif

Return to:

Send suggestions and report system problems to the System administrator.