views:

1091

answers:

9

I am writing a text editor which has an option to display a bullet in place of any invisible Unicode character. Unfortunately there appears to be no easy way to determine whether a Unicode character is invisible.

I need to find a text file containing every Unicode character in order that I can look through for invisible characters. Would anyone know where I can find such a file?

EDIT: I am writing this app in Cocoa for Mac OS X.

A: 

What platform are you using? There may be a call which would help, e.g. in .NET there's Char.GetUnicodeCategory.

Jon Skeet
A: 

Its an impossible task, Unicode supports even Klingon, so it's not going to work. However most text editors use the standard ANSI invisible characters. And if your Unicode library is good, it will support finding equivalent characters and/or categories, you can use these two features to do it as well as any editor out there

Edit: Yes I was being silly about Klingon support, but that doesn't make it not true... of course Klingon is not supported by the Consortium, however there is a movement for Klingon in the Unicode's "Private Use Area" defined for Klingon alphabet (U+F8D0 - U+F8FF). Link here for those interested :)

Note: Wonder what editor Klingon programmers use...

Robert Gould
The actual Unicode standard does not include fictional scripts - perhaps the Consortium will add them someday, but for now they have far more to worry about. But the parts of Unicode that are mapped are very well-defined, so there is a comprehensive list of invisible characters.
coppro
I think Robert was being facetious about support for Klingon. I realize that there are too many characters to make this approach feasible so I am looking for alternatives.
titaniumdecoy
Unicode doesn't support Klingon because everyone who writes Klingon does so w/ ASCII. The fancy Klingon characters aren't used in practice. But if I'm not mistaken, other imaginary scripts are supported.
Logomachist
Yeah like elvin (I don't remember the proper name for the script tho)
Jason Coco
A: 

A good place to start is the Unicode Consortium itself which provides a large body of data, some of which would be what you're looking for.

I'm also in the process of producing a DLL which you give a string and it gives back the UCNs of each character. But don't hold your breath.

boost
A: 

The current official Unicode version is 5.1.0, and text files describing all of the code points in that can be found at http://www.unicode.org/standard/versions/components-latest.html

Alnitak
+2  A: 

Oh, I see... actual invisble characters ;) This FAQ will probably be useful:

http://www.unicode.org/faq/unsup_char.html

It lists the current invisible codepoints and has other information that you might find helpful.

EDIT: Added some Cocoa-specific information

Since you're using Cocoa, you can get the unicode character set for control characters and compare against that:

NSCharacterSet* controlChars = [NSCharacterSet controlCharacterSet];

You might also want to take a look at the FAQ link I posted above and add any characters that you think you may need based on the information there to the character set returned by controlCharacterSet.

EDIT: Added an example of creating a Unicode string from a Unicode character

unichar theChar = 0x000D;
NSString* thestring = [NSStirng stringWithCharacters:&theChar length:1];
Jason Coco
Not all invisible characters are control characters. I think you would consider the zero-width characters invisible, but they aren't control characters. It also doesn't include the Unicode LINE SEPARATOR and PARAGRAPH SEPARATOR characters.
Peter Hosey
@Peter, Right, which is why I posted the FAQ first and suggested that the appropriate characters be added to the controlCharacterSet.
Jason Coco
+1  A: 

For Java, java.lang.Character.getType. For C, u_charType() or u_isgraph().

eed3si9n
A: 

How can I convert a Unicode value into the character itself? For example, 000D.

titaniumdecoy
Libraries do this. Apple uses a wrapper around IBM's ICU library. So it should be doable, but haven't done it myself
Robert Gould
sscanf with format %x into an unsigned int. In Windows you can sscanf it with format %hx directly into a wchar_t.
Windows programmer
I'm not sure exactly what you mean, but I added a little example. Apple has a unichar type that's used to store Unicode characters. Don't use wchar_t as it's 4 bytes wide in Mac OS X and doesn't play well with Cocoa.
Jason Coco
The string “000D” is just a hexadecimal number. Use strtoul, NSScanner, sscanf, etc.Also, perhaps you should have asked this as a separate question?
Peter Hosey
+1 for good question
Robert Gould
-1 for being in the wrong place
Alnitak
A: 

you might find this code to be of interest: http://gavingrover.blogspot.com/2008/11/unicode-for-grerlvy.html

Ray Tayek
+1  A: 

Let me know if this code helps at all:

-(NSString*)stringByReplacingControlCharacters:(NSString*)originalString
{
    NSUInteger length = [originalString length];
    unichar *strAsUnichar = (unichar*)malloc(length*sizeof(unichar));
    NSCharacterSet* controlChars = [NSCharacterSet controlCharacterSet];
    unichar bullet = 0x2022;

    [originalString getCharacters:strAsUnichar];
    for( NSUInteger i = 0; i < length; i++ ) {
     if( [controlChars characterIsMember:strAsUnichar[i]] )
      strAsUnichar[i] = bullet;
    }

    NSString* newString = [NSString stringWithCharacters:strAsUnichar length:length];
    free(strAsUnichar);

    return newString;
}

Important caveats:

This probably isn't the most efficient way of doing this, so you will have to decide how you want to optimize after you get it working. This only works with characters on the BMP, support for composted characters would have to be added if you have such a requirement. This does no error checking at all.

Jason Coco
I appreciate your posting that code. It may well come in handy. However, the problem is that I am quite certain that the controlCharacterSet is only a small subset of all invisible characters.
titaniumdecoy
You might be interested in the code I am currently using, which can be found here: http://stackoverflow.com/questions/300086/display-hidden-characters-in-nstextview
titaniumdecoy
It's actually not a small subset, but it's definitely not all the invisible characters. You can look at the Unicode site for the full list of various characters, but some invisible characters you probably *dont* want to turn into bullets, like joiners and such.
Jason Coco