Re: How would you convert a \r to its UTF-8 counterpart ?
Re: How would you convert a \r to its UTF-8 counterpart ?
- Subject: Re: How would you convert a \r to its UTF-8 counterpart ?
- From: Matt Neuburg <email@hidden>
- Date: Wed, 26 Jul 2006 18:21:03 -0700
- Thread-topic: How would you convert a \r to its UTF-8 counterpart ?
On Wed, 26 Jul 2006 15:11:35 -0500, "stephen joseph butler"
<email@hidden> said:
>2006/7/26, Stéphane Sudre <email@hidden>:
>> On mercredi, juillet 26, 2006, at 12:03 AM, Shawn Erickson wrote:
>> > On Jul 25, 2006, at 2:20 PM, Stéphane Sudre wrote:
>> >
>> >> How would you convert a \r to its UTF-8 counterpart ?
>> >
>> > You may want to review what UTF-8 really is [1] since it has little to
>> > do directly with what you are asking.
>> >
>> > \r is ASCII CR which is 0x0D in ASCII and in UTF-8.
>> >
>> > Anyway it looks like you are asking about character escaping in XML
>> > (for example [2], [3]).
>>
>> Ok, I need to rephrase the question to use the proper terms.
>>
>> How can I save a string in a plist inside <string></string> tags so
>> that the string is saved with character escaping for the '\r' (and
>> probably '\n') characters?
>>
>> This is done automatically for the & character.
>
>Have you given this a test as is? For example, in F-Script (a sort of
>Objective-C scripting language) I tried this:
>
>dict1 := NSDictionary dictionaryWithObjects:{'this is\r a test\r',
>'\r\rthis is another test\r\r'} forKeys:{'a', 'b'}
>dict1 writeToFile:'/Users/foo/test.plist' atomically:true
>
>dict2 := NSDictionary dictionaryWithContentsOfFile:'/Users/foo/test.plist'
>dict2 objectForKey:'a'
>dict2 objectForKey:'b'
>
>Both printed out fine. If you take a look at the XML spec, it has this
>to say about whitespace:
>
>"An XML processor MUST always pass all characters in a document that
>are not markup through to the application. A validating XML processor
>MUST also inform the application which of these characters constitute
>white space appearing in element content."
>
>So how whitespace is handled is entirely up to the application, it is
>illegal for parsers to ignore it. Obviously, Apple has chosen to not
>ignore it.
However, it should be pointed out that Apple routines are perfectly capable
of generating something that claims to be a plist but in fact is neither a
valid plist nor valid XML.[1] So it is not unreasonable to be suspicious, as
a general rule. m.
[1] For example, nibtool does this.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden