Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.
Commit message: Tweaked trim_* API as a prerequisite for hexBinary changes. Other minor changes. Requested reviews: Paul J. Lucas (paul-lucas) For more details, see: https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/153875 Tweaked trim_* API as a prerequisite for hexBinary changes. Other minor changes. -- https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/153875 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/parser/symbol_table.cpp' --- src/compiler/parser/symbol_table.cpp 2013-02-07 17:24:36 +0000 +++ src/compiler/parser/symbol_table.cpp 2013-03-18 17:13:24 +0000 @@ -32,15 +32,10 @@ namespace zorba { -/** - * Whitespace characters used in the functions below - */ -static const char* whitespace = " \t\r\n\f\v"; - - -static bool decode_string(const char *yytext, uint32_t yyleng, string *result) { + +static bool decode_string(const char *yytext, size_t yyleng, string *result) { char delim = yytext [0]; - uint32_t i; + size_t i; for (i = 1; i + 1 < yyleng; i++) { char ch = yytext [i]; if (ch == '&') { @@ -55,7 +50,7 @@ return true; } -symbol_table::symbol_table(uint32_t initial_heapsize) +symbol_table::symbol_table(size_t initial_heapsize) : heap(initial_heapsize), last_qname(-1) @@ -66,14 +61,14 @@ { } -uint32_t symbol_table::size() const +size_t symbol_table::size() const { - return (uint32_t)heap.size(); + return (size_t)heap.size(); } // bool attribute == true when an attribute value is normalized -static void normalize_eol(const char *text, uint32_t length, string *out, bool attribute = false) { - uint32_t i; +static void normalize_eol(const char *text, size_t length, string *out, bool attribute = false) { + size_t i; out->reserve (length + 1); char lastCh = '\0'; for (i = 0; i < length; i++) { @@ -93,7 +88,7 @@ } // normalizationType == 2 is used for normalizing attribute values -off_t symbol_table::put(char const* text, uint32_t length, int normalizationType) +off_t symbol_table::put(char const* text, size_t length, int normalizationType) { string normStr; if (normalizationType == 1 || normalizationType == 2) @@ -106,24 +101,22 @@ return heap.put(text, 0, length); } -off_t symbol_table::put_ncname(char const* text, uint32_t length) +off_t symbol_table::put_ncname(char const* text, size_t length) { last_qname = heap.put(text, 0, length); return last_qname; } -off_t symbol_table::put_qname(char const* text, uint32_t length, bool do_trim_start, bool do_trim_end, bool is_eqname) +off_t symbol_table::put_qname(char const* text, size_t length, bool do_trim_start, bool do_trim_end, bool is_eqname) { if (do_trim_start) { - char const* temp = ascii::trim_start(text, length, whitespace); - length -= (temp-text); - text = temp; + text = ascii::trim_start_whitespace(text, &length); } if (do_trim_end) { - length = ascii::trim_end(text, length, whitespace); + length = ascii::trim_end_whitespace(text, length); } if (!is_eqname) @@ -148,15 +141,10 @@ return last_qname; } -off_t symbol_table::put_uri(char const* text, uint32_t length) +off_t symbol_table::put_uri(char const* text, size_t length) { - // trim start - char const* temp = ascii::trim_start(text, length, whitespace); - length -= (temp-text); - text = temp; - - // trim end - length = ascii::trim_end(text, length, whitespace); + // trim whitespace + text = ascii::trim_whitespace(text, &length); // normalize whitespace string result; @@ -167,12 +155,12 @@ return heap.put (result.c_str (), 0, result.length ()); } -off_t symbol_table::put_varname(char const* text, uint32_t length) +off_t symbol_table::put_varname(char const* text, size_t length) { return heap.put(text, 0, length); } -off_t symbol_table::put_entityref(char const* text, uint32_t length) +off_t symbol_table::put_entityref(char const* text, size_t length) { string result; if (xml::parse_entity (text + 1, &result) < 0) @@ -180,12 +168,12 @@ return heap.put(result.c_str(), 0, result.size ()); } -off_t symbol_table::put_charref(char const* text, uint32_t length) +off_t symbol_table::put_charref(char const* text, size_t length) { return heap.put (text + 1, 0, length - 1); } -off_t symbol_table::put_stringlit(char const* yytext, uint32_t yyleng) +off_t symbol_table::put_stringlit(char const* yytext, size_t yyleng) { string eolNorm; normalize_eol (yytext, yyleng, &eolNorm); @@ -195,7 +183,7 @@ return heap.put (result.c_str (), 0, result.length ()); } -off_t symbol_table::put_commentcontent(char const* yytext, uint32_t yyleng) +off_t symbol_table::put_commentcontent(char const* yytext, size_t yyleng) { string eolNorm; normalize_eol (yytext, yyleng, &eolNorm); @@ -203,13 +191,13 @@ return heap.put (yytext, 0, yyleng); } -xs_decimal* symbol_table::decimalval(char const* text, uint32_t length) +xs_decimal* symbol_table::decimalval(char const* text, size_t length) { return new xs_decimal(text); } // Will return NULL if std::range_error is raised -xs_double* symbol_table::doubleval(char const* text, uint32_t length) +xs_double* symbol_table::doubleval(char const* text, size_t length) { try { return new xs_double(text); @@ -220,7 +208,7 @@ } // Will return NULL if std::range_error is raised -xs_integer* symbol_table::integerval(char const* text, uint32_t length) +xs_integer* symbol_table::integerval(char const* text, size_t length) { try { return new xs_integer(text); @@ -232,7 +220,7 @@ std::string symbol_table::get(off_t id) { - uint32_t n = heap.get_length0(id); + size_t n = heap.get_length0(id); char *buf; buf = (char*)malloc(n+1); heap.get0(id, buf, 0, n+1); === modified file 'src/compiler/parser/symbol_table.h' --- src/compiler/parser/symbol_table.h 2013-02-07 17:24:36 +0000 +++ src/compiler/parser/symbol_table.h 2013-03-18 17:13:24 +0000 @@ -33,7 +33,7 @@ off_t last_qname; // will store the offset of the last added qname or ncname public: // ctor,dtor - symbol_table(uint32_t initial_heapsize=1024); + symbol_table(size_t initial_heapsize=1024); ~symbol_table(); public: // table interface @@ -44,27 +44,27 @@ * normalizationType = 1 -- EOL normalization * normalizationType = 2 -- Attribute value normalization */ - off_t put(char const* text, uint32_t length, int normalizationType = 0); + off_t put(char const* text, size_t length, int normalizationType = 0); - off_t put_ncname(char const* text, uint32_t length); - off_t put_qname(char const* text, uint32_t length, + off_t put_ncname(char const* text, size_t length); + off_t put_qname(char const* text, size_t length, bool do_trim_start = false, bool do_trim_end = false, bool is_eqname = false); - off_t put_uri(char const* text, uint32_t length); - off_t put_varname(char const* text, uint32_t length); - off_t put_entityref(char const* text, uint32_t length); - off_t put_charref(char const* text, uint32_t length); - off_t put_stringlit(char const* text, uint32_t length); - off_t put_commentcontent(char const* text, uint32_t length); + off_t put_uri(char const* text, size_t length); + off_t put_varname(char const* text, size_t length); + off_t put_entityref(char const* text, size_t length); + off_t put_charref(char const* text, size_t length); + off_t put_stringlit(char const* text, size_t length); + off_t put_commentcontent(char const* text, size_t length); - uint32_t size() const; + size_t size() const; std::string get(off_t id); std::string get_last_qname(); // It will return the last added qname or ncname - xs_decimal* decimalval(char const* text, uint32_t length); - xs_double* doubleval(char const* text, uint32_t length); // Will return NULL if std::range_error is raised - xs_integer* integerval(char const* text, uint32_t length); // Will return NULL if std::range_error is raised + xs_decimal* decimalval(char const* text, size_t length); + xs_double* doubleval(char const* text, size_t length); // Will return NULL if std::range_error is raised + xs_integer* integerval(char const* text, size_t length); // Will return NULL if std::range_error is raised }; === modified file 'src/util/ascii_util.cpp' --- src/util/ascii_util.cpp 2013-03-12 00:02:07 +0000 +++ src/util/ascii_util.cpp 2013-03-18 17:13:24 +0000 @@ -126,8 +126,8 @@ return s; } -char const* trim_start( char const *s, size_type s_len, char const *chars ) { - for ( ; s_len-- > 0; ++s ) { +char const* trim_start( char const *s, size_type *s_len, char const *chars ) { + for ( ; *s_len > 0; --*s_len, ++s ) { if ( !std::strchr( chars, *s ) ) break; } === modified file 'src/util/ascii_util.h' --- src/util/ascii_util.h 2013-03-12 03:26:55 +0000 +++ src/util/ascii_util.h 2013-03-18 17:13:24 +0000 @@ -888,12 +888,27 @@ * Skips leading specified characters. * * @param s The string to trim. + * @param s_len A pointer to the length of \a s. It is updated with the new + * length. + * @param chars The characters to trim. + * @return Returns a pointer to the first character in \a s that is not among + * the characters in \a chars. + */ +char const* trim_start( char const *s, size_type *s_len, char const *chars ); + +/** + * Skips leading specified characters. + * + * @param s The string to trim. * @param s_len The length of \a s. * @param chars The characters to trim. * @return Returns a pointer to the first character in \a s that is not among * the characters in \a chars. */ -char const* trim_start( char const *s, size_type s_len, char const *chars ); +inline char const* trim_start( char const *s, size_type s_len, + char const *chars ) { + return trim_start( s, &s_len, chars ); +} /** * Removes all leading specified characters. @@ -937,6 +952,19 @@ * Skips leading whitespace characters. * * @param s The string to trim. + * @param s_len A pointer to the length of \a s. It is updated with the new + * length. + * @return Returns a pointer to the first character in \a s that is not a + * whitespace character. + */ +inline char const* trim_start_whitespace( char const *s, size_type *s_len ) { + return trim_start( s, s_len, whitespace ); +} + +/** + * Skips leading whitespace characters. + * + * @param s The string to trim. * @param s_len The length of \a s. * @return Returns a pointer to the first character in \a s that is not a * whitespace character. @@ -1064,6 +1092,21 @@ } /** + * Removed sll leading and trailing whitespace. + * + * @param s The input C string. + * @param s_len A pointer to the length of \a s. It is updated with the new + * length. + * @return Returns a pointer to the first character in \a s that is not + * whitespace. + */ +inline char const* trim_whitespace( char const *s, size_type *s_len ) { + s = trim_start_whitespace( s, s_len ); + *s_len = trim_end_whitespace( s, *s_len ); + return s; +} + +/** * Removes all leading and trailing whitespace. * * @tparam InputStringType The input string type. === modified file 'src/zorbatypes/schema_types.h' --- src/zorbatypes/schema_types.h 2013-03-12 17:03:31 +0000 +++ src/zorbatypes/schema_types.h 2013-03-18 17:13:24 +0000 @@ -52,7 +52,6 @@ typedef Integer xs_nonPositiveInteger; // this isn't quite right either typedef UInteger xs_positiveInteger; typedef DateTime xs_time; -typedef UInteger xs_uinteger; // old, deprecated name typedef Duration xs_yearMonthDuration; /////////////////////////////////////////////////////////////////////////////// === modified file 'src/zorbautils/locale.cpp' --- src/zorbautils/locale.cpp 2013-02-07 17:24:36 +0000 +++ src/zorbautils/locale.cpp 2013-03-18 17:13:24 +0000 @@ -204,7 +204,8 @@ init = true; } - return IsValidLocaleName_ptr ? IsValidLocaleName_ptr( lpLocaleName )!=0 : false; + return IsValidLocaleName_ptr ? + !!IsValidLocaleName_ptr( lpLocaleName ) : false; } #else /* WIN32 */
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp