aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorPhilipp Stephani2019-04-28 12:28:27 +0200
committerPhilipp Stephani2019-04-28 12:28:27 +0200
commit75ee20364c5ed4c175b13debaa53a2ba14168999 (patch)
tree3bdff98355f169ddf8fe20cc7c60aa13ba682139 /src/coding.c
parentdbe81e16583adcae664871206694573209540286 (diff)
downloademacs-75ee20364c5ed4c175b13debaa53a2ba14168999.tar.gz
emacs-75ee20364c5ed4c175b13debaa53a2ba14168999.zip
Refactoring: move UTF-8 decoding functions into coding.h.
json_make_string and json_build_string are generally useful and not JSON-specific. Move them to coding.[ch]. * src/coding.h (build_utf8_string): Move from json.c. * src/coding.c (make_utf8_string): Move from json.c. * src/json.c (json_make_string, json_build_string): Move to coding.[ch]. Split out JSON-specific comment. (json_parse_error, Fjson_serialize, json_to_lisp): Fix callers. * src/emacs-module.c (module_make_function, module_make_string): Use new functions. (module_decode, module_decode_copy): Remove.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index 2c6b2c4d051..71f687a14e3 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6353,6 +6353,25 @@ utf8_string_p (Lisp_Object string)
6353 return check_utf_8 (&coding) != -1; 6353 return check_utf_8 (&coding) != -1;
6354} 6354}
6355 6355
6356Lisp_Object
6357make_utf8_string (const char *data, ptrdiff_t size)
6358{
6359 ptrdiff_t chars, bytes;
6360 parse_str_as_multibyte ((const unsigned char *) data, size, &chars, &bytes);
6361 /* If DATA is a valid UTF-8 string, we can convert it to a Lisp
6362 string directly. Otherwise, we need to decode it. */
6363 if (chars == size || bytes == size)
6364 return make_specified_string (data, chars, size, true);
6365 else
6366 {
6367 struct coding_system coding;
6368 setup_coding_system (Qutf_8_unix, &coding);
6369 coding.mode |= CODING_MODE_LAST_BLOCK;
6370 coding.source = (const unsigned char *) data;
6371 decode_coding_object (&coding, Qnil, 0, 0, size, size, Qt);
6372 return coding.dst_object;
6373 }
6374}
6356 6375
6357/* Detect how end-of-line of a text of length SRC_BYTES pointed by 6376/* Detect how end-of-line of a text of length SRC_BYTES pointed by
6358 SOURCE is encoded. If CATEGORY is one of 6377 SOURCE is encoded. If CATEGORY is one of