29 if (*
s ==
'x' || *
s ==
'X') {
62 int (*cb)(
void *state,
const char *
s),
void *state) {
64 const char *
s = *current;
72 return cb(state,
"&");
77 return cb(state,
"<");
80 return cb(state,
">");
83 if (c ==
'-' &&
flags.dash)
84 return cb(state,
"-");
86 if (c ==
' ' && previous ==
' ' &&
flags.nbsp)
88 return cb(state,
" ");
91 return cb(state,
""");
94 return cb(state,
"'");
96 if (c ==
'\n' &&
flags.raw)
97 return cb(state,
" ");
99 if (c ==
'\r' &&
flags.raw)
100 return cb(state,
" ");
102 unsigned char uc = (
unsigned char)c;
103 if (uc > 0x7f &&
flags.utf8) {
117 size_t length = (uc >> 5) == 6 ? 2
118 : (uc >> 4) == 14 ? 3
119 : (uc >> 3) == 30 ? 4
123 bool is_invalid = length == 0;
124 for (
size_t l = 1; !is_invalid && length > l; ++l)
125 is_invalid |=
s[l] ==
'\0';
129 fprintf(stderr,
"Error during conversion to \"UTF-8\". Quiting.\n");
135 uint32_t utf8_char = 0;
138 uint32_t low = ((uint32_t)
s[1]) & ((1 << 6) - 1);
139 uint32_t high = ((uint32_t)
s[0]) & ((1 << 5) - 1);
140 utf8_char = low | (high << 6);
144 uint32_t low = ((uint32_t)
s[2]) & ((1 << 6) - 1);
145 uint32_t mid = ((uint32_t)
s[1]) & ((1 << 6) - 1);
146 uint32_t high = ((uint32_t)
s[0]) & ((1 << 4) - 1);
147 utf8_char = low | (mid << 6) | (high << 12);
151 uint32_t low = ((uint32_t)
s[3]) & ((1 << 6) - 1);
152 uint32_t mid1 = ((uint32_t)
s[2]) & ((1 << 6) - 1);
153 uint32_t mid2 = ((uint32_t)
s[1]) & ((1 << 6) - 1);
154 uint32_t high = ((uint32_t)
s[0]) & ((1 << 3) - 1);
155 utf8_char = low | (mid1 << 6) | (mid2 << 12) | (high << 18);
163 char buffer[
sizeof(
"�")];
166 snprintf(buffer,
sizeof(buffer),
"&#x%" PRIx32
";", utf8_char);
169 *current += length - 1;
171 return cb(state, buffer);
175 char buffer[2] = {c,
'\0'};
176 return cb(state, buffer);
180 int (*cb)(
void *state,
const char *
s),
void *state) {
181 char previous =
'\0';
201static int put(
void *stream,
const char *
s) {
return fputs(
s, stream); }
204int main(
int argc,
char **argv) {
209 static const struct option
opts[] = {
210 {
"dash", no_argument, 0,
'd'},
211 {
"nbsp", no_argument, 0,
'n'},
212 {
"raw", no_argument, 0,
'r'},
213 {
"utf8", no_argument, 0,
'u'},
218 int c = getopt_long(argc, argv,
"dnru",
opts, &index);
242 fprintf(stderr,
"unexpected error\n");
248 for (
int i = optind; i < argc; ++i) {
static int put(void *buffer, const char *s)
static NORETURN void graphviz_exit(int status)
replacements for ctype.h functions
static bool gv_isxdigit(int c)
static bool gv_isdigit(int c)
static bool gv_isalpha(int c)
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t
int xml_escape(const char *s, xml_flags_t flags, int(*cb)(void *state, const char *s), void *state)
static bool xml_isentity(const char *s)
static int xml_core(char previous, const char **current, xml_flags_t flags, int(*cb)(void *state, const char *s), void *state)