Last active
April 14, 2020 17:15
-
-
Save s-zeid/c6fd8f879f6668cea86070a6848bd7a6 to your computer and use it in GitHub Desktop.
Print whether Qt 5's `QChar::isPrint()` is true for one or more code points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ -fPIC -I/usr/include/qt5 -lQt5Core qisprint.cc -o qisprint | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <errno.h> | |
#include <QtCore/qchar.h> | |
void usage(char* prog) { | |
fprintf(stderr, "Usage: %s <code point> [...]\n", prog); | |
} | |
int main(int argc, char** argv) { | |
if (argc < 2) { | |
usage(argv[0]); | |
return 2; | |
} | |
for (int i = 1; i < argc; i++) { | |
char* codepoint_str = argv[i]; | |
if (*codepoint_str == '\\') | |
codepoint_str++; | |
if (*codepoint_str == 'U' || *codepoint_str == 'u') | |
codepoint_str++; | |
if (*codepoint_str == '+') | |
codepoint_str++; | |
if (*codepoint_str == '-' || strlen(codepoint_str) > 8) { | |
usage(argv[0]); | |
return 2; | |
} | |
errno = 0; | |
char* endptr; | |
unsigned int codepoint = strtoul(codepoint_str, &endptr, 16); | |
if (errno != 0) { | |
perror("strtoul"); | |
return 1; | |
} else if (endptr == codepoint_str || *endptr != '\0') { | |
usage(argv[0]); | |
return 2; | |
} | |
QChar qchar(codepoint); | |
if (qchar.isPrint()) | |
printf("U+%04X is printable\n", codepoint); | |
else | |
printf("U+%04X is not printable\n", codepoint); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment