aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index 7628a9fbf2e..611f92ea152 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -343,6 +343,10 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error;
343Lisp_Object Qemacs_mule, Qraw_text; 343Lisp_Object Qemacs_mule, Qraw_text;
344Lisp_Object Qutf_8_emacs; 344Lisp_Object Qutf_8_emacs;
345 345
346#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
347static Lisp_Object Qutf_16le;
348#endif
349
346/* Coding-systems are handed between Emacs Lisp programs and C internal 350/* Coding-systems are handed between Emacs Lisp programs and C internal
347 routines by the following three variables. */ 351 routines by the following three variables. */
348/* Coding system to be used to encode text for terminal display when 352/* Coding system to be used to encode text for terminal display when
@@ -7971,6 +7975,39 @@ preferred_coding_system (void)
7971 return CODING_ID_NAME (id); 7975 return CODING_ID_NAME (id);
7972} 7976}
7973 7977
7978#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
7979
7980Lisp_Object
7981from_unicode (Lisp_Object str)
7982{
7983 CHECK_STRING (str);
7984 if (!STRING_MULTIBYTE (str) &&
7985 SBYTES (str) & 1)
7986 {
7987 str = Fsubstring (str, make_number (0), make_number (-1));
7988 }
7989
7990 return code_convert_string_norecord (str, Qutf_16le, 0);
7991}
7992
7993wchar_t *
7994to_unicode (Lisp_Object str, Lisp_Object *buf)
7995{
7996 *buf = code_convert_string_norecord (str, Qutf_16le, 1);
7997 /* We need to make a another copy (in addition to the one made by
7998 code_convert_string_norecord) to ensure that the final string is
7999 _doubly_ zero terminated --- that is, that the string is
8000 terminated by two zero bytes and one utf-16le null character.
8001 Because strings are already terminated with a single zero byte,
8002 we just add one additional zero. */
8003 str = make_uninit_string (SBYTES (*buf) + 1);
8004 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
8005 SDATA (str) [SBYTES (*buf)] = '\0';
8006 *buf = str;
8007 return WCSDATA (*buf);
8008}
8009#endif /* WINDOWSNT || HAVE_NTGUI */
8010
7974 8011
7975#ifdef emacs 8012#ifdef emacs
7976/*** 8. Emacs Lisp library functions ***/ 8013/*** 8. Emacs Lisp library functions ***/
@@ -10284,6 +10321,11 @@ syms_of_coding (void)
10284 DEFSYM (Qutf_8, "utf-8"); 10321 DEFSYM (Qutf_8, "utf-8");
10285 DEFSYM (Qutf_8_emacs, "utf-8-emacs"); 10322 DEFSYM (Qutf_8_emacs, "utf-8-emacs");
10286 10323
10324#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
10325 /* No, not utf-16-le: that one has a BOM. */
10326 DEFSYM (Qutf_16le, "utf-16le");
10327#endif
10328
10287 DEFSYM (Qutf_16, "utf-16"); 10329 DEFSYM (Qutf_16, "utf-16");
10288 DEFSYM (Qbig, "big"); 10330 DEFSYM (Qbig, "big");
10289 DEFSYM (Qlittle, "little"); 10331 DEFSYM (Qlittle, "little");