Lisp HUG Maillist Archive

Convert a NSString

Hi,

How may I convert a NSString to a lisp string ?

With the objc ³invoke-into² function the conversion is automatic.
But, here, I need to convert a foreign-pointer to a NSSTring (not in the
context of a objective-c method)

I tried this (but the result is not good, some resulting strings have
additional erratic characters at the end) :

(defconstant NSUnicodeStringEncoding 10)

(defun convert-NSString (NSStringRef)
  (let ((cstring (objc:invoke NSStringRef "cStringUsingEncoding:"
                     NSUnicodeStringEncoding)))
    (fli:convert-from-foreign-string cstring :external-format :unicode)))

maybe a simplest and more efficient way to do this ?

Thanks

Denis


----------------------------------------------------
Denis Pousseur
6 clos du Drossart
1180 Bruxelles, Belgique

Mail :  denis.pousseur@compositeurs.be
Website : http://compositeurs.be
----------------------------------------------------




Re: Convert a NSString


On Aug 11, 2006, at 2:09 PM, Denis Pousseur wrote:

>
> How may I convert a NSString to a lisp string ?
>
>
>


No extensive testing, but this seems to work for me:


(defun %string (ns-or-cf-string)
   (let ((ptr (objc:invoke ns-or-cf-string "UTF8String")))
     (when ptr
       (fli:convert-from-foreign-string ptr :external-format :utf-8))))




John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


Updated at: 2020-12-10 08:47 UTC