From ca871a3193a03d01323244e5499fbda41ae17108 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 4 Apr 2007 10:15:27 +0000 Subject: 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 --- pjlib-util/src/pjlib-util/scanner.c | 32 +++++++++++++++++++++++++------- pjlib-util/src/pjlib-util/xml.c | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'pjlib-util/src') 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; -- cgit v1.2.3