views:

114

answers:

4

I have a UTF-8 text file open in Eclipse, and I'd like to find out what a particular Unicode character is. Is there a function to display the Unicode codepoint of the character under the cursor?

+1  A: 
VonC
Looks good. I'm sorry to say I don't even know how to get set up to build it--never been a Java programmer, and using Eclipse for Python and C/C++. But in time, I'll try to learn.
Craig McQueen
A: 

Here's the related question how to do it independently from eclipse.

Thomas Jung
A: 

Here's a Python script to show information about Unicode characters on a Windows clipboard. So, just copy the character in your favourite editor, then run this program.

Not built-in to Eclipse, but it's what I'll probably use when I haven't got a better option.

"""
Print information about Unicode characters on the Windows clipboard

Requires Python 2.6 and PyWin32.

For ideas on how to make it work on Linux via GTK, see:
http://mrlauer.wordpress.com/2007/12/31/python-and-the-clipboard/
"""

import win32con
import win32clipboard
import unicodedata
import sys
import codecs
from contextlib import contextmanager

MAX_PRINT_CHARS = 1

# If a character can't be output in the current encoding, output a replacement e.g. '??'
sys.stdout = codecs.getwriter(sys.stdout.encoding)(sys.stdout, errors='replace')

@contextmanager
def win_clipboard_context():
    """
    A context manager for using the Windows clipboard safely.
    """
    try:
        win32clipboard.OpenClipboard()
        yield
    finally:
        win32clipboard.CloseClipboard()

def get_clipboard_text():
    with win_clipboard_context():
        clipboard_text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
    return clipboard_text

def print_unicode_info(text):
    for char in text[:MAX_PRINT_CHARS]:
        print(u"Char: {0}".format(char))
        print(u"    Code: {0:#x} (hex), {0} (dec)".format(ord(char)))
        print(u"    Name: {0}".format(unicodedata.name(char, u"Unknown")))

try:
    clipboard_text = get_clipboard_text()
except TypeError:
    print(u"The clipboard does not contain Unicode text")
else:
    print_unicode_info(clipboard_text)
Craig McQueen
A: 

You can also look-up a character in the Unicode database using the Character Properties Unicode Utility at http://unicode.org/. I've made a Firefox Search Engine to search via that utility. So, just copy-and-paste from your favourite editor into the search box.

See the list of online tools at http://unicode.org/. E.g. it lists Unicode Lookup by Jonathan Hedley.

Craig McQueen