Skip navigation.
 
mlRe: How would you convert a \r to its UTF-8 counterpart ?
FROM : Nir Soffer
DATE : Wed Jul 26 23:22:24 2006

I tried with PyObjC:

from Foundation import *

src = NSDictionary.dictionaryWithObject_forKey_(
   u"CR\rLF\nNEL\u0085FF\u000CLS\u2028PS\u2029", 'whitespace')
src.writeToFile_atomically_('cocoa.plist', True)

dst = NSDictionary.dictionaryWithContentsOfFile_('cocoa.plist')

assert src == dst

It generates this markup:

<dict>
   <key>whitespace</key>
   <string>CR
LF
NEL
FFLS
PS
</string>
</dict>

And the generated plist file is correct according to plutil -lint

So it seems that you can stuff anything you like into the plist and 
let it do the right thing for you :-)


On 26/07/2006, at 23:11, stephen joseph butler wrote:

> 2006/7/26, Stéphane Sudre <<email_removed>>:

>> 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.
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>



Best Regards,

Nir Soffer

Related mailsAuthorDate
mlHow would you convert a \r to its UTF-8 counterpart ? Stéphane Sudre Jul 25, 23:20
mlRe: How would you convert a \r to its UTF-8 counterpart ? Ricky Sharp Jul 25, 23:39
mlRe: How would you convert a \r to its UTF-8 counterpart ? Shawn Erickson Jul 26, 00:03
mlRe: How would you convert a \r to its UTF-8 counterpart ? Stéphane Sudre Jul 26, 21:38
mlRe: How would you convert a \r to its UTF-8 counterpart ? stephen joseph but… Jul 26, 22:11
mlRe: How would you convert a \r to its UTF-8 counterpart ? Nir Soffer Jul 26, 23:22
mlRe: How would you convert a \r to its UTF-8 counterpart ? Matt Neuburg Jul 27, 03:21
mlRe: How would you convert a \r to its UTF-8 counterpart ? Stéphane Sudre Jul 28, 20:23
mlRe: How would you convert a \r to its UTF-8 counterpart ? stephen joseph but… Jul 28, 23:57
mlRe: How would you convert a \r to its UTF-8 counterpart ? John Stiles Jul 29, 00:03
mlRe: How would you convert a \r to its UTF-8 counterpart ? Michael Nickerson Jul 29, 01:32
mlRe: How would you convert a \r to its UTF-8 counterpart ? stephen joseph but… Jul 29, 06:29