* gjs_lossy_string_from_utf8_n: * @cx: the current #JSContext * @utf8_string: an array of UTF-8 characters to decode * @len: length of @utf8_string * * Provides the same conversion behavior as gjs_lossy_string_from_utf8 * with a fixed length. See gjs_lossy_string_from_utf8(). * * Returns: The decoded string. */
| 170 | * Returns: The decoded string. |
| 171 | */ |
| 172 | JSString* gjs_lossy_string_from_utf8_n(JSContext* cx, const char* utf8_string, |
| 173 | size_t len) { |
| 174 | JS::UTF8Chars chars(utf8_string, len); |
| 175 | size_t outlen; |
| 176 | JS::UniqueTwoByteChars twobyte_chars( |
| 177 | JS::LossyUTF8CharsToNewTwoByteCharsZ(cx, chars, &outlen, |
| 178 | js::MallocArena) |
| 179 | .get()); |
| 180 | if (!twobyte_chars) |
| 181 | return nullptr; |
| 182 | |
| 183 | return JS_NewUCStringCopyN(cx, twobyte_chars.get(), outlen); |
| 184 | } |
| 185 | |
| 186 | bool gjs_string_from_utf8(JSContext* cx, const char* utf8_string, |
| 187 | JS::MutableHandleValue value_p) { |
no test coverage detected