Changeset 1145


Ignore:
Timestamp:
Apr 4, 2007 10:15:27 AM (17 years ago)
Author:
bennylp
Message:

Ticket #208: Allow single quotes for attributes in XML (thanks Tory Patnoe)

Location:
pjproject/trunk/pjlib-util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/include/pjlib-util/scanner.h

    r754 r1145  
    351351 
    352352/**  
     353 * Get characters between quotes. If current input doesn't match begin_quote, 
     354 * syntax error will be thrown. Note that the resulting string will contain 
     355 * the enclosing quote. 
     356 * 
     357 * @param scanner       The scanner. 
     358 * @param begin_quotes  The character array to begin the quotes. For example, 
     359 *                      the two characters " and '. 
     360 * @param end_quotes    The character array to end the quotes. The position 
     361 *                      found in the begin_quotes array will be used to match 
     362 *                      the end quotes. So if the begin_quotes was the array 
     363 *                      of "'< the end_quotes should be "'>. If begin_array 
     364 *                      matched the ' then the end_quotes will look for ' to 
     365 *                      match at the end. 
     366 * @param qsize         The size of the begin_quotes and end_quotes arrays. 
     367 * @param out           String to store the result. 
     368 */ 
     369PJ_DECL(void) pj_scan_get_quotes(pj_scanner *scanner, 
     370                                 const char *begin_quotes, 
     371                                 const char *end_quotes, int qsize, 
     372                                 pj_str_t *out); 
     373 
     374 
     375/** 
    353376 * Get N characters from the scanner. 
    354377 * 
  • pjproject/trunk/pjlib-util/src/pjlib-util/scanner.c

    r974 r1145  
    340340 
    341341PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner, 
    342                                  int begin_quote, int end_quote,  
    343                                  pj_str_t *out) 
    344 { 
    345     register char *s = scanner->curptr; 
    346      
     342                                int begin_quote, int end_quote,  
     343                                pj_str_t *out) 
     344{ 
     345    pj_scan_get_quotes(scanner, (char*)&begin_quote, (char*)&end_quote, 1, out); 
     346} 
     347 
     348PJ_DEF(void) pj_scan_get_quotes(pj_scanner *scanner, 
     349                                const char *begin_quote, const char *end_quote, 
     350                                int qsize, pj_str_t *out) 
     351{ 
     352    register char *s = scanner->curptr; 
     353    int qpair = -1; 
     354    int i; 
     355 
     356    pj_assert(qsize > 0); 
     357 
    347358    /* Check and eat the begin_quote. */ 
    348     if (*s != begin_quote) { 
     359    for (i = 0; i < qsize; ++i) { 
     360        if (*s == begin_quote[i]) { 
     361            qpair = i; 
     362            break; 
     363        } 
     364    } 
     365    if (qpair == -1) { 
    349366        pj_scan_syntax_err(scanner); 
    350367        return; 
     
    356373    do { 
    357374        /* loop until end_quote is found. */ 
    358         while (*s && *s != '\n' && *s != end_quote) { 
     375        while (*s && *s != '\n' && *s != end_quote[qpair]) { 
    359376            ++s; 
    360377        } 
    361378 
    362379        /* check that no backslash character precedes the end_quote. */ 
    363         if (*s == end_quote) { 
     380        if (*s == end_quote[qpair]) { 
    364381            if (*(s-1) == '\\') { 
    365382                if (s-2 == scanner->begin) { 
     
    390407 
    391408    /* Check and eat the end quote. */ 
    392     if (*s != end_quote) { 
     409    if (*s != end_quote[qpair]) { 
    393410        pj_scan_syntax_err(scanner); 
    394411        return; 
     
    404421    } 
    405422} 
     423 
    406424 
    407425PJ_DEF(void) pj_scan_get_n( pj_scanner *scanner, 
  • pjproject/trunk/pjlib-util/src/pjlib-util/xml.c

    r974 r1145  
    109109        if (*scanner->curptr == '=') { 
    110110            pj_scan_get_char( scanner ); 
    111             pj_scan_get_quote(scanner, '"', '"', &attr->value); 
     111            pj_scan_get_quotes(scanner, "\"'", "\"'", 2, &attr->value); 
    112112            /* remove quote characters */ 
    113113            ++attr->value.ptr; 
Note: See TracChangeset for help on using the changeset viewer.