diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-04-04 10:15:27 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-04-04 10:15:27 +0000 |
commit | ca871a3193a03d01323244e5499fbda41ae17108 (patch) | |
tree | 6027887697a9fabc75c405dcaa57e7f3b1ff1b32 /pjlib-util | |
parent | aafa82d9e93387af71d2332d0a3d42222b17d0ec (diff) |
Ticket #208: Allow single quotes for attributes in XML (thanks Tory Patnoe)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1145 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util')
-rw-r--r-- | pjlib-util/include/pjlib-util/scanner.h | 23 | ||||
-rw-r--r-- | pjlib-util/src/pjlib-util/scanner.c | 32 | ||||
-rw-r--r-- | pjlib-util/src/pjlib-util/xml.c | 2 |
3 files changed, 49 insertions, 8 deletions
diff --git a/pjlib-util/include/pjlib-util/scanner.h b/pjlib-util/include/pjlib-util/scanner.h index b9812eca..71c4eb8e 100644 --- a/pjlib-util/include/pjlib-util/scanner.h +++ b/pjlib-util/include/pjlib-util/scanner.h @@ -350,6 +350,29 @@ PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner, pj_str_t *out); /** + * Get characters between quotes. If current input doesn't match begin_quote, + * syntax error will be thrown. Note that the resulting string will contain + * the enclosing quote. + * + * @param scanner The scanner. + * @param begin_quotes The character array to begin the quotes. For example, + * the two characters " and '. + * @param end_quotes The character array to end the quotes. The position + * found in the begin_quotes array will be used to match + * the end quotes. So if the begin_quotes was the array + * of "'< the end_quotes should be "'>. If begin_array + * matched the ' then the end_quotes will look for ' to + * match at the end. + * @param qsize The size of the begin_quotes and end_quotes arrays. + * @param out String to store the result. + */ +PJ_DECL(void) pj_scan_get_quotes(pj_scanner *scanner, + const char *begin_quotes, + const char *end_quotes, int qsize, + pj_str_t *out); + + +/** * Get N characters from the scanner. * * @param scanner The scanner. diff --git a/pjlib-util/src/pjlib-util/scanner.c b/pjlib-util/src/pjlib-util/scanner.c index 77f189a7..c7a9cf9b 100644 --- a/pjlib-util/src/pjlib-util/scanner.c +++ b/pjlib-util/src/pjlib-util/scanner.c @@ -339,13 +339,30 @@ PJ_DEF(void) pj_scan_get_unescape( pj_scanner *scanner, PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner, - int begin_quote, int end_quote, - pj_str_t *out) + int begin_quote, int end_quote, + pj_str_t *out) +{ + pj_scan_get_quotes(scanner, (char*)&begin_quote, (char*)&end_quote, 1, out); +} + +PJ_DEF(void) pj_scan_get_quotes(pj_scanner *scanner, + const char *begin_quote, const char *end_quote, + int qsize, pj_str_t *out) { register char *s = scanner->curptr; - + int qpair = -1; + int i; + + pj_assert(qsize > 0); + /* Check and eat the begin_quote. */ - if (*s != begin_quote) { + for (i = 0; i < qsize; ++i) { + if (*s == begin_quote[i]) { + qpair = i; + break; + } + } + if (qpair == -1) { pj_scan_syntax_err(scanner); return; } @@ -355,12 +372,12 @@ PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner, */ do { /* loop until end_quote is found. */ - while (*s && *s != '\n' && *s != end_quote) { + while (*s && *s != '\n' && *s != end_quote[qpair]) { ++s; } /* check that no backslash character precedes the end_quote. */ - if (*s == end_quote) { + if (*s == end_quote[qpair]) { if (*(s-1) == '\\') { if (s-2 == scanner->begin) { break; @@ -389,7 +406,7 @@ PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner, } while (1); /* Check and eat the end quote. */ - if (*s != end_quote) { + if (*s != end_quote[qpair]) { pj_scan_syntax_err(scanner); return; } @@ -404,6 +421,7 @@ PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner, } } + PJ_DEF(void) pj_scan_get_n( pj_scanner *scanner, unsigned N, pj_str_t *out) { diff --git a/pjlib-util/src/pjlib-util/xml.c b/pjlib-util/src/pjlib-util/xml.c index b118a7da..8480f0ef 100644 --- a/pjlib-util/src/pjlib-util/xml.c +++ b/pjlib-util/src/pjlib-util/xml.c @@ -108,7 +108,7 @@ static pj_xml_node *xml_parse_node( pj_pool_t *pool, pj_scanner *scanner) pj_scan_get_until_chr( scanner, "=> \t", &attr->name); if (*scanner->curptr == '=') { pj_scan_get_char( scanner ); - pj_scan_get_quote(scanner, '"', '"', &attr->value); + pj_scan_get_quotes(scanner, "\"'", "\"'", 2, &attr->value); /* remove quote characters */ ++attr->value.ptr; attr->value.slen -= 2; |