diff options
| author | YAMAMOTO Mitsuharu | 2005-10-16 02:22:16 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2005-10-16 02:22:16 +0000 |
| commit | 5f8080a9e2d67e10fd38914ebcd93bddc648eafe (patch) | |
| tree | de1f3c40cbc2b7dfd0c74a22a21971528ce4a753 /src/mac.c | |
| parent | 02abe13c74d269e5892377330d7284b3138e9d6a (diff) | |
| download | emacs-5f8080a9e2d67e10fd38914ebcd93bddc648eafe.tar.gz emacs-5f8080a9e2d67e10fd38914ebcd93bddc648eafe.zip | |
[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.
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 40 |
1 files changed, 23 insertions, 17 deletions
| @@ -3411,7 +3411,7 @@ terminate_applescript() | |||
| 3411 | } | 3411 | } |
| 3412 | 3412 | ||
| 3413 | /* Convert a lisp string to the 4 byte character code. */ | 3413 | /* Convert a lisp string to the 4 byte character code. */ |
| 3414 | 3414 | ||
| 3415 | OSType | 3415 | OSType |
| 3416 | mac_get_code_from_arg(Lisp_Object arg, OSType defCode) | 3416 | mac_get_code_from_arg(Lisp_Object arg, OSType defCode) |
| 3417 | { | 3417 | { |
| @@ -3419,7 +3419,7 @@ mac_get_code_from_arg(Lisp_Object arg, OSType defCode) | |||
| 3419 | if (NILP(arg)) | 3419 | if (NILP(arg)) |
| 3420 | { | 3420 | { |
| 3421 | result = defCode; | 3421 | result = defCode; |
| 3422 | } | 3422 | } |
| 3423 | else | 3423 | else |
| 3424 | { | 3424 | { |
| 3425 | /* check type string */ | 3425 | /* check type string */ |
| @@ -3483,7 +3483,7 @@ DEFUN ("mac-get-file-creator", Fmac_get_file_creator, Smac_get_file_creator, 1, | |||
| 3483 | 3483 | ||
| 3484 | status = FSpGetFInfo (&fss, &finder_info); | 3484 | status = FSpGetFInfo (&fss, &finder_info); |
| 3485 | #endif | 3485 | #endif |
| 3486 | if (status == noErr) | 3486 | if (status == noErr) |
| 3487 | { | 3487 | { |
| 3488 | #ifdef MAC_OSX | 3488 | #ifdef MAC_OSX |
| 3489 | result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator); | 3489 | result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileCreator); |
| @@ -3538,7 +3538,7 @@ DEFUN ("mac-get-file-type", Fmac_get_file_type, Smac_get_file_type, 1, 1, 0, | |||
| 3538 | 3538 | ||
| 3539 | status = FSpGetFInfo (&fss, &finder_info); | 3539 | status = FSpGetFInfo (&fss, &finder_info); |
| 3540 | #endif | 3540 | #endif |
| 3541 | if (status == noErr) | 3541 | if (status == noErr) |
| 3542 | { | 3542 | { |
| 3543 | #ifdef MAC_OSX | 3543 | #ifdef MAC_OSX |
| 3544 | result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType); | 3544 | result = mac_get_object_from_code(((FileInfo*)&catalogInfo.finderInfo)->fileType); |
| @@ -3596,7 +3596,7 @@ assumed. Return non-nil if successful. */) | |||
| 3596 | 3596 | ||
| 3597 | status = FSpGetFInfo (&fss, &finder_info); | 3597 | status = FSpGetFInfo (&fss, &finder_info); |
| 3598 | #endif | 3598 | #endif |
| 3599 | if (status == noErr) | 3599 | if (status == noErr) |
| 3600 | { | 3600 | { |
| 3601 | #ifdef MAC_OSX | 3601 | #ifdef MAC_OSX |
| 3602 | ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode; | 3602 | ((FileInfo*)&catalogInfo.finderInfo)->fileCreator = cCode; |
| @@ -3656,7 +3656,7 @@ CODE must be a 4-character string. Return non-nil if successful. */) | |||
| 3656 | 3656 | ||
| 3657 | status = FSpGetFInfo (&fss, &finder_info); | 3657 | status = FSpGetFInfo (&fss, &finder_info); |
| 3658 | #endif | 3658 | #endif |
| 3659 | if (status == noErr) | 3659 | if (status == noErr) |
| 3660 | { | 3660 | { |
| 3661 | #ifdef MAC_OSX | 3661 | #ifdef MAC_OSX |
| 3662 | ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode; | 3662 | ((FileInfo*)&catalogInfo.finderInfo)->fileType = cCode; |
| @@ -3968,10 +3968,13 @@ get_cfstring_encoding_from_lisp (obj) | |||
| 3968 | CFStringRef iana_name; | 3968 | CFStringRef iana_name; |
| 3969 | CFStringEncoding encoding = kCFStringEncodingInvalidId; | 3969 | CFStringEncoding encoding = kCFStringEncodingInvalidId; |
| 3970 | 3970 | ||
| 3971 | if (NILP (obj)) | ||
| 3972 | return kCFStringEncodingUnicode; | ||
| 3973 | |||
| 3971 | if (INTEGERP (obj)) | 3974 | if (INTEGERP (obj)) |
| 3972 | return XINT (obj); | 3975 | return XINT (obj); |
| 3973 | 3976 | ||
| 3974 | if (SYMBOLP (obj) && !NILP (obj) && !NILP (Fcoding_system_p (obj))) | 3977 | if (SYMBOLP (obj) && !NILP (Fcoding_system_p (obj))) |
| 3975 | { | 3978 | { |
| 3976 | Lisp_Object coding_spec, plist; | 3979 | Lisp_Object coding_spec, plist; |
| 3977 | 3980 | ||
| @@ -4115,7 +4118,8 @@ DEFUN ("mac-code-convert-string", Fmac_code_convert_string, Smac_code_convert_st | |||
| 4115 | doc: /* Convert STRING from SOURCE encoding to TARGET encoding. | 4118 | doc: /* Convert STRING from SOURCE encoding to TARGET encoding. |
| 4116 | The conversion is performed using the converter provided by the system. | 4119 | The conversion is performed using the converter provided by the system. |
| 4117 | Each encoding is specified by either a coding system symbol, a mime | 4120 | Each encoding is specified by either a coding system symbol, a mime |
| 4118 | charset string, or an integer as a CFStringEncoding value. | 4121 | charset string, or an integer as a CFStringEncoding value. Nil for |
| 4122 | encoding means UTF-16 in native byte order, no byte order marker. | ||
| 4119 | On Mac OS X 10.2 and later, you can do Unicode Normalization by | 4123 | On Mac OS X 10.2 and later, you can do Unicode Normalization by |
| 4120 | specifying the optional argument NORMALIZATION-FORM with a symbol NFD, | 4124 | specifying the optional argument NORMALIZATION-FORM with a symbol NFD, |
| 4121 | NFKD, NFC, NFKC, HFS+D, or HFS+C. | 4125 | NFKD, NFC, NFKC, HFS+D, or HFS+C. |
| @@ -4126,7 +4130,6 @@ On successful conversion, return the result string, else return nil. */) | |||
| 4126 | Lisp_Object result = Qnil; | 4130 | Lisp_Object result = Qnil; |
| 4127 | CFStringEncoding src_encoding, tgt_encoding; | 4131 | CFStringEncoding src_encoding, tgt_encoding; |
| 4128 | CFStringRef str = NULL; | 4132 | CFStringRef str = NULL; |
| 4129 | CFDataRef data = NULL; | ||
| 4130 | 4133 | ||
| 4131 | CHECK_STRING (string); | 4134 | CHECK_STRING (string); |
| 4132 | if (!INTEGERP (source) && !STRINGP (source)) | 4135 | if (!INTEGERP (source) && !STRINGP (source)) |
| @@ -4148,7 +4151,7 @@ On successful conversion, return the result string, else return nil. */) | |||
| 4148 | if (src_encoding != kCFStringEncodingInvalidId | 4151 | if (src_encoding != kCFStringEncodingInvalidId |
| 4149 | && tgt_encoding != kCFStringEncodingInvalidId) | 4152 | && tgt_encoding != kCFStringEncodingInvalidId) |
| 4150 | str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string), | 4153 | str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string), |
| 4151 | src_encoding, true); | 4154 | src_encoding, !NILP (source)); |
| 4152 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | 4155 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 |
| 4153 | if (str) | 4156 | if (str) |
| 4154 | { | 4157 | { |
| @@ -4160,15 +4163,18 @@ On successful conversion, return the result string, else return nil. */) | |||
| 4160 | #endif | 4163 | #endif |
| 4161 | if (str) | 4164 | if (str) |
| 4162 | { | 4165 | { |
| 4163 | data = CFStringCreateExternalRepresentation (NULL, str, | 4166 | CFIndex str_len, buf_len; |
| 4164 | tgt_encoding, '\0'); | 4167 | |
| 4168 | str_len = CFStringGetLength (str); | ||
| 4169 | if (CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0, | ||
| 4170 | !NILP (target), NULL, 0, &buf_len) == str_len) | ||
| 4171 | { | ||
| 4172 | result = make_uninit_string (buf_len); | ||
| 4173 | CFStringGetBytes (str, CFRangeMake (0, str_len), tgt_encoding, 0, | ||
| 4174 | !NILP (target), SDATA (result), buf_len, NULL); | ||
| 4175 | } | ||
| 4165 | CFRelease (str); | 4176 | CFRelease (str); |
| 4166 | } | 4177 | } |
| 4167 | if (data) | ||
| 4168 | { | ||
| 4169 | result = cfdata_to_lisp (data); | ||
| 4170 | CFRelease (data); | ||
| 4171 | } | ||
| 4172 | 4178 | ||
| 4173 | UNBLOCK_INPUT; | 4179 | UNBLOCK_INPUT; |
| 4174 | 4180 | ||