// Collator.startswith {{{ static PyObject * icu_Collator_startswith(icu_Collator *self, PyObject *args, PyObject *kwargs) { PyObject *a_ = NULL, *b_ = NULL; int32_t asz = 0, bsz = 0; UChar *a = NULL, *b = NULL; uint8_t ans = 0; if (!PyArg_ParseTuple(args, "OO", &a_, &b_)) return NULL; a = python_to_icu(a_, &asz, 1); if (a == NULL) goto end; b = python_to_icu(b_, &bsz, 1); if (b == NULL) goto end; if (asz < bsz) goto end; if (bsz == 0) { ans = 1; goto end; } ans = ucol_equal(self->collator, a, bsz, b, bsz); end: if (a != NULL) free(a); if (b != NULL) free(b); if (PyErr_Occurred()) return NULL; if (ans) { Py_RETURN_TRUE; } Py_RETURN_FALSE; } // }}}
static int icu_collator_equals(lua_State *L) { luaL_argcheck(L, lua_getmetatable(L,1) && lua_rawequal(L,-1,COLLATOR_UV_META), 1, "expecting collator"); lua_pop(L,1); icu4lua_checkustring(L,2,COLLATOR_UV_USTRING_META); icu4lua_checkustring(L,3,COLLATOR_UV_USTRING_META); lua_pushboolean(L, ucol_equal( *(UCollator**)lua_touserdata(L,1), icu4lua_trustustring(L,2), (int32_t)icu4lua_ustrlen(L,2), icu4lua_trustustring(L,3), (int32_t)icu4lua_ustrlen(L,3))); return 1; }
// Collator.startswith {{{ static PyObject * icu_Collator_startswith(icu_Collator *self, PyObject *args, PyObject *kwargs) { PyObject *a_, *b_; int32_t asz, bsz; int32_t actual_a, actual_b; UChar *a, *b; wchar_t *aw, *bw; UErrorCode status = U_ZERO_ERROR; int ans = 0; if (!PyArg_ParseTuple(args, "UU", &a_, &b_)) return NULL; asz = (int32_t)PyUnicode_GetSize(a_); bsz = (int32_t)PyUnicode_GetSize(b_); if (asz < bsz) Py_RETURN_FALSE; if (bsz == 0) Py_RETURN_TRUE; a = (UChar*)calloc(asz*4 + 2, sizeof(UChar)); b = (UChar*)calloc(bsz*4 + 2, sizeof(UChar)); aw = (wchar_t*)calloc(asz*4 + 2, sizeof(wchar_t)); bw = (wchar_t*)calloc(bsz*4 + 2, sizeof(wchar_t)); if (a == NULL || b == NULL || aw == NULL || bw == NULL) return PyErr_NoMemory(); actual_a = (int32_t)PyUnicode_AsWideChar((PyUnicodeObject*)a_, aw, asz*4+1); actual_b = (int32_t)PyUnicode_AsWideChar((PyUnicodeObject*)b_, bw, bsz*4+1); if (actual_a > -1 && actual_b > -1) { u_strFromWCS(a, asz*4 + 1, &actual_a, aw, -1, &status); u_strFromWCS(b, bsz*4 + 1, &actual_b, bw, -1, &status); if (U_SUCCESS(status) && ucol_equal(self->collator, a, actual_b, b, actual_b)) ans = 1; } free(a); free(b); free(aw); free(bw); if (ans) Py_RETURN_TRUE; Py_RETURN_FALSE; } // }}}