• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Confused re unichar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confused re unichar


  • Subject: Re: Confused re unichar
  • From: "stephen joseph butler" <email@hidden>
  • Date: Sat, 17 Feb 2007 10:35:48 -0600

2007/2/17, Timothy Mowlem <email@hidden>:
Presumably a unichar is a single unicode character. But is it defined
as 2 bytes in size (UTF-16) or is it variable (UTF-8)? I can't find
its defintion anywhere.

UTF-16 is 2 bytes in size, and is a variable length encoding. Some symbols will be two characters in length.

But this shouldn't matter for your purposes. The way the encoding
happens, the second character of a 2 character encoding will never be
a valid first character. So you don't have to worry that your checks
for a space will accidently match the second character.

More at Wikipedia: <http://en.wikipedia.org/wiki/UTF-16>

- (NSString *) stringByTrimmingWhitespaceAtStart {
        int length = [self length];
        unichar *buffer = unichar[length];
        [self getCharacters: buffer];
        int idx = 0;
        unichar ch;
        while (idx < length) {
                ch = buffer[idx++];
                if (ch == '\x0020' || ch == '\x0009' || ch == '\x000A' || ch ==
'\x000D' || ch == '\x0085') {
                        continue;
                }
                break;
        }
        return [self substringFromIndex: idx];
}


The compiler complains with "error: parse error before unichar"

Yes, because you can't create C arrays of dynamic size that way. You need to malloc() or (better yet) calloc(). For example:

buffer = (unichar*)calloc( [self length], sizeof( unichar ) );

Don't forget to free() when you're done.

One other thing... NSCharacterSet was designed to do the type of
things you're doing inside your loop. Take a look at it, there's even
a predefined set for whitespace characters.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Confused re unichar (From: Timothy Mowlem <email@hidden>)

  • Prev by Date: Confused re unichar
  • Next by Date: Re: Removing / inserting Menuitems in Mainmenu
  • Previous by thread: Confused re unichar
  • Next by thread: Re: Confused re unichar
  • Index(es):
    • Date
    • Thread