Changeset 14698


Ignore:
Timestamp:
Mar 25, 2011, 9:38:32 PM (8 years ago)
Author:
gb
Message:

In LISP-STRING-FROM-NSSTRING, allow the NSString to contain embedded
#\NUL characters.

Fixes ticket:838.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/objc-bridge/objc-support.lisp

    r14462 r14698  
    318318
    319319(defun lisp-string-from-nsstring (nsstring)
    320   ;; The value returned by #/UTF8String is autoreleased.
    321   (%get-utf-8-cstring (#/UTF8String nsstring)))
     320  (with-autorelease-pool
     321      ;; It's not clear that it's even possible to lose information
     322      ;; when converting to UTF-8, but allow lossage to occur, just in
     323      ;; case.
     324      (let* ((data (#/dataUsingEncoding:allowLossyConversion:
     325                    nsstring #$NSUTF8StringEncoding t))
     326             (len (#/length data)))
     327        (if (= len 0)
     328          ""
     329          (let* ((bytes (#/bytes data))
     330                 (nchars (utf-8-length-of-memory-encoding bytes len 0))
     331                 (string (make-string nchars)))
     332            (utf-8-memory-decode bytes len 0 string)
     333            string)))))
     334
    322335
    323336
Note: See TracChangeset for help on using the changeset viewer.