Changeset 6585


Ignore:
Timestamp:
May 20, 2007, 9:10:26 AM (18 years ago)
Author:
Gary Byers
Message:

Lose %MAKE-NSSTRING-FROM-UTF32-STRING. Add %MAKE-NSSTRING-FROM-UTF8-C-STRING.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/examples/objc-support.lisp

    r6566 r6585  
    153153
    154154
    155 (defun %make-nsstring-from-c-string (s)
    156   (#/initWithCString: (#/alloc ns:ns-string) s))
    157 
    158 (defun %make-nsstring-from-utf32-string (s nbytes)
    159   (#/initWithBytes:length:encoding: (#/alloc ns:ns-string)
    160                                     s
    161                                     nbytes
    162                                     #+big-endian-target #x98000100
    163                                     #+little-endian-target #x9c000100))
     155(defun %make-nsstring-from-utf8-c-string (s)
     156  (#/initWithUTF8String: (#/alloc ns:ns-string) s))
     157
    164158
    165159(defun retain-objc-instance (instance)
     
    173167  (#/release p))
    174168
    175 ;;; This can fail if the nsstring contains non-8-bit characters.
     169
     170#-ascii-only
     171(defun lisp-string-from-nsstring (nsstring)
     172  ;; The NSData object created here is autoreleased.
     173  (let* ((data (#/dataUsingEncoding:allowLossyConversion:
     174                nsstring
     175                #+little-endian-target #x9c000100
     176                #+big-endian-target #x98000100
     177                nil)))
     178    (unless (%null-ptr-p data)
     179      (let* ((nbytes (#/length data))
     180             (string (make-string (ash nbytes -2))))
     181        ;; BLT the 4-byte code-points from the NSData object
     182        ;; to the string, return the string.
     183        (%copy-ptr-to-ivector (#/bytes data) 0 string 0 nbytes)))))
     184       
     185
     186
     187#+ascii-only
    176188(defun lisp-string-from-nsstring (nsstring)
    177189  (with-macptrs (cstring)
     
    206218  ;;; this condition.
    207219
    208   ;; (dbg (format nil "~a" c))
     220  (dbg (format nil "~a" c))
    209221  ;;(#_NSLog #@"Lisp exception: %@" :id (%make-nsstring (format nil "~a" c)))
    210222  (make-instance 'ns-lisp-exception :condition c))
Note: See TracChangeset for help on using the changeset viewer.