Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#unicode_sort_key ⇒ Object
string.unicode_sort_key -> string.
Instance Method Details
#unicode_sort_key ⇒ Object
string.unicode_sort_key -> string
Returns a string that will sort according to the Unicode collation algorithm.
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 |
# File 'ext/unicode_collation.c', line 14
static VALUE unicode_sort_key(VALUE string) {
char str[BUF_SIZE];
UChar ustr[BUF_SIZE];
int32_t len = 0;
int32_t ulen = 0;
UErrorCode status = U_ZERO_ERROR;
UCollator *col;
string = StringValue(string);
u_strFromUTF8(ustr, BUF_SIZE, &ulen, RSTRING_PTR(string), RSTRING_LEN(string), &status);
if (status == U_INVALID_CHAR_FOUND) {
return Qnil;
}
col = ucol_open("en_US", &status);
if (U_SUCCESS(status)) {
len = ucol_getSortKey(col, ustr, ulen, (uint8_t*)str, BUF_SIZE);
ucol_close(col);
}
if (len == 0) {
return Qnil;
}
return rb_str_new(str, len - 1);
}
|