37 #include "runtime_object.h" |
37 #include "runtime_object.h" |
38 #include "runtime_root.h" |
38 #include "runtime_root.h" |
39 #include "Platform.h" |
39 #include "Platform.h" |
40 #if USE(ICU_UNICODE) && !USE(SYMBIAN_UNICODE) |
40 #if USE(ICU_UNICODE) && !USE(SYMBIAN_UNICODE) |
41 #include <unicode/ucnv.h> |
41 #include <unicode/ucnv.h> |
|
42 #elif PLATFORM(SYMBIAN) |
|
43 #include <utf.h> |
42 #endif |
44 #endif |
43 |
45 |
44 namespace KJS { namespace Bindings { |
46 namespace KJS { namespace Bindings { |
45 |
47 |
46 // Requires free() of returned UTF16Chars. |
48 // Requires free() of returned UTF16Chars. |
86 |
88 |
87 for (unsigned i = 0; i < *UTF16Length; i++) |
89 for (unsigned i = 0; i < *UTF16Length; i++) |
88 (*UTF16Chars)[i] = UTF8Chars[i] & 0xFF; |
90 (*UTF16Chars)[i] = UTF8Chars[i] & 0xFF; |
89 } |
91 } |
90 #elif PLATFORM(SYMBIAN) |
92 #elif PLATFORM(SYMBIAN) |
91 // fixme: this needs to be a little bit more sophisticated |
|
92 if (UTF8Length == -1) |
93 if (UTF8Length == -1) |
93 UTF8Length = strlen(UTF8Chars); |
94 UTF8Length = strlen(UTF8Chars); |
94 |
95 |
95 *UTF16Length = UTF8Length; |
96 *UTF16Length = 0; |
96 |
97 *UTF16Chars = 0; |
97 *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length)); |
98 |
98 |
99 TPtrC8 buf8((TUint8*) UTF8Chars, UTF8Length); |
99 for (unsigned i = 0; i < *UTF16Length; i++) |
100 HBufC *hbuf16 = HBufC::New(UTF8Length+1); |
100 (*UTF16Chars)[i] = UTF8Chars[i] & 0xFF; |
101 if (!hbuf16) |
101 |
102 return; |
|
103 TPtr16 buf16 = hbuf16->Des(); |
|
104 CnvUtfConverter::ConvertToUnicodeFromUtf8(buf16, buf8); |
|
105 *UTF16Chars = new NPUTF16[buf16.Length()+1]; |
|
106 if (!(*UTF16Chars)) { |
|
107 delete hbuf16; |
|
108 return; |
|
109 } |
|
110 memcpy((void*)*UTF16Chars, (const char*)(buf16.Ptr()), buf16.Size()); |
|
111 *UTF16Length = buf16.Length(); |
|
112 (*UTF16Chars)[(*UTF16Length)] = 0; |
|
113 delete hbuf16; |
102 #else |
114 #else |
103 assert(!"Implement me!"); |
115 assert(!"Implement me!"); |
104 #endif |
116 #endif |
105 } |
117 } |
|
118 |
|
119 |
106 |
120 |
107 // Variant value must be released with NPReleaseVariantValue() |
121 // Variant value must be released with NPReleaseVariantValue() |
108 void convertValueToNPVariant(ExecState *exec, JSValue *value, NPVariant *result) |
122 void convertValueToNPVariant(ExecState *exec, JSValue *value, NPVariant *result) |
109 { |
123 { |
110 JSLock lock; |
124 JSLock lock; |