Skip to content

Instantly share code, notes, and snippets.

@s-zeid
Last active April 14, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-zeid/c6fd8f879f6668cea86070a6848bd7a6 to your computer and use it in GitHub Desktop.
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
// 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