mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More work on entity conversion
This commit is contained in:
parent
858f047b78
commit
741ddaadb8
@ -9,8 +9,6 @@
|
|||||||
#define UNICODE
|
#define UNICODE
|
||||||
#define _UNICODE
|
#define _UNICODE
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <frozen/unordered_map.h>
|
|
||||||
#include <frozen/string.h>
|
|
||||||
#include "../utils/cpp_binding.h"
|
#include "../utils/cpp_binding.h"
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
@ -58,26 +56,26 @@ bad_entity:
|
|||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
memcpy(e, entity, elen);
|
memcpy(e, entity, elen);
|
||||||
unsigned long codepoint = ULONG_MAX;
|
|
||||||
e[elen] = 0;
|
e[elen] = 0;
|
||||||
if (e[0] == '#') {
|
if (e[0] == '#') {
|
||||||
if (elen > 1) {
|
if (elen < 2) goto bad_entity;
|
||||||
char *end;
|
char *end;
|
||||||
if (e[1] == 'x' || e[1] == 'X') {
|
unsigned long codepoint = ULONG_MAX;
|
||||||
errno = 0;
|
if (e[1] == 'x' || e[1] == 'X') {
|
||||||
codepoint = strtoul(e + 2, &end, 16);
|
errno = 0;
|
||||||
if (errno || *end) goto bad_entity;
|
codepoint = strtoul(e + 2, &end, 16);
|
||||||
} else {
|
if (errno || *end) goto bad_entity;
|
||||||
errno = 0;
|
} else {
|
||||||
codepoint = strtoul(e + 1, &end, 10);
|
errno = 0;
|
||||||
if (errno || *end) goto bad_entity;
|
codepoint = strtoul(e + 1, &end, 10);
|
||||||
}
|
if (errno || *end) goto bad_entity;
|
||||||
if (codepoint <= 1114111ul) return encode_utf8(codepoint, output);
|
|
||||||
}
|
}
|
||||||
|
unsigned num = encode_utf8(codepoint, output);
|
||||||
|
if (!num) goto bad_entity;
|
||||||
|
return num;
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
goto bad_entity;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user