diff options
author | David Robillard <d@drobilla.net> | 2011-01-21 19:34:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-21 19:34:33 +0000 |
commit | 846e313f10b21575119037581fbf985ef0793eb3 (patch) | |
tree | d4306b4bcaa13b5a7a814ee30e718f31bfa46959 /src/reader.c | |
parent | 2a45d353d555e65087d7ce623da42d1ac10f2493 (diff) | |
download | serd-846e313f10b21575119037581fbf985ef0793eb3.tar.gz serd-846e313f10b21575119037581fbf985ef0793eb3.tar.bz2 serd-846e313f10b21575119037581fbf985ef0793eb3.zip |
Faster/terser/more consistent character escape reading.
git-svn-id: http://svn.drobilla.net/serd/trunk@25 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r-- | src/reader.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/src/reader.c b/src/reader.c index 10175d45..1df3c110 100644 --- a/src/reader.c +++ b/src/reader.c @@ -392,6 +392,51 @@ read_character_escape(SerdReader parser, Ref dest) } } +static inline bool +read_echaracter_escape(SerdReader parser, Ref dest) +{ + switch (peek_byte(parser)) { + case 't': + eat_byte(parser, 't'); + push_byte(parser, dest, '\t'); + return true; + case 'n': + eat_byte(parser, 'n'); + push_byte(parser, dest, '\n'); + return true; + case 'r': + eat_byte(parser, 'r'); + push_byte(parser, dest, '\r'); + return true; + default: + return read_character_escape(parser, dest); + } +} + +static inline bool +read_scharacter_escape(SerdReader parser, Ref dest) +{ + switch (peek_byte(parser)) { + case '"': + push_byte(parser, dest, eat_byte(parser, '"')); + return true; + default: + return read_echaracter_escape(parser, dest); + } +} + +static inline bool +read_ucharacter_escape(SerdReader parser, Ref dest) +{ + switch (peek_byte(parser)) { + case '>': + push_byte(parser, dest, eat_byte(parser, '>')); + return true; + default: + return read_echaracter_escape(parser, dest); + } +} + // [38] character ::= '\u' hex hex hex hex // | '\U' hex hex hex hex hex hex hex hex // | '\\' @@ -422,30 +467,6 @@ read_character(SerdReader parser, Ref dest) } } -static inline bool -read_echaracter_escape(SerdReader parser, Ref dest) -{ - if (read_character_escape(parser, dest)) { - return true; - } - switch (peek_byte(parser)) { - case 't': - eat_byte(parser, 't'); - push_byte(parser, dest, '\t'); - return true; - case 'n': - eat_byte(parser, 'n'); - push_byte(parser, dest, '\n'); - return true; - case 'r': - eat_byte(parser, 'r'); - push_byte(parser, dest, '\r'); - return true; - default: - return false; - } -} - // [39] echaracter ::= character | '\t' | '\n' | '\r' static inline SerdStatus read_echaracter(SerdReader parser, Ref dest) @@ -465,30 +486,6 @@ read_echaracter(SerdReader parser, Ref dest) } } -static inline bool -read_scharacter_escape(SerdReader parser, Ref dest) -{ - if (read_echaracter_escape(parser, dest)) { - return true; - } else if (peek_byte(parser) == '"') { - push_byte(parser, dest, eat_byte(parser, '"')); - return true; - } - return false; -} - -static inline bool -read_ucharacter_escape(SerdReader parser, Ref dest) -{ - if (read_echaracter_escape(parser, dest)) { - return true; - } else if (peek_byte(parser) == '>') { - push_byte(parser, dest, eat_byte(parser, '>')); - return true; - } - return false; -} - // [43] lcharacter ::= echaracter | '\"' | #x9 | #xA | #xD static inline SerdStatus read_lcharacter(SerdReader parser, Ref dest) |