#include <signal.h>
#include <string.h>
#include <mono/metadata/string-icalls.h>
+#include <mono/metadata/class-internals.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/loader.h>
#include <mono/metadata/object.h>
#include <mono/metadata/unicode.h>
#include <mono/metadata/exception.h>
+#include <mono/metadata/debug-helpers.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, gint32 mode);
-
MonoString *
ves_icall_System_String_ctor_charp (gpointer dummy, gunichar2 *value)
{
gint32 length, MonoObject *enc)
{
MONO_ARCH_SAVE_REGS;
+ MonoArray *arr;
+ MonoString *s;
+ MonoObject *exc;
+ MonoDomain *domain = mono_domain_get ();
+ MonoMethod *get_string;
+ gpointer args [1];
+
+ if ((value == NULL) || (length == 0))
+ return mono_string_new_size (mono_domain_get (), 0);
+ if (enc == NULL)
+ mono_raise_exception (mono_get_exception_argument_null ("enc"));
+ if (sindex < 0)
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("startIndex"));
+ if (length < 0)
+ mono_raise_exception (mono_get_exception_argument_out_of_range ("length"));
+
+ arr = mono_array_new (domain, mono_defaults.byte_class, length);
+ memcpy (mono_array_addr (arr, guint8*, 0), value + sindex, length);
- g_warning("string.ctor with encoding obj unimplemented");
- g_assert_not_reached ();
- return NULL;
+ get_string = mono_find_method_by_name (enc->vtable->klass, "GetString", 1);
+ args [0] = arr;
+ s = (MonoString*)mono_runtime_invoke (get_string, enc, args, &exc);
+ if (!s || exc)
+ mono_raise_exception (mono_get_exception_argument ("", "Unable to decode the array into a valid string."));
+
+ return s;
}
MonoString *
/* if no split chars found return the string */
if (splitsize == 0) {
- retarr = mono_array_new(mono_domain_get(), mono_defaults.string_class, 1);
+ retarr = mono_array_new(mono_domain_get(), mono_get_string_class (), 1);
mono_array_set(retarr, MonoString *, 0, me);
return retarr;
if (splitsize != count)
splitsize++;
- retarr = mono_array_new(mono_domain_get(), mono_defaults.string_class, splitsize);
+ retarr = mono_array_new(mono_domain_get(), mono_get_string_class (), splitsize);
for (i = 0; i != srcsize && arrpos != count; i++) {
if (string_icall_is_in_array(separator, arrsize, src[i])) {
if (arrpos == count - 1)
memcpy (dest, src, sizeof (gunichar2) * count);
}
-
-/*
- * @mode:
- * 0 = StringCompareModeDirect
- * 1 = StringCompareModeCaseInsensitive
- * 2 = StringCompareModeOrdinal
- */
-static gint32
-string_icall_cmp_char (gunichar2 c1, gunichar2 c2, gint32 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 (c1type == G_UNICODE_UPPERCASE_LETTER && c2type == G_UNICODE_LOWERCASE_LETTER)
- return 1;
-
- if (c1type == G_UNICODE_LOWERCASE_LETTER && c2type == G_UNICODE_UPPERCASE_LETTER)
- return -1;
-
- result = (gint32) c1 - c2;
- break;
- case 1:
- result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
- (c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
- break;
- case 2:
- // Rotor/ms return the full value just not -1 and 1
- return (gint32) c1 - c2; break;
- }
-
- return ((result < 0) ? -1 : (result > 0) ? 1 : 0);
-}