diff options
author | Eli Zaretskii <eliz@gnu.org> | 2019-04-28 17:14:39 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2019-04-28 17:14:39 +0300 |
commit | 6b6a6f06b4df9d76ad50294d0b6e88978ffb27d0 (patch) | |
tree | eb6d3c33d20a57caa9cb2430029249b88b1752fa /src | |
parent | 75ee20364c5ed4c175b13debaa53a2ba14168999 (diff) | |
download | emacs-6b6a6f06b4df9d76ad50294d0b6e88978ffb27d0.tar.gz |
Fix names of functions in last commit
* src/coding.h (build_string_from_utf8): Rename from
build_utf8_string. All callers changed.
* src/coding.c (make_string_from_utf8): Rename from
make_utf8_string. All callers changed.
Diffstat (limited to 'src')
-rw-r--r-- | src/coding.c | 18 | ||||
-rw-r--r-- | src/coding.h | 11 | ||||
-rw-r--r-- | src/emacs-module.c | 4 | ||||
-rw-r--r-- | src/json.c | 21 |
4 files changed, 30 insertions, 24 deletions
diff --git a/src/coding.c b/src/coding.c index 71f687a14e3..9cba6494a8d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6353,22 +6353,26 @@ utf8_string_p (Lisp_Object string) return check_utf_8 (&coding) != -1; } +/* Like make_string, but always returns a multibyte Lisp string, and + avoids decoding if TEXT encoded in UTF-8. */ + Lisp_Object -make_utf8_string (const char *data, ptrdiff_t size) +make_string_from_utf8 (const char *text, ptrdiff_t nbytes) { 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 + parse_str_as_multibyte ((const unsigned char *) text, nbytes, + &chars, &bytes); + /* If TEXT 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); + if (chars == nbytes || bytes == nbytes) + return make_specified_string (text, chars, nbytes, 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); + coding.source = (const unsigned char *) text; + decode_coding_object (&coding, Qnil, 0, 0, nbytes, nbytes, Qt); return coding.dst_object; } } diff --git a/src/coding.h b/src/coding.h index 773df9abb90..619ca29c8e4 100644 --- a/src/coding.h +++ b/src/coding.h @@ -695,7 +695,7 @@ extern Lisp_Object raw_text_coding_system (Lisp_Object); 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 Lisp_Object make_string_from_utf8 (const char *, ptrdiff_t); extern void decode_coding_gap (struct coding_system *, ptrdiff_t, ptrdiff_t); @@ -763,14 +763,13 @@ surrogates_to_codepoint (int low, int high) 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. */ +/* Like build_string, but always returns a multibyte string, and is + optimized for speed when STR is a UTF-8 encoded text string. */ INLINE Lisp_Object -build_utf8_string (const char *data) +build_string_from_utf8 (const char *str) { - return make_utf8_string (data, strlen (data)); + return make_string_from_utf8 (str, strlen (str)); } diff --git a/src/emacs-module.c b/src/emacs-module.c index b9050942559..685bdb8bb4c 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -530,7 +530,7 @@ module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity, function->data = data; if (documentation) - function->documentation = build_utf8_string (documentation); + function->documentation = build_string_from_utf8 (documentation); Lisp_Object result; XSET_MODULE_FUNCTION (result, function); @@ -663,7 +663,7 @@ module_make_string (emacs_env *env, const char *str, ptrdiff_t length) MODULE_FUNCTION_BEGIN (NULL); if (! (0 <= length && length <= STRING_BYTES_BOUND)) overflow_error (); - Lisp_Object lstr = make_utf8_string (str, length); + Lisp_Object lstr = make_string_from_utf8 (str, length); return lisp_to_value (env, lstr); } diff --git a/src/json.c b/src/json.c index cc98914423b..e2a4424463b 100644 --- a/src/json.c +++ b/src/json.c @@ -215,7 +215,7 @@ json_has_suffix (const char *string, const char *suffix) #endif -/* Note that all callers of make_utf8_string and build_utf8_string +/* Note that all callers of make_string_from_utf8 and build_string_from_utf8 below either pass only value UTF-8 strings or use the functionf for formatting error messages; in the latter case correctness isn't critical. */ @@ -267,9 +267,11 @@ json_parse_error (const json_error_t *error) symbol = Qjson_parse_error; #endif xsignal (symbol, - 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))); + list5 (build_string_from_utf8 (error->text), + build_string_from_utf8 (error->source), + INT_TO_INTEGER (error->line), + INT_TO_INTEGER (error->column), + INT_TO_INTEGER (error->position))); } static void @@ -612,7 +614,7 @@ usage: (json-serialize OBJECT &rest ARGS) */) json_out_of_memory (); record_unwind_protect_ptr (json_free, string); - return unbind_to (count, build_utf8_string (string)); + return unbind_to (count, build_string_from_utf8 (string)); } struct json_buffer_and_size @@ -819,8 +821,8 @@ json_to_lisp (json_t *json, struct json_configuration *conf) case JSON_REAL: return make_float (json_real_value (json)); case JSON_STRING: - return make_utf8_string (json_string_value (json), - json_string_length (json)); + return make_string_from_utf8 (json_string_value (json), + json_string_length (json)); case JSON_ARRAY: { if (++lisp_eval_depth > max_lisp_eval_depth) @@ -879,7 +881,7 @@ json_to_lisp (json_t *json, struct json_configuration *conf) json_t *value; json_object_foreach (json, key_str, value) { - Lisp_Object key = build_utf8_string (key_str); + Lisp_Object key = build_string_from_utf8 (key_str); EMACS_UINT hash; ptrdiff_t i = hash_lookup (h, key, &hash); /* Keys in JSON objects are unique, so the key can't @@ -896,7 +898,8 @@ json_to_lisp (json_t *json, struct json_configuration *conf) json_t *value; json_object_foreach (json, key_str, value) { - Lisp_Object key = Fintern (build_utf8_string (key_str), Qnil); + Lisp_Object key + = Fintern (build_string_from_utf8 (key_str), Qnil); result = Fcons (Fcons (key, json_to_lisp (value, conf)), result); |