1
by Bernd Zeimetz
Import upstream version 0.8 |
1 |
/* ====================================================================
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
2 |
* Copyright (c) 2004-2011 Open Source Applications Foundation.
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
5 |
* copy of this software and associated documentation files (the "Software"),
|
|
6 |
* to deal in the Software without restriction, including without limitation
|
|
7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8 |
* and/or sell copies of the Software, and to permit persons to whom the
|
|
9 |
* Software is furnished to do so, subject to the following conditions:
|
|
10 |
*
|
|
11 |
* The above copyright notice and this permission notice shall be included
|
|
12 |
* in all copies or substantial portions of the Software.
|
|
13 |
*
|
|
14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20 |
* DEALINGS IN THE SOFTWARE.
|
|
21 |
* ====================================================================
|
|
22 |
*/
|
|
23 |
||
24 |
#include "common.h" |
|
25 |
#include "structmember.h" |
|
26 |
||
27 |
#include "bases.h" |
|
28 |
#include "locale.h" |
|
29 |
#include "collator.h" |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
30 |
#include "iterators.h" |
31 |
#include "unicodeset.h" |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
32 |
#include "macros.h" |
33 |
||
34 |
DECLARE_CONSTANTS_TYPE(UCollationResult); |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
35 |
DECLARE_CONSTANTS_TYPE(UCollAttribute); |
36 |
DECLARE_CONSTANTS_TYPE(UCollAttributeValue); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
37 |
|
38 |
/* CollationKey */
|
|
39 |
||
40 |
class t_collationkey : public _wrapper { |
|
41 |
public: |
|
42 |
CollationKey *object; |
|
43 |
};
|
|
44 |
||
45 |
static int t_collationkey_init(t_collationkey *self, |
|
46 |
PyObject *args, PyObject *kwds); |
|
47 |
static PyObject *t_collationkey_isBogus(t_collationkey *self); |
|
48 |
static PyObject *t_collationkey_compareTo(t_collationkey *self, PyObject *arg); |
|
49 |
static PyObject *t_collationkey_getByteArray(t_collationkey *self); |
|
50 |
||
51 |
static PyMethodDef t_collationkey_methods[] = { |
|
52 |
DECLARE_METHOD(t_collationkey, isBogus, METH_NOARGS), |
|
53 |
DECLARE_METHOD(t_collationkey, compareTo, METH_O), |
|
54 |
DECLARE_METHOD(t_collationkey, getByteArray, METH_NOARGS), |
|
55 |
{ NULL, NULL, 0, NULL } |
|
56 |
};
|
|
57 |
||
58 |
DECLARE_TYPE(CollationKey, t_collationkey, UObject, CollationKey, |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
59 |
t_collationkey_init, NULL); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
60 |
|
61 |
/* Collator */
|
|
62 |
||
63 |
class t_collator : public _wrapper { |
|
64 |
public: |
|
65 |
Collator *object; |
|
66 |
};
|
|
67 |
||
68 |
static PyObject *t_collator_compare(t_collator *self, PyObject *args); |
|
69 |
static PyObject *t_collator_greater(t_collator *self, PyObject *args); |
|
70 |
static PyObject *t_collator_greaterOrEqual(t_collator *self, PyObject *args); |
|
71 |
static PyObject *t_collator_equals(t_collator *self, PyObject *args); |
|
72 |
static PyObject *t_collator_getCollationKey(t_collator *self, PyObject *args); |
|
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
73 |
static PyObject *t_collator_getSortKey(t_collator *self, PyObject *args); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
74 |
static PyObject *t_collator_getStrength(t_collator *self); |
75 |
static PyObject *t_collator_setStrength(t_collator *self, PyObject *arg); |
|
76 |
static PyObject *t_collator_getLocale(t_collator *self, PyObject *args); |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
77 |
static PyObject *t_collator_getAttribute(t_collator *self, PyObject *arg); |
78 |
static PyObject *t_collator_setAttribute(t_collator *self, PyObject *args); |
|
79 |
static PyObject *t_collator_getTailoredSet(t_collator *self); |
|
80 |
static PyObject *t_collator_getVariableTop(t_collator *self); |
|
81 |
static PyObject *t_collator_setVariableTop(t_collator *self, PyObject *arg); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
82 |
static PyObject *t_collator_createInstance(PyTypeObject *type, PyObject *args); |
83 |
static PyObject *t_collator_getAvailableLocales(PyTypeObject *type); |
|
84 |
static PyObject *t_collator_getKeywords(PyTypeObject *type); |
|
85 |
static PyObject *t_collator_getKeywordValues(PyTypeObject *type, PyObject *arg); |
|
86 |
static PyObject *t_collator_getFunctionalEquivalent(PyTypeObject *type, |
|
87 |
PyObject *args); |
|
88 |
||
89 |
static PyMethodDef t_collator_methods[] = { |
|
90 |
DECLARE_METHOD(t_collator, compare, METH_VARARGS), |
|
91 |
DECLARE_METHOD(t_collator, greater, METH_VARARGS), |
|
92 |
DECLARE_METHOD(t_collator, greaterOrEqual, METH_VARARGS), |
|
93 |
DECLARE_METHOD(t_collator, equals, METH_VARARGS), |
|
94 |
DECLARE_METHOD(t_collator, getCollationKey, METH_VARARGS), |
|
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
95 |
DECLARE_METHOD(t_collator, getSortKey, METH_VARARGS), |
1
by Bernd Zeimetz
Import upstream version 0.8 |
96 |
DECLARE_METHOD(t_collator, getStrength, METH_NOARGS), |
97 |
DECLARE_METHOD(t_collator, setStrength, METH_O), |
|
98 |
DECLARE_METHOD(t_collator, getLocale, METH_VARARGS), |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
99 |
DECLARE_METHOD(t_collator, getAttribute, METH_O), |
100 |
DECLARE_METHOD(t_collator, setAttribute, METH_VARARGS), |
|
101 |
DECLARE_METHOD(t_collator, getTailoredSet, METH_O), |
|
102 |
DECLARE_METHOD(t_collator, getVariableTop, METH_NOARGS), |
|
103 |
DECLARE_METHOD(t_collator, setVariableTop, METH_O), |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
104 |
DECLARE_METHOD(t_collator, createInstance, METH_VARARGS | METH_CLASS), |
105 |
DECLARE_METHOD(t_collator, getAvailableLocales, METH_NOARGS | METH_CLASS), |
|
106 |
DECLARE_METHOD(t_collator, getKeywords, METH_NOARGS | METH_CLASS), |
|
107 |
DECLARE_METHOD(t_collator, getKeywordValues, METH_O | METH_CLASS), |
|
108 |
DECLARE_METHOD(t_collator, getFunctionalEquivalent, METH_VARARGS | METH_CLASS), |
|
109 |
{ NULL, NULL, 0, NULL } |
|
110 |
};
|
|
111 |
||
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
112 |
DECLARE_TYPE(Collator, t_collator, UObject, Collator, abstract_init, NULL); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
113 |
|
114 |
/* RuleBasedCollator */
|
|
115 |
||
116 |
class t_rulebasedcollator : public _wrapper { |
|
117 |
public: |
|
118 |
RuleBasedCollator *object; |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
119 |
PyObject *buf; |
120 |
PyObject *base; |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
121 |
};
|
122 |
||
123 |
static int t_rulebasedcollator_init(t_rulebasedcollator *self, |
|
124 |
PyObject *args, PyObject *kwds); |
|
125 |
static PyObject *t_rulebasedcollator_getRules(t_rulebasedcollator *self, |
|
126 |
PyObject *args); |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
127 |
static PyObject *t_rulebasedcollator_createCollationElementIterator(t_rulebasedcollator *self, PyObject *arg); |
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
128 |
static PyObject *t_rulebasedcollator_cloneBinary(t_rulebasedcollator *self); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
129 |
|
130 |
static PyMethodDef t_rulebasedcollator_methods[] = { |
|
131 |
DECLARE_METHOD(t_rulebasedcollator, getRules, METH_VARARGS), |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
132 |
DECLARE_METHOD(t_rulebasedcollator, createCollationElementIterator, METH_O), |
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
133 |
DECLARE_METHOD(t_rulebasedcollator, cloneBinary, METH_NOARGS), |
1
by Bernd Zeimetz
Import upstream version 0.8 |
134 |
{ NULL, NULL, 0, NULL } |
135 |
};
|
|
136 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
137 |
static void t_rulebasedcollator_dealloc(t_rulebasedcollator *self) |
138 |
{
|
|
139 |
if (self->flags & T_OWNED) |
|
140 |
delete self->object; |
|
141 |
self->object = NULL; |
|
142 |
||
143 |
Py_CLEAR(self->buf); |
|
144 |
Py_CLEAR(self->base); |
|
145 |
||
146 |
Py_TYPE(self)->tp_free((PyObject *) self); |
|
147 |
}
|
|
148 |
||
1
by Bernd Zeimetz
Import upstream version 0.8 |
149 |
DECLARE_TYPE(RuleBasedCollator, t_rulebasedcollator, Collator, |
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
150 |
RuleBasedCollator, t_rulebasedcollator_init, |
151 |
t_rulebasedcollator_dealloc); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
152 |
|
153 |
||
154 |
/* CollationKey */
|
|
155 |
||
156 |
static int t_collationkey_init(t_collationkey *self, |
|
157 |
PyObject *args, PyObject *kwds) |
|
158 |
{
|
|
159 |
switch (PyTuple_Size(args)) { |
|
160 |
case 0: |
|
161 |
self->object = new CollationKey(); |
|
162 |
self->flags = T_OWNED; |
|
163 |
break; |
|
164 |
default: |
|
165 |
PyErr_SetArgsError((PyObject *) self, "__init__", args); |
|
166 |
return -1; |
|
167 |
}
|
|
168 |
||
169 |
if (self->object) |
|
170 |
return 0; |
|
171 |
||
172 |
return -1; |
|
173 |
}
|
|
174 |
||
175 |
static PyObject *t_collationkey_isBogus(t_collationkey *self) |
|
176 |
{
|
|
177 |
int b = self->object->isBogus(); |
|
178 |
Py_RETURN_BOOL(b); |
|
179 |
}
|
|
180 |
||
181 |
static PyObject *t_collationkey_compareTo(t_collationkey *self, PyObject *arg) |
|
182 |
{
|
|
183 |
CollationKey *key; |
|
184 |
||
185 |
if (!parseArg(arg, "P", TYPE_CLASSID(CollationKey), &key)) |
|
186 |
{
|
|
187 |
UCollationResult result; |
|
188 |
STATUS_CALL(result = self->object->compareTo(*key, status)); |
|
189 |
return PyInt_FromLong(result); |
|
190 |
}
|
|
191 |
||
192 |
return PyErr_SetArgsError((PyObject *) self, "compareTo", arg); |
|
193 |
}
|
|
194 |
||
195 |
static PyObject *t_collationkey_getByteArray(t_collationkey *self) |
|
196 |
{
|
|
197 |
int32_t count; |
|
198 |
const uint8_t *array = self->object->getByteArray(count); |
|
199 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
200 |
return PyBytes_FromStringAndSize((char *) array, count); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
201 |
}
|
202 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
203 |
DEFINE_RICHCMP(CollationKey, t_collationkey); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
204 |
|
205 |
||
206 |
/* Collator */
|
|
207 |
||
208 |
static PyObject *t_collator_compare(t_collator *self, PyObject *args) |
|
209 |
{
|
|
210 |
UCollationResult result; |
|
211 |
UnicodeString *u, *v; |
|
212 |
UnicodeString _u, _v; |
|
213 |
int len; |
|
214 |
||
215 |
switch (PyTuple_Size(args)) { |
|
216 |
case 2: |
|
217 |
if (!parseArgs(args, "SS", &u, &_u, &v, &_v)) |
|
218 |
{
|
|
219 |
STATUS_CALL(result = self->object->compare(*u, *v, status)); |
|
220 |
return PyInt_FromLong(result); |
|
221 |
}
|
|
222 |
break; |
|
223 |
case 3: |
|
224 |
if (!parseArgs(args, "SSi", &u, &_u, &v, &_v, &len)) |
|
225 |
{
|
|
226 |
STATUS_CALL(result = self->object->compare(*u, *v, len, status)); |
|
227 |
return PyInt_FromLong(result); |
|
228 |
}
|
|
229 |
break; |
|
230 |
}
|
|
231 |
||
232 |
return PyErr_SetArgsError((PyObject *) self, "compare", args); |
|
233 |
}
|
|
234 |
||
235 |
static PyObject *t_collator_greater(t_collator *self, PyObject *args) |
|
236 |
{
|
|
237 |
int b; |
|
238 |
UnicodeString *u, *v; |
|
239 |
UnicodeString _u, _v; |
|
240 |
||
241 |
if (!parseArgs(args, "SS", &u, &_u, &v, &_v)) |
|
242 |
{
|
|
243 |
b = self->object->greater(*u, *v); |
|
244 |
Py_RETURN_BOOL(b); |
|
245 |
}
|
|
246 |
||
247 |
return PyErr_SetArgsError((PyObject *) self, "greater", args); |
|
248 |
}
|
|
249 |
||
250 |
static PyObject *t_collator_greaterOrEqual(t_collator *self, PyObject *args) |
|
251 |
{
|
|
252 |
int b; |
|
253 |
UnicodeString *u, *v; |
|
254 |
UnicodeString _u, _v; |
|
255 |
||
256 |
if (!parseArgs(args, "SS", &u, &_u, &v, &_v)) |
|
257 |
{
|
|
258 |
b = self->object->greaterOrEqual(*u, *v); |
|
259 |
Py_RETURN_BOOL(b); |
|
260 |
}
|
|
261 |
||
262 |
return PyErr_SetArgsError((PyObject *) self, "greaterOrEqual", args); |
|
263 |
}
|
|
264 |
||
265 |
static PyObject *t_collator_equals(t_collator *self, PyObject *args) |
|
266 |
{
|
|
267 |
int b; |
|
268 |
UnicodeString *u, *v; |
|
269 |
UnicodeString _u, _v; |
|
270 |
||
271 |
if (!parseArgs(args, "SS", &u, &_u, &v, &_v)) |
|
272 |
{
|
|
273 |
b = self->object->equals(*u, *v); |
|
274 |
Py_RETURN_BOOL(b); |
|
275 |
}
|
|
276 |
||
277 |
return PyErr_SetArgsError((PyObject *) self, "equals", args); |
|
278 |
}
|
|
279 |
||
280 |
static PyObject *t_collator_getCollationKey(t_collator *self, PyObject *args) |
|
281 |
{
|
|
282 |
UnicodeString *u; |
|
283 |
UnicodeString _u; |
|
284 |
CollationKey *key; |
|
285 |
CollationKey _key; |
|
286 |
||
287 |
switch (PyTuple_Size(args)) { |
|
288 |
case 1: |
|
289 |
if (!parseArgs(args, "S", &u, &_u)) |
|
290 |
{
|
|
291 |
STATUS_CALL(self->object->getCollationKey(*u, _key, status)); |
|
292 |
return wrap_CollationKey(new CollationKey(_key), T_OWNED); |
|
293 |
}
|
|
294 |
break; |
|
295 |
case 2: |
|
296 |
if (!parseArgs(args, "SP", TYPE_CLASSID(CollationKey), |
|
297 |
&u, &_u, &key)) |
|
298 |
{
|
|
299 |
STATUS_CALL(self->object->getCollationKey(*u, *key, status)); |
|
300 |
Py_RETURN_ARG(args, 1); |
|
301 |
}
|
|
302 |
break; |
|
303 |
}
|
|
304 |
||
305 |
return PyErr_SetArgsError((PyObject *) self, "getCollationKey", args); |
|
306 |
}
|
|
307 |
||
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
308 |
static PyObject *t_collator_getSortKey(t_collator *self, PyObject *args) |
309 |
{
|
|
310 |
UnicodeString *u; |
|
311 |
UnicodeString _u; |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
312 |
uint32_t len, size; |
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
313 |
uint8_t *buf; |
314 |
PyObject *key; |
|
315 |
||
316 |
switch (PyTuple_Size(args)) { |
|
317 |
case 1: |
|
318 |
if (!parseArgs(args, "S", &u, &_u)) |
|
319 |
{
|
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
320 |
len = u->length() * 4 + 8; |
321 |
buf = (uint8_t *) malloc(len); |
|
322 |
retry: |
|
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
323 |
if (buf == NULL) |
324 |
return PyErr_NoMemory(); |
|
325 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
326 |
size = self->object->getSortKey(*u, buf, len); |
327 |
if (size <= len) |
|
328 |
{
|
|
329 |
key = PyBytes_FromStringAndSize((char *) buf, size); |
|
330 |
free(buf); |
|
331 |
}
|
|
332 |
else
|
|
333 |
{
|
|
334 |
len = size; |
|
335 |
buf = (uint8_t *) realloc(buf, len); |
|
336 |
goto retry; |
|
337 |
}
|
|
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
338 |
|
339 |
return key; |
|
340 |
}
|
|
341 |
break; |
|
342 |
case 2: |
|
343 |
if (!parseArgs(args, "Si", &u, &_u, &len)) |
|
344 |
{
|
|
345 |
buf = (uint8_t *) calloc(len, 1); |
|
346 |
if (buf == NULL) |
|
347 |
return PyErr_NoMemory(); |
|
348 |
||
349 |
len = self->object->getSortKey(*u, buf, len); |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
350 |
key = PyBytes_FromStringAndSize((char *) buf, len); |
1.1.2
by Bernd Zeimetz
Import upstream version 0.9 |
351 |
free(buf); |
352 |
||
353 |
return key; |
|
354 |
}
|
|
355 |
break; |
|
356 |
}
|
|
357 |
||
358 |
return PyErr_SetArgsError((PyObject *) self, "getSortKey", args); |
|
359 |
}
|
|
360 |
||
1
by Bernd Zeimetz
Import upstream version 0.8 |
361 |
static PyObject *t_collator_getStrength(t_collator *self) |
362 |
{
|
|
363 |
return PyInt_FromLong(self->object->getStrength()); |
|
364 |
}
|
|
365 |
||
366 |
static PyObject *t_collator_setStrength(t_collator *self, PyObject *arg) |
|
367 |
{
|
|
368 |
Collator::ECollationStrength strength; |
|
369 |
||
370 |
if (!parseArg(arg, "i", &strength)) |
|
371 |
{
|
|
372 |
self->object->setStrength(strength); |
|
373 |
Py_RETURN_NONE; |
|
374 |
}
|
|
375 |
||
376 |
return PyErr_SetArgsError((PyObject *) self, "setStrength", arg); |
|
377 |
}
|
|
378 |
||
379 |
static PyObject *t_collator_getLocale(t_collator *self, PyObject *args) |
|
380 |
{
|
|
381 |
ULocDataLocaleType type; |
|
382 |
Locale locale; |
|
383 |
||
384 |
switch (PyTuple_Size(args)) { |
|
385 |
case 0: |
|
386 |
STATUS_CALL(locale = self->object->getLocale(ULOC_VALID_LOCALE, |
|
387 |
status)); |
|
388 |
return wrap_Locale(locale); |
|
389 |
case 1: |
|
390 |
if (!parseArgs(args, "i", &type)) |
|
391 |
{
|
|
392 |
STATUS_CALL(locale = self->object->getLocale(type, status)); |
|
393 |
return wrap_Locale(locale); |
|
394 |
}
|
|
395 |
break; |
|
396 |
}
|
|
397 |
||
398 |
return PyErr_SetArgsError((PyObject *) self, "getLocale", args); |
|
399 |
}
|
|
400 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
401 |
static inline PyObject *wrap_Collator(Collator *collator) |
402 |
{
|
|
403 |
RETURN_WRAPPED_IF_ISINSTANCE(collator, RuleBasedCollator); |
|
404 |
return wrap_Collator(collator, T_OWNED); |
|
405 |
}
|
|
406 |
||
1
by Bernd Zeimetz
Import upstream version 0.8 |
407 |
static PyObject *t_collator_createInstance(PyTypeObject *type, PyObject *args) |
408 |
{
|
|
409 |
Locale *locale; |
|
410 |
Collator *collator; |
|
411 |
||
412 |
switch (PyTuple_Size(args)) { |
|
413 |
case 0: |
|
414 |
STATUS_CALL(collator = Collator::createInstance(status)); |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
415 |
return wrap_Collator(collator); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
416 |
case 1: |
417 |
if (!parseArgs(args, "P", TYPE_CLASSID(Locale), &locale)) |
|
418 |
{
|
|
419 |
STATUS_CALL(collator = Collator::createInstance(*locale, status)); |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
420 |
return wrap_Collator(collator); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
421 |
}
|
422 |
break; |
|
423 |
}
|
|
424 |
||
425 |
return PyErr_SetArgsError(type, "createInstance", args); |
|
426 |
}
|
|
427 |
||
428 |
static PyObject *t_collator_getKeywords(PyTypeObject *type) |
|
429 |
{
|
|
430 |
StringEnumeration *e; |
|
431 |
||
432 |
STATUS_CALL(e = Collator::getKeywords(status)); |
|
433 |
return wrap_StringEnumeration(e, T_OWNED); |
|
434 |
}
|
|
435 |
||
436 |
static PyObject *t_collator_getKeywordValues(PyTypeObject *type, PyObject *arg) |
|
437 |
{
|
|
438 |
StringEnumeration *e; |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
439 |
charsArg keyword; |
1
by Bernd Zeimetz
Import upstream version 0.8 |
440 |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
441 |
if (!parseArg(arg, "n", &keyword)) |
1
by Bernd Zeimetz
Import upstream version 0.8 |
442 |
{
|
443 |
STATUS_CALL(e = Collator::getKeywordValues(keyword, status)); |
|
444 |
return wrap_StringEnumeration(e, T_OWNED); |
|
445 |
}
|
|
446 |
||
447 |
return PyErr_SetArgsError(type, "getKeywordValues", arg); |
|
448 |
}
|
|
449 |
||
450 |
static PyObject *t_collator_getAvailableLocales(PyTypeObject *type) |
|
451 |
{
|
|
452 |
int count; |
|
453 |
const Locale *locales = Collator::getAvailableLocales(count); |
|
454 |
PyObject *dict = PyDict_New(); |
|
455 |
||
456 |
for (int32_t i = 0; i < count; i++) { |
|
457 |
Locale *locale = (Locale *) locales + i; |
|
458 |
PyObject *obj = wrap_Locale(locale, 0); |
|
459 |
PyDict_SetItemString(dict, locale->getName(), obj); |
|
460 |
Py_DECREF(obj); |
|
461 |
}
|
|
462 |
||
463 |
return dict; |
|
464 |
}
|
|
465 |
||
466 |
static PyObject *t_collator_getFunctionalEquivalent(PyTypeObject *type, |
|
467 |
PyObject *args) |
|
468 |
{
|
|
469 |
UBool isAvailable; |
|
470 |
Locale *locale; |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
471 |
charsArg keyword; |
1
by Bernd Zeimetz
Import upstream version 0.8 |
472 |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
473 |
if (!parseArgs(args, "nP", TYPE_CLASSID(Locale), |
1
by Bernd Zeimetz
Import upstream version 0.8 |
474 |
&keyword, &locale)) |
475 |
{
|
|
476 |
Locale result(*locale); |
|
477 |
STATUS_CALL(Collator::getFunctionalEquivalent(keyword, result, |
|
478 |
isAvailable, status)); |
|
479 |
return Py_BuildValue("(OO)", wrap_Locale(result), |
|
480 |
isAvailable ? Py_True : Py_False); |
|
481 |
}
|
|
482 |
||
483 |
return PyErr_SetArgsError(type, "getFunctionalEquivalent", args); |
|
484 |
}
|
|
485 |
||
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
486 |
static PyObject *t_collator_getAttribute(t_collator *self, PyObject *arg) |
487 |
{
|
|
488 |
UColAttribute attribute; |
|
489 |
||
490 |
if (!parseArg(arg, "i", &attribute)) |
|
491 |
{
|
|
492 |
UColAttributeValue value; |
|
493 |
STATUS_CALL(value = self->object->getAttribute(attribute, status)); |
|
494 |
||
495 |
return PyInt_FromLong(value); |
|
496 |
}
|
|
497 |
||
498 |
return PyErr_SetArgsError((PyObject *) self, "getAttribute", arg); |
|
499 |
}
|
|
500 |
||
501 |
static PyObject *t_collator_setAttribute(t_collator *self, PyObject *args) |
|
502 |
{
|
|
503 |
UColAttribute attribute; |
|
504 |
UColAttributeValue value; |
|
505 |
||
506 |
if (!parseArgs(args, "ii", &attribute, &value)) |
|
507 |
{
|
|
508 |
STATUS_CALL(self->object->setAttribute(attribute, value, status)); |
|
509 |
Py_RETURN_NONE; |
|
510 |
}
|
|
511 |
||
512 |
return PyErr_SetArgsError((PyObject *) self, "setAttribute", args); |
|
513 |
}
|
|
514 |
||
515 |
static PyObject *t_collator_getTailoredSet(t_collator *self) |
|
516 |
{
|
|
517 |
UnicodeSet *set; |
|
518 |
||
519 |
STATUS_CALL(set = self->object->getTailoredSet(status)); |
|
520 |
return wrap_UnicodeSet(set, T_OWNED); |
|
521 |
}
|
|
522 |
||
523 |
static PyObject *t_collator_getVariableTop(t_collator *self) |
|
524 |
{
|
|
525 |
uint32_t top; |
|
526 |
||
527 |
STATUS_CALL(top = self->object->getVariableTop(status)); |
|
528 |
return PyInt_FromLong(top >> 16); |
|
529 |
}
|
|
530 |
||
531 |
static PyObject *t_collator_setVariableTop(t_collator *self, PyObject *arg) |
|
532 |
{
|
|
533 |
UnicodeString *u, _u; |
|
534 |
uint32_t top; |
|
535 |
||
536 |
if (!parseArg(arg, "i", &top)) |
|
537 |
{
|
|
538 |
STATUS_CALL(self->object->setVariableTop(top << 16, status)); |
|
539 |
Py_RETURN_NONE; |
|
540 |
}
|
|
541 |
else if (!parseArg(arg, "S", &u, &_u)) |
|
542 |
{
|
|
543 |
STATUS_CALL(self->object->setVariableTop(*u, status)); /* transient */ |
|
544 |
Py_RETURN_NONE; |
|
545 |
}
|
|
546 |
||
547 |
return PyErr_SetArgsError((PyObject *) self, "setVariableTop", arg); |
|
548 |
}
|
|
549 |
||
550 |
||
551 |
static int t_collator_hash(t_collator *self) |
|
552 |
{
|
|
553 |
return self->object->hashCode(); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
554 |
}
|
555 |
||
556 |
||
557 |
/* RuleBasedCollator */
|
|
558 |
||
559 |
static int t_rulebasedcollator_init(t_rulebasedcollator *self, |
|
560 |
PyObject *args, PyObject *kwds) |
|
561 |
{
|
|
562 |
UnicodeString *u; |
|
563 |
UnicodeString _u; |
|
564 |
RuleBasedCollator *collator; |
|
565 |
Collator::ECollationStrength strength; |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
566 |
UColAttributeValue decompositionMode; |
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
567 |
PyObject *buf, *base; |
1
by Bernd Zeimetz
Import upstream version 0.8 |
568 |
|
569 |
switch (PyTuple_Size(args)) { |
|
570 |
case 1: |
|
571 |
if (!parseArgs(args, "S", &u, &_u)) |
|
572 |
{
|
|
573 |
INT_STATUS_CALL(collator = new RuleBasedCollator(*u, status)); |
|
574 |
self->object = collator; |
|
575 |
self->flags = T_OWNED; |
|
576 |
break; |
|
577 |
}
|
|
578 |
PyErr_SetArgsError((PyObject *) self, "__init__", args); |
|
579 |
return -1; |
|
580 |
case 2: |
|
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
581 |
if (!parseArgs(args, "CO", &RuleBasedCollatorType, &buf, &base)) |
582 |
{
|
|
583 |
INT_STATUS_CALL(collator = new RuleBasedCollator((uint8_t *) PyBytes_AS_STRING(buf), PyBytes_GET_SIZE(buf), ((t_rulebasedcollator *) base)->object, status)); |
|
584 |
self->object = collator; |
|
585 |
self->flags = T_OWNED; |
|
586 |
self->buf = buf; Py_INCREF(buf); |
|
587 |
self->base = base; Py_INCREF(base); |
|
588 |
break; |
|
589 |
}
|
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
590 |
PyErr_SetArgsError((PyObject *) self, "__init__", args); |
591 |
return -1; |
|
592 |
case 3: |
|
593 |
if (!parseArgs(args, "Sii", &u, &_u, &strength, &decompositionMode)) |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
594 |
{
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
595 |
INT_STATUS_CALL(collator = new RuleBasedCollator(*u, strength, decompositionMode, status)); |
1
by Bernd Zeimetz
Import upstream version 0.8 |
596 |
self->object = collator; |
597 |
self->flags = T_OWNED; |
|
598 |
break; |
|
599 |
}
|
|
600 |
PyErr_SetArgsError((PyObject *) self, "__init__", args); |
|
601 |
return -1; |
|
602 |
default: |
|
603 |
PyErr_SetArgsError((PyObject *) self, "__init__", args); |
|
604 |
return -1; |
|
605 |
}
|
|
606 |
||
607 |
if (self->object) |
|
608 |
return 0; |
|
609 |
||
610 |
return -1; |
|
611 |
}
|
|
612 |
||
613 |
static PyObject *t_rulebasedcollator_getRules(t_rulebasedcollator *self, |
|
614 |
PyObject *args) |
|
615 |
{
|
|
616 |
UnicodeString u = self->object->getRules(); |
|
617 |
return PyUnicode_FromUnicodeString(&u); |
|
618 |
}
|
|
619 |
||
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
620 |
static PyObject *t_rulebasedcollator_createCollationElementIterator(t_rulebasedcollator *self, PyObject *arg) |
621 |
{
|
|
622 |
UnicodeString *u, _u; |
|
623 |
CharacterIterator *chars; |
|
624 |
CollationElementIterator *iterator; |
|
625 |
||
626 |
if (!parseArg(arg, "S", &u, &_u)) |
|
627 |
{
|
|
628 |
iterator = self->object->createCollationElementIterator(*u); |
|
629 |
return wrap_CollationElementIterator(iterator, T_OWNED); |
|
630 |
}
|
|
631 |
else if (!parseArg(arg, "P", TYPE_ID(CharacterIterator), &chars)) |
|
632 |
{
|
|
633 |
iterator = self->object->createCollationElementIterator(*chars); |
|
634 |
return wrap_CollationElementIterator(iterator, T_OWNED); |
|
635 |
}
|
|
636 |
||
637 |
return PyErr_SetArgsError((PyObject *) self, "createCollationElementIterator", arg); |
|
638 |
}
|
|
639 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
640 |
static PyObject *t_rulebasedcollator_cloneBinary(t_rulebasedcollator *self) |
641 |
{
|
|
642 |
UErrorCode status = U_ZERO_ERROR; |
|
643 |
PyObject *result; |
|
644 |
int32_t len; |
|
645 |
||
646 |
len = self->object->cloneBinary(NULL, 0, status); |
|
647 |
result = PyBytes_FromStringAndSize(NULL, len); |
|
648 |
if (!result) |
|
649 |
return NULL; |
|
650 |
||
651 |
STATUS_CALL(len = self->object->cloneBinary((uint8_t *) PyBytes_AS_STRING(result), len, status)); |
|
652 |
||
653 |
return result; |
|
654 |
}
|
|
655 |
||
1
by Bernd Zeimetz
Import upstream version 0.8 |
656 |
static PyObject *t_rulebasedcollator_str(t_rulebasedcollator *self) |
657 |
{
|
|
658 |
UnicodeString u = self->object->getRules(); |
|
659 |
return PyUnicode_FromUnicodeString(&u); |
|
660 |
}
|
|
661 |
||
1.1.5
by Jakub Wilk
Import upstream version 1.3 |
662 |
DEFINE_RICHCMP(RuleBasedCollator, t_rulebasedcollator); |
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
663 |
|
664 |
||
1
by Bernd Zeimetz
Import upstream version 0.8 |
665 |
void _init_collator(PyObject *m) |
666 |
{
|
|
667 |
CollationKeyType.tp_richcompare = (richcmpfunc) t_collationkey_richcmp; |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
668 |
CollatorType.tp_hash = (hashfunc) t_collator_hash; |
1
by Bernd Zeimetz
Import upstream version 0.8 |
669 |
RuleBasedCollatorType.tp_str = (reprfunc) t_rulebasedcollator_str; |
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
670 |
RuleBasedCollatorType.tp_richcompare = |
671 |
(richcmpfunc) t_rulebasedcollator_richcmp; |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
672 |
|
673 |
INSTALL_CONSTANTS_TYPE(UCollationResult, m); |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
674 |
INSTALL_CONSTANTS_TYPE(UCollAttribute, m); |
675 |
INSTALL_CONSTANTS_TYPE(UCollAttributeValue, m); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
676 |
REGISTER_TYPE(CollationKey, m); |
677 |
INSTALL_TYPE(Collator, m); |
|
678 |
REGISTER_TYPE(RuleBasedCollator, m); |
|
679 |
||
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
680 |
INSTALL_ENUM(UCollationResult, "LESS", UCOL_LESS); |
681 |
INSTALL_ENUM(UCollationResult, "EQUAL", UCOL_EQUAL); |
|
682 |
INSTALL_ENUM(UCollationResult, "GREATER", UCOL_GREATER); |
|
683 |
||
684 |
INSTALL_ENUM(UCollAttribute, "FRENCH_COLLATION", UCOL_FRENCH_COLLATION); |
|
685 |
INSTALL_ENUM(UCollAttribute, "ALTERNATE_HANDLING", UCOL_ALTERNATE_HANDLING); |
|
686 |
INSTALL_ENUM(UCollAttribute, "CASE_FIRST", UCOL_CASE_FIRST); |
|
687 |
INSTALL_ENUM(UCollAttribute, "CASE_LEVEL", UCOL_CASE_LEVEL); |
|
688 |
INSTALL_ENUM(UCollAttribute, "NORMALIZATION_MODE", UCOL_NORMALIZATION_MODE); |
|
689 |
INSTALL_ENUM(UCollAttribute, "DECOMPOSITION_MODE", UCOL_DECOMPOSITION_MODE); |
|
690 |
INSTALL_ENUM(UCollAttribute, "STRENGTH", UCOL_STRENGTH); |
|
691 |
INSTALL_ENUM(UCollAttribute, "HIRAGANA_QUATERNARY_MODE", UCOL_HIRAGANA_QUATERNARY_MODE); |
|
692 |
INSTALL_ENUM(UCollAttribute, "NUMERIC_COLLATION", UCOL_NUMERIC_COLLATION); |
|
693 |
||
694 |
INSTALL_ENUM(UCollAttributeValue, "DEFAULT", UCOL_DEFAULT); |
|
695 |
INSTALL_ENUM(UCollAttributeValue, "PRIMARY", UCOL_PRIMARY); |
|
696 |
INSTALL_ENUM(UCollAttributeValue, "SECONDARY", UCOL_SECONDARY); |
|
697 |
INSTALL_ENUM(UCollAttributeValue, "TERTIARY", UCOL_TERTIARY); |
|
698 |
INSTALL_ENUM(UCollAttributeValue, "DEFAULT_STRENGTH", UCOL_DEFAULT_STRENGTH); |
|
699 |
INSTALL_ENUM(UCollAttributeValue, "QUATERNARY", UCOL_QUATERNARY); |
|
700 |
INSTALL_ENUM(UCollAttributeValue, "IDENTICAL", UCOL_IDENTICAL); |
|
701 |
INSTALL_ENUM(UCollAttributeValue, "OFF", UCOL_OFF); |
|
702 |
INSTALL_ENUM(UCollAttributeValue, "ON", UCOL_ON); |
|
703 |
INSTALL_ENUM(UCollAttributeValue, "SHIFTED", UCOL_SHIFTED); |
|
704 |
INSTALL_ENUM(UCollAttributeValue, "NON_IGNORABLE", UCOL_NON_IGNORABLE); |
|
705 |
INSTALL_ENUM(UCollAttributeValue, "LOWER_FIRST", UCOL_LOWER_FIRST); |
|
706 |
INSTALL_ENUM(UCollAttributeValue, "UPPER_FIRST", UCOL_UPPER_FIRST); |
|
707 |
||
708 |
INSTALL_ENUM(UCollationResult, "LESS", UCOL_LESS); |
|
709 |
INSTALL_ENUM(UCollationResult, "EQUAL", UCOL_EQUAL); |
|
710 |
INSTALL_ENUM(UCollationResult, "GREATER", UCOL_GREATER); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
711 |
|
712 |
INSTALL_STATIC_INT(Collator, PRIMARY); |
|
713 |
INSTALL_STATIC_INT(Collator, SECONDARY); |
|
714 |
INSTALL_STATIC_INT(Collator, TERTIARY); |
|
715 |
INSTALL_STATIC_INT(Collator, QUATERNARY); |
|
716 |
INSTALL_STATIC_INT(Collator, IDENTICAL); |
|
1.1.3
by Bernd Zeimetz
Import upstream version 1.0 |
717 |
|
718 |
INSTALL_STATIC_INT(CollationElementIterator, NULLORDER); |
|
1
by Bernd Zeimetz
Import upstream version 0.8 |
719 |
}
|