return check_utf_8 (&coding) != -1;
}
+Lisp_Object
+make_utf8_string (const char *data, ptrdiff_t size)
+{
+ ptrdiff_t chars, bytes;
+ parse_str_as_multibyte ((const unsigned char *) data, size, &chars, &bytes);
+ /* If DATA is a valid UTF-8 string, we can convert it to a Lisp
+ string directly. Otherwise, we need to decode it. */
+ if (chars == size || bytes == size)
+ return make_specified_string (data, chars, size, true);
+ else
+ {
+ struct coding_system coding;
+ setup_coding_system (Qutf_8_unix, &coding);
+ coding.mode |= CODING_MODE_LAST_BLOCK;
+ coding.source = (const unsigned char *) data;
+ decode_coding_object (&coding, Qnil, 0, 0, size, size, Qt);
+ return coding.dst_object;
+ }
+}
/* Detect how end-of-line of a text of length SRC_BYTES pointed by
SOURCE is encoded. If CATEGORY is one of
extern bool raw_text_coding_system_p (struct coding_system *);
extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
extern Lisp_Object complement_process_encoding_system (Lisp_Object);
+extern Lisp_Object make_utf8_string (const char *, ptrdiff_t);
extern void decode_coding_gap (struct coding_system *,
ptrdiff_t, ptrdiff_t);
return 0x10000 + (low - 0xDC00) + ((high - 0xD800) * 0x400);
}
+/* Create a multibyte Lisp string from the NUL-terminated UTF-8 string
+ beginning at DATA. If the string is not a valid UTF-8 string, an
+ unspecified string is returned. */
+
+INLINE Lisp_Object
+build_utf8_string (const char *data)
+{
+ return make_utf8_string (data, strlen (data));
+}
+
+
extern Lisp_Object preferred_coding_system (void);
/* Coding system to be used to encode text for terminal display when
static bool value_storage_contains_p (const struct emacs_value_storage *,
emacs_value, ptrdiff_t *);
static Lisp_Object module_encode (Lisp_Object);
-static Lisp_Object module_decode (Lisp_Object);
-static Lisp_Object module_decode_copy (Lisp_Object);
static bool module_assertions = false;
\f
function->data = data;
if (documentation)
- {
- AUTO_STRING (unibyte_doc, documentation);
- function->documentation = module_decode_copy (unibyte_doc);
- }
+ function->documentation = build_utf8_string (documentation);
Lisp_Object result;
XSET_MODULE_FUNCTION (result, function);
MODULE_FUNCTION_BEGIN (NULL);
if (! (0 <= length && length <= STRING_BYTES_BOUND))
overflow_error ();
- Lisp_Object lstr = make_unibyte_string (str, length);
- return lisp_to_value (env, module_decode (lstr));
+ Lisp_Object lstr = make_utf8_string (str, length);
+ return lisp_to_value (env, lstr);
}
static emacs_value
return code_convert_string (string, Qutf_8_unix, Qt, true, true, true);
}
-static Lisp_Object
-module_decode (Lisp_Object string)
-{
- return code_convert_string (string, Qutf_8_unix, Qt, false, true, true);
-}
-
-static Lisp_Object
-module_decode_copy (Lisp_Object string)
-{
- return code_convert_string (string, Qutf_8_unix, Qt, false, false, true);
-}
-
\f
/* Value conversion. */
#endif
-/* Create a multibyte Lisp string from the UTF-8 string in
- [DATA, DATA + SIZE). If the range [DATA, DATA + SIZE) does not
- contain a valid UTF-8 string, the returned string will include raw
- bytes.
- Note that all callers below either pass only value UTF-8 strings or
- use this function for formatting error messages; in the latter case
- correctness isn't critical. */
-
-static Lisp_Object
-json_make_string (const char *data, ptrdiff_t size)
-{
- ptrdiff_t chars, bytes;
- parse_str_as_multibyte ((const unsigned char *) data, size, &chars, &bytes);
- /* If DATA is a valid UTF-8 string, we can convert it to a Lisp
- string directly. Otherwise, we need to decode it. */
- if (chars == size || bytes == size)
- return make_specified_string (data, chars, size, true);
- else
- {
- struct coding_system coding;
- setup_coding_system (Qutf_8_unix, &coding);
- coding.mode |= CODING_MODE_LAST_BLOCK;
- coding.source = (const unsigned char *) data;
- decode_coding_object (&coding, Qnil, 0, 0, size, size, Qt);
- return coding.dst_object;
- }
-}
-
-/* Create a multibyte Lisp string from the NUL-terminated UTF-8
- string beginning at DATA. If the string is not a valid UTF-8
- string, an unspecified string is returned. Note that all callers
- below either pass only value UTF-8 strings or use this function for
+/* Note that all callers of make_utf8_string and build_utf8_string
+ below either pass only value UTF-8 strings or use the functionf for
formatting error messages; in the latter case correctness isn't
critical. */
-static Lisp_Object
-json_build_string (const char *data)
-{
- return json_make_string (data, strlen (data));
-}
-
/* Return a unibyte string containing the sequence of UTF-8 encoding
units of the UTF-8 representation of STRING. If STRING does not
represent a sequence of Unicode scalar values, return a string with
symbol = Qjson_parse_error;
#endif
xsignal (symbol,
- list5 (json_build_string (error->text),
- json_build_string (error->source), INT_TO_INTEGER (error->line),
+ list5 (build_utf8_string (error->text),
+ build_utf8_string (error->source), INT_TO_INTEGER (error->line),
INT_TO_INTEGER (error->column), INT_TO_INTEGER (error->position)));
}
json_out_of_memory ();
record_unwind_protect_ptr (json_free, string);
- return unbind_to (count, json_build_string (string));
+ return unbind_to (count, build_utf8_string (string));
}
struct json_buffer_and_size
case JSON_REAL:
return make_float (json_real_value (json));
case JSON_STRING:
- return json_make_string (json_string_value (json),
+ return make_utf8_string (json_string_value (json),
json_string_length (json));
case JSON_ARRAY:
{
json_t *value;
json_object_foreach (json, key_str, value)
{
- Lisp_Object key = json_build_string (key_str);
+ Lisp_Object key = build_utf8_string (key_str);
EMACS_UINT hash;
ptrdiff_t i = hash_lookup (h, key, &hash);
/* Keys in JSON objects are unique, so the key can't
json_t *value;
json_object_foreach (json, key_str, value)
{
- Lisp_Object key = Fintern (json_build_string (key_str), Qnil);
+ Lisp_Object key = Fintern (build_utf8_string (key_str), Qnil);
result
= Fcons (Fcons (key, json_to_lisp (value, conf)),
result);