1 /*
2 Copyright(C) 2009-2018 Brazil
3 Copyright(C) 2021 Sutou Kouhei <kou@clear-code.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 module groonga_d.string_;
20
21
22 private static import groonga_d.groonga;
23
24 extern(C):
25 nothrow @nogc:
26
27 /* grn_str: deprecated. use grn_string instead. */
28
29 struct grn_str
30 {
31 const (char)* orig;
32 char* norm;
33 short* checks;
34 ubyte* ctypes;
35 int flags;
36 uint orig_blen;
37 uint norm_blen;
38 uint length;
39 groonga_d.groonga.grn_encoding encoding;
40 }
41
42 enum GRN_STR_REMOVEBLANK = 0x01 << 0;
43 enum GRN_STR_WITH_CTYPES = 0x01 << 1;
44 enum GRN_STR_WITH_CHECKS = 0x01 << 2;
45 enum GRN_STR_NORMALIZE = groonga_d.groonga.GRN_OBJ_KEY_NORMALIZE;
46
47 //GRN_API
48 grn_str* grn_str_open(groonga_d.groonga.grn_ctx* ctx, const (char)* str, uint str_len, int flags);
49
50 //GRN_API
51 groonga_d.groonga.grn_rc grn_str_close(groonga_d.groonga.grn_ctx* ctx, grn_str* nstr);
52
53 /* grn_string */
54
55 enum GRN_STRING_REMOVE_BLANK = 0x01 << 0;
56 enum GRN_STRING_WITH_TYPES = 0x01 << 1;
57 enum GRN_STRING_WITH_CHECKS = 0x01 << 2;
58 enum GRN_STRING_REMOVE_TOKENIZED_DELIMITER = 0x01 << 3;
59
60 /+
61 #define GRN_NORMALIZER_AUTO (cast(groonga_d.groonga.grn_obj *)(1))
62 +/
63
64 enum GRN_CHAR_BLANK = 0x80;
65
66 /+
67 #define GRN_CHAR_IS_BLANK(c) ((c) & (GRN_CHAR_BLANK))
68 #define GRN_CHAR_TYPE(c) ((c) & 0x7F)
69 +/
70
71 enum grn_char_type
72 {
73 GRN_CHAR_NULL = 0,
74 GRN_CHAR_ALPHA,
75 GRN_CHAR_DIGIT,
76 GRN_CHAR_SYMBOL,
77 GRN_CHAR_HIRAGANA,
78 GRN_CHAR_KATAKANA,
79 GRN_CHAR_KANJI,
80 GRN_CHAR_OTHERS,
81 GRN_CHAR_EMOJI,
82 }
83
84 //Declaration name in C language
85 enum
86 {
87 GRN_CHAR_NULL = .grn_char_type.GRN_CHAR_NULL,
88 GRN_CHAR_ALPHA = .grn_char_type.GRN_CHAR_ALPHA,
89 GRN_CHAR_DIGIT = .grn_char_type.GRN_CHAR_DIGIT,
90 GRN_CHAR_SYMBOL = .grn_char_type.GRN_CHAR_SYMBOL,
91 GRN_CHAR_HIRAGANA = .grn_char_type.GRN_CHAR_HIRAGANA,
92 GRN_CHAR_KATAKANA = .grn_char_type.GRN_CHAR_KATAKANA,
93 GRN_CHAR_KANJI = .grn_char_type.GRN_CHAR_KANJI,
94 GRN_CHAR_OTHERS = .grn_char_type.GRN_CHAR_OTHERS,
95 GRN_CHAR_EMOJI = .grn_char_type.GRN_CHAR_EMOJI,
96 }
97
98 //GRN_API
99 const (char)* grn_char_type_to_string(grn_char_type type);
100
101 //GRN_API
102 groonga_d.groonga.grn_obj* grn_string_open(groonga_d.groonga.grn_ctx* ctx, const (char)* string_, uint length_in_bytes, groonga_d.groonga.grn_obj* lexicon_or_normalizer, int flags);
103
104 //GRN_API
105 groonga_d.groonga.grn_rc grn_string_get_original(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, const (char)** original, uint* length_in_bytes);
106
107 //GRN_API
108 int grn_string_get_flags(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
109
110 //GRN_API
111 groonga_d.groonga.grn_rc grn_string_get_normalized(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, const (char)** normalized, uint* length_in_bytes, uint* n_characters);
112
113 //GRN_API
114 groonga_d.groonga.grn_rc grn_string_set_normalized(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, char* normalized, uint length_in_bytes, uint n_characters);
115
116 //GRN_API
117 const (short)* grn_string_get_checks(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
118
119 //GRN_API
120 groonga_d.groonga.grn_rc grn_string_set_checks(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, short* checks);
121
122 //GRN_API
123 const (ubyte)* grn_string_get_types(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
124
125 //GRN_API
126 groonga_d.groonga.grn_rc grn_string_set_types(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, ubyte* types);
127
128 //GRN_API
129 const (ulong)* grn_string_get_offsets(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
130
131 //GRN_API
132 groonga_d.groonga.grn_rc grn_string_set_offsets(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_, ulong* offsets);
133
134 //GRN_API
135 groonga_d.groonga.grn_encoding grn_string_get_encoding(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
136
137 //GRN_API
138 groonga_d.groonga.grn_obj* grn_string_get_table(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
139
140 //GRN_API
141 uint grn_string_get_normalizer_index(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* string_);
142
143 //GRN_API
144 int grn_charlen(groonga_d.groonga.grn_ctx* ctx, const (char)* str, const (char)* end);