ennuikiller
ennuikiller

Reputation: 46975

Reading a plist utf-8 value as utf-16

I'm working on an iphone app that needs to display superscripts and subscripts. I'm using a picker to read in data from a plist but the unicode values aren't being displayed corretly in the pickerview. Subscripts and superscripts are not being recognized. I'm assuming this is due to the encoding of the plist as utf-8, so the question is how do a convert a plist string encoding from utf-8 to utf-16 ?

Just a little more elaboration:

If I do this it displays properly at least in a textfield:

NSString *equation = @"x\u00B2 + y\u00B2 = z\u00B2"

However if I define the same string in a plist and try to read it in and assign it to a string and display it on a pickerview it just displays the the encoding and not the superscripts.

@Matt: thanks for your suggestion the unicode is being escaped that is \u00B2 => \u00B2. Googling for "escaped values in plists" returned no useful results, and I haven't been able to use the keyboard cmd-ctrl-shift-+ to work. Any further suggestions would be greatly appreciated!!

Upvotes: 2

Views: 4521

Answers (4)

Doesn't seem to work with longer unicode like

𢌾

header of the plist:

<?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
     3 <plist version="1.0">

Upvotes: 0

Jim Dovey
Jim Dovey

Reputation: 11156

The \u variants only work when presented to the C compiler. For UTF-8, if you really want to type character codes rather than simply typing them (the companion to the character palette is the keyboard viewer, which will update as you press modifier keys so you can search for specific characters that way), then you'll have to use XML entities, i.e. &#x00B2;.

Upvotes: 4

ennuikiller
ennuikiller

Reputation: 46975

AFter about a day of experimenting I chanced upon using the OS X character palatte. This works well although a bit tedious....I would still like to discover how to embed the codes as text in a plist.

Upvotes: 0

Matt Gallagher
Matt Gallagher

Reputation: 14968

Plist files automatically embed their own encoding. i.e.:

<?xml version="1.0" encoding="UTF-8"?>

This means that whether they are UTF-8, UTF-16 or otherwise, they will be loaded correctly.

If you are having issues with loading from a plist, it must be something else. Try using:

NSLog(@"%@", [[[NSDictionary alloc] initWithContentsOfFile:@"/path/to/plist"] autorelease]);

to output the entire plist as a starting point for finding the problem.

If you're curious about the encodings, you can change them by Opening as Text File in Xcode (right-click in the File Tree and select Open As...) then using the View->Text->File Encoding menu to change the file encoding (you'll need to fix the XML encoding to match).

Upvotes: 0

Related Questions