Cant't use UTF-8 source files. False string interpretation.

  • Hello,
    my problem is that I cannot programmaticaly apply international
    characters to my nib file.
    It is possible to enter arabic letters in an NSTextField by using IB's
    Attributes window but I can't [text1 setStringValue:@"someArabic"];
    Whenever I try to do so XCode tells me that I need to change the
    document layout to UTF-8. Then it does work in XCodes editor but not in
    my GUI.
    My window produces the usual crap when it's trying to display UTF-8 in
    an non UTF-8 environment.

    I'm confused. I know that my nib knows how to display arabic but only
    when I use IB to enter it. There seems to be an communication problem at
    build time.

    The manual says this:
    > Choosing File Encodings:
    > You can choose the file encoding, which defines the character set that
    Xcode uses to display and save a file. If you type a character that
    isnt in the files encoding, Xcode asks whether you want to change the
    encoding. Xcode uses the default single-byte string encoding, if
    possible (usually Mac OS Roman), or Unicode if the file contains
    double-byte characters.
    > To change the file encoding for one or more files, select those files
    in the Groups & Files list or in the detail view and open the inspector
    window. In the General pane of the inspector window, choose the desired
    file encoding from the File Encoding pop-up menu. Generally Unicode
    (UTF-8) is best for source files and Unicode (UTF-16) is best for
    .strings files.
    > GCC, the compiler used by Xcode for C, C++, and Objective-C, expects
    its source files to contain only ASCII characters, with the exception
    that comments and strings can contain any characters. Make sure your
    application and your source files both use the same encoding. [......]

    Anyway, thanks for your help,
    Bernd.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Replace:

    > [text1 setStringValue:@"someArabic"];

    with:

    [text1
    setStringValue:NSLocalizedStringFromTable(@"someArabic",@"MyArabicstring
    sile",@"Description forthcoming")];

    ?
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • > It is possible to enter arabic letters in an NSTextField by using IB's
    > Attributes window but I can't [text1 setStringValue:@"someArabic"];

    If you set the encoding of your source files to UTF-8, you can do
    something like that:

    [text1 setStringValue:[NSString stringWithUTF8String:"someArabic"]];

    >> GCC, the compiler used by Xcode for C, C++, and Objective-C, expects
    > its source files to contain only ASCII characters, with the exception
    > that comments and strings can contain any characters. Make sure your
    > application and your source files both use the same encoding. [......]

    This seems to be valid for C-Strings ("...") only, not for
    Obj-C-Strings (@"...").

    Regards,
    Mani
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Feb 16, 2004, at 08:42, Bernd Carl wrote:

    > Hello,
    > my problem is that I cannot programmaticaly apply international
    > characters to my nib file.
    > It is possible to enter arabic letters in an NSTextField by using IB's
    > Attributes window but I can't [text1 setStringValue:@"someArabic"];
    > Whenever I try to do so XCode tells me that I need to change the
    > document layout to UTF-8. Then it does work in XCodes editor but not
    > in my GUI.
    > My window produces the usual crap when it's trying to display UTF-8 in
    > an non UTF-8 environment.

    You can use UTF-8 strings in UTF-8 source files only with the C string
    syntax (i.e. "my UTF-8 string"), not with the Objective-C string syntax
    (i.e. @"my NSString"), as the latter only supports 7-bit, ASCII. You
    have two options here:

    1) Use NSLocalizedString, and put your GUI strings in a .strings file
    2) Use [NSString stringWithUTF8String: "My UTF-8 String"]

    Option 1 is arguably better as it makes no assumptions about the
    encoding of the source code, and it allows you to add other
    localizations at a later date.

    --
    Clark S. Cox III
    <clarkcox3...>
    http://homepage.mac.com/clarkcox3/
    http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Thank you for the explanation :-) Now it works.
    Another problem it can't really solve: Manipulation of strings.
    I need to split all arabic strings up into all its letters. So my problem
    wasn't really a GUI thing, than rather a Cocoa thing.
    Probably I have to work it out in unicode entities but this is really
    annoying.

    Clark Cox wrote:

      On Feb 16, 2004, at 08:42, Bernd Carl wrote:

        Hello,
        my problem is that I cannot programmaticaly apply international
        characters to my nib file.
        It is possible to enter arabic letters in an NSTextField by using
        IB's Attributes window but I can't [text1
        setStringValue:@"someArabic"];
        Whenever I try to do so XCode tells me that I need to change the
        document layout to UTF-8. Then it does work in XCodes editor but
        not in my GUI.
        My window produces the usual crap when it's trying to display
        UTF-8 in an non UTF-8 environment.

          You can use UTF-8 strings in UTF-8 source files only with the C
      string syntax (i.e. "my UTF-8 string"), not with the Objective-C
      string syntax (i.e. @"my NSString"), as the latter only supports
      7-bit, ASCII. You have two options here:

      1) Use NSLocalizedString, and put your GUI strings in a .strings file
      2) Use [NSString stringWithUTF8String: "My UTF-8 String"]

          Option 1 is arguably better as it makes no assumptions about the
      encoding of the source code, and it allows you to add other
      localizations at a later date.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 16 Feb, 2004, at 12:40 PM, Bernd Carl wrote:

    > Another problem it can't really solve: Manipulation of strings.
    > I need to split all arabic strings up into all its letters. So my
    > problem
    > wasn't really a GUI thing, than rather a Cocoa thing.
    > Probably I have to work it out in unicode entities but this is really
    > annoying.

    I don't know Arabic, but I don't see why you would need to work
    directly with Unicode entities. You can use NSString's
    rangeOfComposedCharacterSequenceAtIndex: to iterate through the string,
    collecting clusters of base characters and their non-base characters.

    If you don't trust NSString, you can also use Carbon's Unicode
    Utilities to go through the string character-by-character,
    cluster-by-cluster, word-by-word, or line-by-line. Those functions are
    documented at
    <file:///Developer/Documentation/Carbon/Reference/
    Unicode_Utilities_Ref/uu_refchap/function_group_3.html>.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month february 2004 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
Go to today