How to correctly handle UTF-8 strings in XCode Objective-C program with multiple inputs?

26 Views Asked by At

In a program, I am reading data from a pure text input file, some more data from a preference file (user input saved in a plist file) and finally strings from a localization file in my project.

When I display these files in some external editor (e.g. Sublime Text) using unicode, they are correct.

Basically, my program is taking data from the input file, adding some HTML enhancements and including contents from plist file and localization file. Then, I put the result in another text file.

When I have a look to the output file in that same editor, all strings coming from plist or localization are not correctly handled and I wonder to know what is wrong somewhere.

As an example, here is a line from the output file :

1 NOTE <div id="occu"><h4>Activit? professionnelle</h4><div style="background-color:#f3f3f3; padding:10px;">

"Activit? professionnelle" is coming from localization file . it should be displayed as shown in localization file

"OCCU" = "Activité professionnelle";

Here is another line from the output file :

2 CONT <table><tr><td><strong>T?oin(s) au d??</strong>: </td></tr><tr><td>Machin Truc, son cousin</td></tr><tr><td></td></tr></table>

"T?oin(s) au d??" should be displayed as shown in plist file :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>description</key>
        <string>LIFE:Témoin(s) au décès</string>
        <key>private</key>
        <false/>
        <key>tag</key>
        <string>_WID</string>
    </dict>
</array>
</plist>

In the program, I use NSLocalizedString to access Localization file. Result is handled in a NSMutableString

        [sNote appendString: NSLocalizedString(occuTagLabel,occuTagLabel)];

Plist data are handled in a NSMutableArray of NSMutableDictionary, each containing an object instance of a class I have defined in the program. It is initialized as follow :

    NSMutableArray *tagTable;
    tagTable = [NSMutableArray arrayWithContentsOfFile: fName];

During debugging, XCode is displaying these strings as expected :

sNote   __NSCFString *  @"<div id=\"occu\"><h4>Activité professionnelle"    0x0000600000487180

but when I display any string coming from the input file (which are correctly displayed in the output file as well

value   __NSCFString *  @"Quelque part, Département, Pays" 0x000060000049f1b0

I understand that strings from Plist or Localization are NOT interpreted as UTF-8

Does anyone could explain this unexpected behavior ? What should I do in order to have all strings interpreted as UTF-8

0

There are 0 best solutions below