Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard solution for displaying names of chars c++?

Tags:

c++

char

Is there a standard function for user-friendly representation of non-alphanum input characters?
Say char(27) would be "ESC" or "Escape" or something alike.
I am asking this because that would be an easy way for me to display help on controls in command line.

EDIT:

As @ypnos pointed out: the question is how to avoid defining my own key names.
I wonder if there was a function in boost or std or some basic lib which I missed?

For now, Ascii-only could work for me but I am looking for a "standard" solution because I don't want to reimplement once dealing with Unicode input -- say characters with accents not in Ascii -- later on.

My program code will be sent over to Linux and Windows and I also don't want that the names would be faulty at places.

like image 712
Barney Szabolcs Avatar asked Nov 06 '12 14:11

Barney Szabolcs


1 Answers

The most C++-y way would probably via a library such as Ogonek. Unfortunately, the relevant function isn’t yet implemented at the moment.

R. Martinho Fernandes (the maintainer) tells me that it should look as follows:

namespace ogonek {
    namespace ucd {
        …

        basic_text<utf8> get_name(codepoint u) {
            return basic_text<utf8> {
                find_property_group(name_data, name_data_size, u).name };
        }

        …
    }
}

And then you could simply display a Unicode code point’s (27, say) name using

std::cout << ogonek::ucd::get_name(27);
like image 84
Konrad Rudolph Avatar answered Oct 25 '22 07:10

Konrad Rudolph