static constexpr u32 MAX_NUMBER = INT_MAX;
static
-void pushDec(u32 *acc, u8 raw_digit) {
+void pushDec(u32 *acc, char raw_digit) {
assert(raw_digit >= '0' && raw_digit <= '9');
u32 digit_val = raw_digit - '0';
}
static
-void pushOct(u32 *acc, u8 raw_digit) {
+void pushOct(u32 *acc, char raw_digit) {
assert(raw_digit >= '0' && raw_digit <= '7');
u32 digit_val = raw_digit - '0';
}
static
-void addLiteral(ComponentSequence *currentSeq, unsigned char c,
- const ParseMode &mode) {
+void addLiteral(ComponentSequence *currentSeq, char c, const ParseMode &mode) {
if (mode.utf8 && mode.caseless) {
/* leverage ComponentClass to generate the vertices */
auto cc = getComponentClass(mode);
if (accum > 255) {
throw LocatedParseError(err_msg);
}
- addLiteral(currentSeq, (unsigned char)accum, mode);
+ addLiteral(currentSeq, (char)accum, mode);
}
}
#define SLASH_C_ERROR "\\c must be followed by an ASCII character"
static
-u8 decodeCtrl(u8 raw) {
+u8 decodeCtrl(char raw) {
if (raw & 0x80) {
throw LocatedParseError(SLASH_C_ERROR);
}
}
static
-unichar readUtf8CodePoint2c(const u8 *ts) {
+unichar readUtf8CodePoint2c(const char *s) {
+ auto *ts = (const u8 *)s;
assert(ts[0] >= 0xc0 && ts[0] < 0xe0);
assert(ts[1] >= 0x80 && ts[1] < 0xc0);
-
unichar val = ts[0] & 0x1f;
val <<= 6;
val |= ts[1] & 0x3f;
}
static
-unichar readUtf8CodePoint3c(const u8 *ts) {
+unichar readUtf8CodePoint3c(const char *s) {
+ auto *ts = (const u8 *)s;
assert(ts[0] >= 0xe0 && ts[0] < 0xf0);
assert(ts[1] >= 0x80 && ts[1] < 0xc0);
assert(ts[2] >= 0x80 && ts[2] < 0xc0);
}
static
-unichar readUtf8CodePoint4c(const u8 *ts) {
+unichar readUtf8CodePoint4c(const char *s) {
+ auto *ts = (const u8 *)s;
assert(ts[0] >= 0xf0 && ts[0] < 0xf8);
assert(ts[1] >= 0x80 && ts[1] < 0xc0);
assert(ts[2] >= 0x80 && ts[2] < 0xc0);
%%{
machine regex;
- alphtype unsigned char;
-
action throwUnsupportedEscape {
ostringstream str;
- str << "'\\" << (char)*(ts + 1) << "' at index "
- << ts - ptr << " not supported in a character class.";
+ str << "'\\" << *(ts + 1) << "' at index " << ts - ptr
+ << " not supported in a character class.";
throw ParseError(str.str());
}
action unsupportedProperty {
};
'\\o{' [0-7]+ '}' => {
- string oct((const char *)ts + 3, te - ts - 4);
+ string oct(ts + 3, te - ts - 4);
long int val = strtol(oct.c_str(), nullptr, 8);
if ((!mode.utf8 && val > 255) || val > MAX_UNICODE) {
throw LocatedParseError("Value in \\o{...} sequence is too large");
};
# Unicode Hex
'\\x{' xdigit+ '}' => {
- string hex((const char *)ts + 3, te - ts - 4);
+ string hex(ts + 3, te - ts - 4);
long int val = strtol(hex.c_str(), nullptr, 16);
if (val > MAX_UNICODE) {
throw LocatedParseError("Value in \\x{...} sequence is too large");
# Literal character
(any - ']') => {
- currentCls->add(*ts);
+ currentCls->add((u8)*ts);
};
']' => {
// Otherwise, we interpret the first three digits as an
// octal escape, and the remaining characters stand for
// themselves as literals.
- const u8 *s = ts;
+ const char *s = ts;
unsigned int accum = 0;
unsigned int oct_digits = 0;
assert(*s == '\\'); // token starts at backslash
throw LocatedParseError("Invalid reference after \\g");
};
'\\o{' [0-7]+ '}' => {
- string oct((const char *)ts + 3, te - ts - 4);
+ string oct(ts + 3, te - ts - 4);
long int val = strtol(oct.c_str(), nullptr, 8);
if ((!mode.utf8 && val > 255) || val > MAX_UNICODE) {
throw LocatedParseError("Value in \\o{...} sequence is too large");
};
# Unicode Hex
'\\x{' xdigit+ '}' => {
- string hex((const char *)ts + 3, te - ts - 4);
+ string hex(ts + 3, te - ts - 4);
long int val = strtol(hex.c_str(), nullptr, 16);
if (val > MAX_UNICODE) {
throw LocatedParseError("Value in \\x{...} sequence is too large");
# A bunch of unsupported (for now) escapes
escapedUnsupported => {
ostringstream str;
- str << "'\\" << (char)*(ts + 1) << "' at index "
- << ts - ptr << " not supported.";
+ str << "'\\" << *(ts + 1) << "' at index " << ts - ptr
+ << " not supported.";
throw ParseError(str.str());
};
%% write data nofinal;
/** \brief Main parser call, returns root Component or nullptr. */
-unique_ptr<Component> parse(const char *c_ptr, ParseMode &globalMode) {
- assert(c_ptr);
+unique_ptr<Component> parse(const char *ptr, ParseMode &globalMode) {
+ assert(ptr);
- const u8 *ptr = (const u8 *const)c_ptr;
- const u8 *p = ptr;
- const u8 *pe = ptr + strlen(c_ptr);
+ const char *p = ptr;
+ const char *pe = ptr + strlen(ptr);
// First, read the control verbs, set any global mode flags and move the
// ptr forward.
- p = (const u8 *)read_control_verbs((const char *)p, (const char *)pe,
- globalMode);
+ p = read_control_verbs(p, pe, globalMode);
- const u8 *eof = pe;
+ const char *eof = pe;
int cs;
UNUSED int act;
int top;
vector<int> stack;
- const u8 *ts, *te;
+ const char *ts, *te;
unichar accumulator = 0;
unichar octAccumulator = 0; /* required as we are also accumulating for
* back ref when looking for octals */
bool inCharClassEarly = false;
// Location at which the current character class began.
- const u8 *currentClsBegin = p;
+ const char *currentClsBegin = p;
// We throw exceptions on various parsing failures beyond this point: we
// use a try/catch block here to clean up our allocated memory before we