diff src/mac.c @ 90260:0ca0d9181b5e

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-95 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 598-615) - Update from CVS - Remove lisp/toolbar directory - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 142-146) - Update from CVS
author Miles Bader <miles@gnu.org>
date Mon, 16 Jan 2006 06:59:21 +0000
parents 2d92f5c9d6ae f4ddfc71077d
children 7beb78bc1f8e
line wrap: on
line diff
--- a/src/mac.c	Wed Dec 28 07:22:57 2005 +0000
+++ b/src/mac.c	Mon Jan 16 06:59:21 2006 +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;