| 221 | } |
| 222 | |
| 223 | bool gjs_string_from_filename(JSContext* cx, const char* filename_string, |
| 224 | ssize_t n_bytes, JS::MutableHandleValue value_p) { |
| 225 | gsize written; // Do not use size_t, may be different width |
| 226 | Gjs::AutoError error; |
| 227 | |
| 228 | Gjs::AutoChar utf8_string{g_filename_to_utf8(filename_string, n_bytes, |
| 229 | nullptr, &written, &error)}; |
| 230 | if (error) { |
| 231 | Gjs::AutoChar escaped_char{g_strescape(filename_string, nullptr)}; |
| 232 | gjs_throw( |
| 233 | cx, |
| 234 | "Could not convert filename string to UTF-8 for string: %s. If " |
| 235 | "string is invalid UTF-8 and used for display purposes, try GLib " |
| 236 | "attribute standard::display-name. The reason is: %s. ", |
| 237 | escaped_char.get(), error->message); |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | return gjs_string_from_utf8_n(cx, utf8_string, written, value_p); |
| 242 | } |
| 243 | |
| 244 | /* Converts a JSString's array of Latin-1 chars to an array of a wider integer |
| 245 | * type, by what the compiler believes is the most efficient method possible */ |
no test coverage detected