*
* Author:
* Patrik Torstensson (patrik.torstensson@labs2.com)
+ * Duncan Mak (duncan@ximian.com)
*
* (C) 2001 Ximian, Inc.
*/
#include <mono/metadata/loader.h>
#include <mono/metadata/object.h>
#include <mono/metadata/unicode.h>
+#include <mono/metadata/exception.h>
+
+/* Internal helper methods */
+
+static gboolean
+string_icall_is_in_array (MonoArray *chars, gint32 arraylength, gunichar2 chr);
+
+static gint32
+string_icall_cmp_char (gunichar2 c1, gunichar2 c2, gint16 mode);
+
+MonoString *
+ves_icall_System_String_ctor_charp (gpointer dummy, gunichar2 *value)
+{
+ gint32 i, length;
+ MonoDomain *domain;
+
+ domain = mono_domain_get ();
+
+ if (value == NULL)
+ length = 0;
+ else {
+ for (i = 0; *(value + i) != '\0'; i++);
+ length = i;
+ }
+
+ return mono_string_new_utf16 (domain, value, length);
+}
+
+MonoString *
+ves_icall_System_String_ctor_char_int (gpointer dummy, gunichar2 value, gint32 count)
+{
+ MonoDomain *domain;
+ MonoString *res;
+ gunichar2 *chars;
+ gint32 i;
+
+ domain = mono_domain_get ();
+ res = mono_string_new_size (domain, count);
+
+ chars = mono_string_chars (res);
+ for (i = 0; i < count; i++)
+ chars [i] = value;
+
+ return res;
+}
+
+MonoString *
+ves_icall_System_String_ctor_charp_int_int (gpointer dummy, gunichar2 *value, gint32 sindex, gint32 length)
+{
+ gunichar2 *begin;
+ MonoDomain * domain;
+
+ domain = mono_domain_get ();
+
+ if ((value == NULL) && (length != 0))
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
+
+ if ((sindex < 0) || (length < 0))
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
+
+ if (length == 0) { /* fixme: return String.Empty here */
+ g_warning ("string doesn't yet support empy strings in char* constructor");
+ g_assert_not_reached ();
+ }
+
+ begin = (gunichar2 *) (value + sindex);
+
+ return mono_string_new_utf16 (domain, begin, length);
+}
+
+MonoString *
+ves_icall_System_String_ctor_sbytep (gpointer dummy, gint8 *value)
+{
+ MonoDomain *domain;
+
+ domain = mono_domain_get ();
+
+ if (NULL == value) { /* fixme: return String.Empty here */
+ g_warning ("string doesn't yet support empy strings in char* constructor");
+ g_assert_not_reached ();
+ }
+
+ return mono_string_new (domain, (const char *) value);
+}
+
+MonoString *
+ves_icall_System_String_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gint32 sindex, gint32 length)
+{
+ char *begin;
+ MonoDomain *domain;
+
+ domain = mono_domain_get ();
+
+ if ((value == NULL) && (length != 0))
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
+
+ if ((sindex < 0) || (length < 0))
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
+
+ begin = (char *) (value + sindex);
+
+ return mono_string_new_len (domain, begin, length);
+}
+
+MonoString *
+ves_icall_System_String_ctor_chara (gpointer dummy, MonoArray *value)
+{
+ MonoDomain *domain;
+
+ MONO_CHECK_ARG_NULL (value);
+
+ domain = mono_domain_get ();
+
+ return mono_string_new_utf16 (domain, (gunichar2 *) mono_array_addr(value, gunichar2, 0), value->max_length);
+}
+
+MonoString *
+ves_icall_System_String_ctor_chara_int_int (gpointer dummy, MonoArray *value,
+ gint32 sindex, gint32 length)
+{
+ MonoDomain *domain;
+
+ MONO_CHECK_ARG_NULL (value);
+
+ domain = mono_domain_get ();
+
+ return mono_string_new_utf16 (domain, (gunichar2 *) mono_array_addr(value, gunichar2, sindex), length);
+}
+
+MonoString *
+ves_icall_System_String_ctor_encoding (gpointer dummy, gint8 *value, gint32 sindex,
+ gint32 length, MonoObject *enc)
+{
+ g_warning("string.ctor with encoding obj unimplemented");
+ g_assert_not_reached ();
+ return NULL;
+}
+
+MonoBoolean
+ves_icall_System_String_InternalEquals (MonoString *str1, MonoString *str2)
+{
+ gunichar2 *str1ptr;
+ gunichar2 *str2ptr;
+ gint32 str1len;
+
+ /* Length checking is done in C# */
+ str1len = mono_string_length(str1);
+
+ str1ptr = mono_string_chars(str1);
+ str2ptr = mono_string_chars(str2);
+
+ return (0 == memcmp(str1ptr, str2ptr, str1len * sizeof(gunichar2)));
+}
MonoString *
-mono_string_InternalJoin (MonoString *separator, MonoArray * value, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalJoin (MonoString *separator, MonoArray * value, gint32 sindex, gint32 count)
{
MonoString * ret;
gint32 length;
length += insertlen;
}
- ret = mono_string_InternalAllocateStr(length);
+ ret = mono_string_new_size( mono_domain_get (), length);
dest = mono_string_chars(ret);
destpos = 0;
}
MonoString *
-mono_string_InternalInsert (MonoString *me, gint32 sindex, MonoString *value)
+ves_icall_System_String_InternalInsert (MonoString *me, gint32 sindex, MonoString *value)
{
MonoString * ret;
gunichar2 *src;
gunichar2 *insertsrc;
gunichar2 *dest;
gint32 srclen;
+ gint32 insertlen;
src = mono_string_chars(me);
- srclen = mono_string_length(value);
+ srclen = mono_string_length(me);
- ret = mono_string_InternalAllocateStr(mono_string_length(me) + srclen - sindex);
+ insertsrc = mono_string_chars(value);
+ insertlen = mono_string_length(value);
+
+ ret = mono_string_new_size( mono_domain_get (), srclen + insertlen);
dest = mono_string_chars(ret);
memcpy(dest, src, sindex * sizeof(gunichar2));
- memcpy(dest + sindex, insertsrc, srclen * sizeof(gunichar2));
+ memcpy(dest + sindex, insertsrc, insertlen * sizeof(gunichar2));
+ memcpy(dest + sindex + insertlen, src + sindex, (srclen - sindex) * sizeof(gunichar2));
return ret;
}
MonoString *
-mono_string_InternalReplaceChar (MonoString *me, gunichar2 oldChar, gunichar2 newChar)
+ves_icall_System_String_InternalReplace_Char (MonoString *me, gunichar2 oldChar, gunichar2 newChar)
{
- g_warning("mono_string_InternalReplaceChar not impl");
- return mono_string_new_utf16(mono_domain_get(), mono_string_chars(me), mono_string_length(me));
+ MonoString *ret;
+ gunichar2 *src;
+ gunichar2 *dest;
+ gint32 i, srclen;
+
+ src = mono_string_chars(me);
+ srclen = mono_string_length(me);
+
+ ret = mono_string_new_size( mono_domain_get (), srclen);
+ dest = mono_string_chars(ret);
+
+ for (i = 0; i != srclen; i++) {
+ if (src[i] == oldChar)
+ dest[i] = newChar;
+ else
+ dest[i] = src[i];
+ }
+
+ return ret;
}
MonoString *
-mono_string_InternalReplaceStr (MonoString *me, MonoString *oldValue, MonoString *newValue)
+ves_icall_System_String_InternalReplace_Str (MonoString *me, MonoString *oldValue, MonoString *newValue)
{
- g_warning("mono_string_InternalReplaceStr not impl");
- return mono_string_new_utf16(mono_domain_get(), mono_string_chars(me), mono_string_length(me));
+ MonoString *ret;
+ gunichar2 *src;
+ gunichar2 *dest;
+ gunichar2 *oldstr;
+ gunichar2 *newstr;
+ gint32 i, destpos;
+ gint32 occurr;
+ gint32 newsize;
+ gint32 oldstrlen;
+ gint32 newstrlen;
+ gint32 srclen;
+
+ occurr = 0;
+ destpos = 0;
+
+ oldstr = mono_string_chars(oldValue);
+ oldstrlen = mono_string_length(oldValue);
+
+ if (NULL != newValue) {
+ newstr = mono_string_chars(newValue);
+ newstrlen = mono_string_length(newValue);
+ } else
+ newstrlen = 0;
+
+ src = mono_string_chars(me);
+ srclen = mono_string_length(me);
+
+ if (oldstrlen != newstrlen) {
+ for (i = 0; i <= srclen - oldstrlen; i++)
+ if (0 == memcmp(src + i, oldstr, oldstrlen * sizeof(gunichar2)))
+ occurr++;
+
+ newsize = srclen + ((newstrlen - oldstrlen) * occurr);
+ } else
+ newsize = srclen;
+
+ ret = mono_string_new_size( mono_domain_get (), newsize);
+ dest = mono_string_chars(ret);
+
+ i = 0;
+ while (i < srclen) {
+ if (0 == memcmp(src + i, oldstr, oldstrlen * sizeof(gunichar2))) {
+ if (newstrlen > 0) {
+ memcpy(dest + destpos, newstr, newstrlen * sizeof(gunichar2));
+ destpos += newstrlen;
+ }
+ i += oldstrlen;
+ } else {
+ dest[destpos] = src[i];
+ destpos++;
+ i++;
+ }
+ }
+
+ return ret;
}
MonoString *
-mono_string_InternalRemove (MonoString *me, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalRemove (MonoString *me, gint32 sindex, gint32 count)
{
MonoString * ret;
- gint32 count_bytes;
- gint32 index_bytes;
+ gint32 srclen;
gunichar2 *dest;
gunichar2 *src;
- ret = mono_string_InternalAllocateStr(mono_string_length(me) - count);
- index_bytes = sindex * sizeof(gunichar2);
- count_bytes = count * sizeof(gunichar2);
+ srclen = mono_string_length(me);
+ ret = mono_string_new_size( mono_domain_get (), srclen - count);
src = mono_string_chars(me);
dest = mono_string_chars(ret);
- memcpy(dest, src, index_bytes);
- memcpy(dest + sindex, src + sindex + count, index_bytes - count_bytes);
+ memcpy(dest, src, sindex * sizeof(gunichar2));
+ memcpy(dest + sindex, src + sindex + count, (srclen - count - sindex) * sizeof(gunichar2));
return ret;
}
void
-mono_string_InternalCopyTo (MonoString *me, gint32 sindex, MonoArray *dest, gint32 dindex, gint32 count)
+ves_icall_System_String_InternalCopyTo (MonoString *me, gint32 sindex, MonoArray *dest, gint32 dindex, gint32 count)
{
gunichar2 *destptr = (gunichar2 *) mono_array_addr(dest, gunichar2, dindex);
gunichar2 *src = mono_string_chars(me);
}
MonoArray *
-mono_string_InternalSplit (MonoString *me, MonoArray *separator, gint32 count)
+ves_icall_System_String_InternalSplit (MonoString *me, MonoArray *separator, gint32 count)
{
MonoString * tmpstr;
MonoArray * retarr;
gint32 tmpstrsize;
gunichar2 *tmpstrptr;
+ gunichar2 cmpchar;
+
src = mono_string_chars(me);
srcsize = mono_string_length(me);
arrsize = mono_array_length(separator);
+ cmpchar = mono_array_get(separator, gunichar2, 0);
+
splitsize = 0;
for (i = 0; i != srcsize && splitsize < count; i++) {
- if (mono_string_isinarray(separator, arrsize, src[i]))
+ if (string_icall_is_in_array(separator, arrsize, src[i]))
splitsize++;
}
lastpos = 0;
arrpos = 0;
- // if no split chars found return the string
+ /* if no split chars found return the string */
if (splitsize == 0) {
retarr = mono_array_new(mono_domain_get(), mono_defaults.string_class, 1);
- tmpstr = mono_string_InternalAllocateStr(srcsize);
+ tmpstr = mono_string_new_size( mono_domain_get (), srcsize);
tmpstrptr = mono_string_chars(tmpstr);
memcpy(tmpstrptr, src, srcsize * sizeof(gunichar2));
return retarr;
}
+ if (splitsize != count)
+ splitsize++;
+
retarr = mono_array_new(mono_domain_get(), mono_defaults.string_class, splitsize);
for (i = 0; i != srcsize && arrpos != count; i++) {
- if (mono_string_isinarray(separator, arrsize, src[i])) {
+ if (string_icall_is_in_array(separator, arrsize, src[i])) {
if (arrpos == count - 1)
tmpstrsize = srcsize - lastpos;
else
tmpstrsize = i - lastpos;
- tmpstr = mono_string_InternalAllocateStr(tmpstrsize);
+ tmpstr = mono_string_new_size( mono_domain_get (), tmpstrsize);
tmpstrptr = mono_string_chars(tmpstr);
memcpy(tmpstrptr, src + lastpos, tmpstrsize * sizeof(gunichar2));
}
}
+ if (arrpos < count) {
+ tmpstrsize = srcsize - lastpos;
+ tmpstr = mono_string_new_size( mono_domain_get (), tmpstrsize);
+ tmpstrptr = mono_string_chars(tmpstr);
+
+ memcpy(tmpstrptr, src + lastpos, tmpstrsize * sizeof(gunichar2));
+ mono_array_set(retarr, MonoString *, arrpos, tmpstr);
+ }
+
return retarr;
}
-gboolean
-mono_string_isinarray (MonoArray *chars, gint32 arraylength, gunichar2 chr)
+static gboolean
+string_icall_is_in_array (MonoArray *chars, gint32 arraylength, gunichar2 chr)
{
gunichar2 cmpchar;
gint32 arrpos;
for (arrpos = 0; arrpos != arraylength; arrpos++) {
cmpchar = mono_array_get(chars, gunichar2, arrpos);
- if (mono_string_cmp_char(cmpchar, chr, 1) == 0)
+ if (cmpchar == chr)
return TRUE;
}
}
MonoString *
-mono_string_InternalTrim (MonoString *me, MonoArray *chars, gint32 typ)
+ves_icall_System_String_InternalTrim (MonoString *me, MonoArray *chars, gint32 typ)
{
MonoString * ret;
gunichar2 *src, *dest;
if (0 == typ || 1 == typ) {
for (i = 0; i != srclen; i++) {
- if (mono_string_isinarray(chars, arrlen, src[i]))
+ if (string_icall_is_in_array(chars, arrlen, src[i]))
lenfirst++;
else
break;
}
if (0 == typ || 2 == typ) {
- for (i = srclen - lenfirst; i != 0; i--) {
- if (mono_string_isinarray(chars, arrlen, src[i]))
+ for (i = srclen - 1; i > lenfirst - 1; i--) {
+ if (string_icall_is_in_array(chars, arrlen, src[i]))
lenlast++;
else
break;
newlen = srclen - lenfirst - lenlast;
- ret = mono_string_InternalAllocateStr(newlen);
+ ret = mono_string_new_size( mono_domain_get (), newlen);
dest = mono_string_chars(ret);
memcpy(dest, src + lenfirst, newlen *sizeof(gunichar2));
}
gint32
-mono_string_InternalIndexOfChar (MonoString *me, gunichar2 value, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalIndexOf_Char (MonoString *me, gunichar2 value, gint32 sindex, gint32 count)
{
gint32 pos;
gunichar2 *src;
src = mono_string_chars(me);
for (pos = sindex; pos != count + sindex; pos++) {
- if (mono_string_cmp_char(src[pos], value ,1) == 0)
+ if ( src [pos] == value)
return pos;
}
}
gint32
-mono_string_InternalIndexOfStr (MonoString *me, MonoString *value, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalIndexOf_Str (MonoString *me, MonoString *value, gint32 sindex, gint32 count)
{
gint32 lencmpstr;
- gint32 pos;
+ gint32 pos, i;
gunichar2 *src;
gunichar2 *cmpstr;
src = mono_string_chars(me);
cmpstr = mono_string_chars(value);
- for (pos = sindex; pos != count + sindex; pos++) {
- if (0 == mono_string_InternalCompareStrN(me, pos, value, 0, lencmpstr, 0)) {
- return pos;
+ count -= lencmpstr;
+ for (pos = sindex; pos <= sindex + count; pos++) {
+ for (i = 0; src [pos + i] == cmpstr [i];) {
+ if (++i == lencmpstr)
+ return pos;
}
}
}
gint32
-mono_string_InternalIndexOfAny (MonoString *me, MonoArray *arr, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalIndexOfAny (MonoString *me, MonoArray *arr, gint32 sindex, gint32 count)
{
gint32 pos;
+ gint32 loop;
gint32 arraysize;
gunichar2 *src;
src = mono_string_chars(me);
for (pos = sindex; pos != count + sindex; pos++) {
- if (mono_string_isinarray(arr, arraysize, src[pos]))
- return pos;
+ for (loop = 0; loop != arraysize; loop++)
+ if ( src [pos] == mono_array_get(arr, gunichar2, loop) )
+ return pos;
}
return -1;
}
gint32
-mono_string_InternalLastIndexOfChar (MonoString *me, gunichar2 value, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalLastIndexOf_Char (MonoString *me, gunichar2 value, gint32 sindex, gint32 count)
{
gint32 pos;
gunichar2 *src;
src = mono_string_chars(me);
for (pos = sindex; pos > sindex - count; pos--) {
- if (mono_string_cmp_char(src[pos], value ,1) == 0)
+ if (src [pos] == value)
return pos;
}
}
gint32
-mono_string_InternalLastIndexOfStr (MonoString *me, MonoString *value, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalLastIndexOf_Str (MonoString *me, MonoString *value, gint32 sindex, gint32 count)
{
gint32 lencmpstr;
gint32 pos;
src = mono_string_chars(me);
cmpstr = mono_string_chars(value);
- for (pos = sindex; pos > sindex - count; pos -= lencmpstr) {
- if (0 == mono_string_InternalCompareStrN(me, pos, value, 0, lencmpstr, 0)) {
+ for (pos = sindex - lencmpstr + 1; pos > sindex - count; pos--) {
+ if (0 == memcmp(src + pos, cmpstr, lencmpstr * sizeof(gunichar2)))
return pos;
- }
}
return -1;
}
gint32
-mono_string_InternalLastIndexOfAny (MonoString *me, MonoArray *anyOf, gint32 sindex, gint32 count)
+ves_icall_System_String_InternalLastIndexOfAny (MonoString *me, MonoArray *anyOf, gint32 sindex, gint32 count)
{
gint32 pos;
+ gint32 loop;
gint32 arraysize;
gunichar2 *src;
src = mono_string_chars(me);
for (pos = sindex; pos > sindex - count; pos--) {
- if (mono_string_isinarray(anyOf, arraysize, src[pos]))
- return pos;
+ for (loop = 0; loop != arraysize; loop++)
+ if ( src [pos] == mono_array_get(anyOf, gunichar2, loop) )
+ return pos;
}
return -1;
}
MonoString *
-mono_string_InternalPad (MonoString *me, gint32 width, gint16 chr, MonoBoolean right)
+ves_icall_System_String_InternalPad (MonoString *me, gint32 width, gunichar2 chr, MonoBoolean right)
{
MonoString * ret;
gunichar2 *src;
srclen = mono_string_length(me);
src = mono_string_chars(me);
- ret = mono_string_InternalAllocateStr(width);
+ ret = mono_string_new_size( mono_domain_get (), width);
dest = mono_string_chars(ret);
fillcount = width - srclen;
return ret;
}
- // left fill
+ /* left fill */
for (i = 0; i != fillcount; i++)
dest[i] = chr;
}
MonoString *
-mono_string_InternalToLower (MonoString *me)
+ves_icall_System_String_InternalToLower (MonoString *me)
{
MonoString * ret;
gunichar2 *src;
}
MonoString *
-mono_string_InternalToUpper (MonoString *me)
+ves_icall_System_String_InternalToUpper (MonoString *me)
{
int i;
MonoString * ret;
}
MonoString *
-mono_string_InternalAllocateStr(gint32 length)
+ves_icall_System_String_InternalAllocateStr (gint32 length)
{
return mono_string_new_size(mono_domain_get (), length);
}
void
-mono_string_InternalStrcpyStr (MonoString *dest, gint32 destPos, MonoString *src)
+ves_icall_System_String_InternalStrcpy_Str (MonoString *dest, gint32 destPos, MonoString *src)
{
gunichar2 *srcptr;
gunichar2 *destptr;
- srcptr = mono_string_chars(src);
- destptr = mono_string_chars(dest);
+ srcptr = mono_string_chars (src);
+ destptr = mono_string_chars (dest);
memcpy(destptr + destPos, srcptr, mono_string_length(src) * sizeof(gunichar2));
}
void
-mono_string_InternalStrcpyStrN (MonoString *dest, gint32 destPos, MonoString *src, gint32 startPos, gint32 count)
+ves_icall_System_String_InternalStrcpy_StrN (MonoString *dest, gint32 destPos, MonoString *src, gint32 startPos, gint32 count)
{
gunichar2 *srcptr;
gunichar2 *destptr;
- srcptr = mono_string_chars(src);
- destptr = mono_string_chars(dest);
+ srcptr = mono_string_chars (src);
+ destptr = mono_string_chars (dest);
memcpy(destptr + destPos, srcptr + startPos, count * sizeof(gunichar2));
}
MonoString *
-mono_string_InternalIntern (MonoString *str)
+ves_icall_System_String_InternalIntern (MonoString *str)
{
return mono_string_intern(str);
}
MonoString *
-mono_string_InternalIsInterned (MonoString *str)
+ves_icall_System_String_InternalIsInterned (MonoString *str)
{
return mono_string_is_interned(str);
}
gint32
-mono_string_InternalCompareStrN (MonoString *s1, gint32 i1, MonoString *s2, gint32 i2, gint32 length, MonoBoolean inCase)
+ves_icall_System_String_InternalCompareStr_N (MonoString *s1, gint32 i1, MonoString *s2, gint32 i2, gint32 length, MonoBoolean inCase)
{
- // c translation of C# code.. :)
- //
+ /* c translation of C# code from old string.cs.. :) */
gint32 lenstr1;
gint32 lenstr2;
+ gint32 charcmp;
gunichar2 *str1;
gunichar2 *str2;
if (i1 + pos >= lenstr1 || i2 + pos >= lenstr2)
break;
- if (0 != mono_string_cmp_char(str1[i1 + pos], str2[i2 + pos], mode))
- break;
+ charcmp = string_icall_cmp_char(str1[i1 + pos], str2[i2 + pos], mode);
+ if (charcmp != 0)
+ return charcmp;
}
- // the lesser wins, so if we have looped until length we just need to check the last char
+ /* the lesser wins, so if we have looped until length we just need to check the last char */
if (pos == length) {
- return mono_string_cmp_char(str1[i1 + pos - 1], str2[i2 + pos - 1], mode);
+ return string_icall_cmp_char(str1[i1 + pos - 1], str2[i2 + pos - 1], mode);
}
- // Test if one the strings has been compared to the end
+ /* Test if one the strings has been compared to the end */
if (i1 + pos >= lenstr1) {
if (i2 + pos >= lenstr2)
return 0;
} else if (i2 + pos >= lenstr2)
return 1;
- // if not, check our last char only.. (can this happen?)
- return mono_string_cmp_char(str1[i1 + pos], str2[i2 + pos], mode);
+ /* if not, check our last char only.. (can this happen?) */
+ return string_icall_cmp_char(str1[i1 + pos], str2[i2 + pos], mode);
}
gint32
-mono_string_GetHashCode (MonoString *me)
+ves_icall_System_String_GetHashCode (MonoString *me)
{
int i, h = 0;
gunichar2 *data = mono_string_chars (me);
}
gunichar2
-mono_string_get_Chars (MonoString *me, gint32 idx)
+ves_icall_System_String_get_Chars (MonoString *me, gint32 idx)
{
return mono_string_chars(me)[idx];
}
1 = StringCompareModeCaseInsensitive
2 = StringCompareModeOrdinal
*/
-gint32
-mono_string_cmp_char (gunichar2 c1, gunichar2 c2, gint16 mode)
+static gint32
+string_icall_cmp_char (gunichar2 c1, gunichar2 c2, gint16 mode)
{
gint32 result;
+ GUnicodeType c1type, c2type;
+
+ c1type = g_unichar_type (c1);
+ c2type = g_unichar_type (c2);
switch (mode) {
case 0:
- // TODO: compare with culture info
- if (g_unichar_isupper(c1) && g_unichar_islower(c2))
+ /* TODO: compare with culture info */
+ if (c1type == G_UNICODE_UPPERCASE_LETTER && c2type == G_UNICODE_LOWERCASE_LETTER)
return 1;
- if (g_unichar_islower(c1) && g_unichar_isupper(c2))
+ if (c1type == G_UNICODE_LOWERCASE_LETTER && c2type == G_UNICODE_UPPERCASE_LETTER)
return -1;
result = (gint32) c1 - c2;
break;
case 1:
- result = (gint32) g_unichar_tolower(c1) - g_unichar_tolower(c2);
+ result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
+ (c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
break;
- // fix: compare ordinal
- case 2:
- result = (gint32) g_unichar_tolower(c1) - g_unichar_tolower(c2);
+ case 2:
+ result = (gint32) c1 - c2;
break;
}
- if (result < 0)
- return -1;
-
- if (result > 0)
- return 1;
-
- return 0;
+ return ((result < 0) ? -1 : (result > 0) ? 1 : 0);
}