changeset 66108:f4ddfc71077d

[TARGET_API_MAC_CARBON] (get_cfstring_encoding_from_lisp): Allow nil as argument. [TARGET_API_MAC_CARBON] (Fmac_code_convert_string): Regard nil for encoding arguments as UTF-16 in native byte order, no BOM.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sun, 16 Oct 2005 02:22:16 +0000
parents bfc846e38bba
children 04660708774d
files src/mac.c
diffstat 1 files changed, 23 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/mac.c	Sun Oct 16 02:21:16 2005 +0000
+++ b/src/mac.c	Sun Oct 16 02:22:16 2005 +0000
@@ -3411,7 +3411,7 @@
 }
 
 /* Convert a lisp string to the 4 byte character code.  */
- 
+
 OSType
 mac_get_code_from_arg(Lisp_Object arg, OSType defCode)
 {
@@ -3419,7 +3419,7 @@
   if (NILP(arg))
     {
       result = defCode;
-    } 
+    }
   else
     {
       /* check type string */
@@ -3483,7 +3483,7 @@
 
       status = FSpGetFInfo (&fss, &finder_info);
 #endif
-      if (status == noErr) 
+      if (status == noErr)
 	{
 #ifdef MAC_OSX
 	  result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator);
@@ -3538,7 +3538,7 @@
 
       status = FSpGetFInfo (&fss, &finder_info);
 #endif
-      if (status == noErr) 
+      if (status == noErr)
 	{
 #ifdef MAC_OSX
 	  result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType);
@@ -3596,7 +3596,7 @@
 
       status = FSpGetFInfo (&fss, &finder_info);
 #endif
-      if (status == noErr) 
+      if (status == noErr)
 	{
 #ifdef MAC_OSX
 	((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode;
@@ -3656,7 +3656,7 @@
 
       status = FSpGetFInfo (&fss, &finder_info);
 #endif
-      if (status == noErr) 
+      if (status == noErr)
 	{
 #ifdef MAC_OSX
 	((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode;
@@ -3968,10 +3968,13 @@
   CFStringRef iana_name;
   CFStringEncoding encoding = kCFStringEncodingInvalidId;
 
+  if (NILP (obj))
+    return kCFStringEncodingUnicode;
+
   if (INTEGERP (obj))
     return XINT (obj);
 
-  if (SYMBOLP (obj) && !NILP (obj) && !NILP (Fcoding_system_p (obj)))
+  if (SYMBOLP (obj) && !NILP (Fcoding_system_p (obj)))
     {
       Lisp_Object coding_spec, plist;
 
@@ -4115,7 +4118,8 @@
        doc: /* Convert STRING from SOURCE encoding to TARGET encoding.
 The conversion is performed using the converter provided by the system.
 Each encoding is specified by either a coding system symbol, a mime
-charset string, or an integer as a CFStringEncoding value.
+charset string, or an integer as a CFStringEncoding value.  Nil for
+encoding means UTF-16 in native byte order, no byte order marker.
 On Mac OS X 10.2 and later, you can do Unicode Normalization by
 specifying the optional argument NORMALIZATION-FORM with a symbol NFD,
 NFKD, NFC, NFKC, HFS+D, or HFS+C.
@@ -4126,7 +4130,6 @@
   Lisp_Object result = Qnil;
   CFStringEncoding src_encoding, tgt_encoding;
   CFStringRef str = NULL;
-  CFDataRef data = NULL;
 
   CHECK_STRING (string);
   if (!INTEGERP (source) && !STRINGP (source))
@@ -4148,7 +4151,7 @@
   if (src_encoding != kCFStringEncodingInvalidId
       && tgt_encoding != kCFStringEncodingInvalidId)
     str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string),
-				   src_encoding, true);
+				   src_encoding, !NILP (source));
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
   if (str)
     {
@@ -4160,15 +4163,18 @@
 #endif
   if (str)
     {
-      data = CFStringCreateExternalRepresentation (NULL, str,
-						   tgt_encoding, '\0');
+      CFIndex str_len, buf_len;
+
+      str_len = CFStringGetLength (str);
+      if (CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0,
+			    !NILP (target), NULL, 0, &buf_len) == str_len)
+	{
+	  result = make_uninit_string (buf_len);
+	  CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0,
+			    !NILP (target), SDATA (result), buf_len, NULL);
+	}
       CFRelease (str);
     }
-  if (data)
-    {
-      result = cfdata_to_lisp (data);
-      CFRelease (data);
-    }
 
   UNBLOCK_INPUT;