views:

800

answers:

4

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!!

A: 

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).

Matt Gallagher
@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!!
ennuikiller
@ennuikiller Have you put the escapes into the Plist? That won't work at all... the plist is not parsed to replace escapes. If you want special characters to appear, what you need to do is copy the exact characters into the plist (no escapes -- the actual characters, already superscripted).
Matt Gallagher
A: 

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.

ennuikiller
+2  A: 

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;.

Jim Dovey
A: 

Doesn't seem to work with longer unicode like

&#x2233E;

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"&gt;
     3 <plist version="1.0">
sdnf189uwebf18ubwe8fbas