From: Markus Scherer Date: Fri, 10 Jan 2014 21:41:03 +0000 (+0000) Subject: ICU-10499 genrb use explicit UnicodeString constructors X-Git-Tag: milestone-59-0-1~2281 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed3bb51647c03aac3f7959e330d058d05830c021;p=icu ICU-10499 genrb use explicit UnicodeString constructors X-SVN-Rev: 34867 --- diff --git a/icu4c/source/tools/genrb/parse.cpp b/icu4c/source/tools/genrb/parse.cpp index ab7bcca23d4..864c874b96c 100644 --- a/icu4c/source/tools/genrb/parse.cpp +++ b/icu4c/source/tools/genrb/parse.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2013, International Business Machines +* Copyright (C) 1998-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -18,6 +18,16 @@ ******************************************************************************* */ +// Safer use of UnicodeString. +#ifndef UNISTR_FROM_CHAR_EXPLICIT +# define UNISTR_FROM_CHAR_EXPLICIT explicit +#endif + +// Less important, but still a good idea. +#ifndef UNISTR_FROM_STRING_EXPLICIT +# define UNISTR_FROM_STRING_EXPLICIT explicit +#endif + #include "ucol_imp.h" #include "parse.h" #include "errmsg.h" diff --git a/icu4c/source/tools/genrb/prscmnts.cpp b/icu4c/source/tools/genrb/prscmnts.cpp index 758cf831cee..af771313477 100644 --- a/icu4c/source/tools/genrb/prscmnts.cpp +++ b/icu4c/source/tools/genrb/prscmnts.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2003-2007, International Business Machines + * Copyright (C) 2003-2014, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * @@ -13,6 +13,16 @@ ******************************************************************************* */ +// Safer use of UnicodeString. +#ifndef UNISTR_FROM_CHAR_EXPLICIT +# define UNISTR_FROM_CHAR_EXPLICIT explicit +#endif + +// Less important, but still a good idea. +#ifndef UNISTR_FROM_STRING_EXPLICIT +# define UNISTR_FROM_STRING_EXPLICIT explicit +#endif + #include "unicode/regex.h" #include "unicode/unistr.h" #include "unicode/parseerr.h" @@ -57,18 +67,18 @@ removeText(UChar *source, int32_t srcLen, } U_CFUNC int32_t trim(UChar *src, int32_t srcLen, UErrorCode *status){ - srcLen = removeText(src, srcLen, "^[ \\r\\n]+ ", 0, "", status); // remove leading new lines - srcLen = removeText(src, srcLen, "^\\s+", 0, "", status); // remove leading spaces - srcLen = removeText(src, srcLen, "\\s+$", 0, "", status); // remvoe trailing spcaes + srcLen = removeText(src, srcLen, UnicodeString("^[ \\r\\n]+ "), 0, UnicodeString(), status); // remove leading new lines + srcLen = removeText(src, srcLen, UnicodeString("^\\s+"), 0, UnicodeString(), status); // remove leading spaces + srcLen = removeText(src, srcLen, UnicodeString("\\s+$"), 0, UnicodeString(), status); // remvoe trailing spcaes return srcLen; } U_CFUNC int32_t removeCmtText(UChar* source, int32_t srcLen, UErrorCode* status){ srcLen = trim(source, srcLen, status); - UnicodeString patString = "^\\s*?\\*\\s*?"; // remove pattern like " * " at the begining of the line - srcLen = removeText(source, srcLen, patString, UREGEX_MULTILINE, "", status); - return removeText(source, srcLen, "[ \\r\\n]+", 0, " ", status);// remove new lines; + UnicodeString patString("^\\s*?\\*\\s*?"); // remove pattern like " * " at the begining of the line + srcLen = removeText(source, srcLen, patString, UREGEX_MULTILINE, UnicodeString(), status); + return removeText(source, srcLen, UnicodeString("[ \\r\\n]+"), 0, UnicodeString(" "), status);// remove new lines; } U_CFUNC int32_t @@ -82,7 +92,7 @@ getText(const UChar* source, int32_t srcLen, } UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile("@", 0, *status); + RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), 0, *status); UnicodeString src (source,srcLen); if (U_FAILURE(*status)) { @@ -117,7 +127,7 @@ getDescription( const UChar* source, int32_t srcLen, } UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile("@", UREGEX_MULTILINE, *status); + RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); UnicodeString src(source, srcLen); if (U_FAILURE(*status)) { @@ -141,7 +151,7 @@ getCount(const UChar* source, int32_t srcLen, } UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile("@", UREGEX_MULTILINE, *status); + RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); UnicodeString src (source, srcLen); @@ -150,7 +160,7 @@ getCount(const UChar* source, int32_t srcLen, } int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); - RegexMatcher matcher(patternStrings[option], UREGEX_DOTALL, *status); + RegexMatcher matcher(UnicodeString(patternStrings[option]), UREGEX_DOTALL, *status); if (U_FAILURE(*status)) { return 0; } @@ -180,7 +190,7 @@ getAt(const UChar* source, int32_t srcLen, } UnicodeString stringArray[MAX_SPLIT_STRINGS]; - RegexPattern *pattern = RegexPattern::compile("@", UREGEX_MULTILINE, *status); + RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); UnicodeString src (source, srcLen); @@ -189,7 +199,7 @@ getAt(const UChar* source, int32_t srcLen, } int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); - RegexMatcher matcher(patternStrings[option], UREGEX_DOTALL, *status); + RegexMatcher matcher(UnicodeString(patternStrings[option]), UREGEX_DOTALL, *status); if (U_FAILURE(*status)) { return 0; } @@ -213,7 +223,7 @@ U_CFUNC int32_t getTranslate( const UChar* source, int32_t srcLen, UChar** dest, int32_t destCapacity, UErrorCode* status){ - UnicodeString notePatternString = "^translate\\s*?(.*)"; + UnicodeString notePatternString("^translate\\s*?(.*)"); int32_t destLen = getText(source, srcLen, dest, destCapacity, notePatternString, status); return trim(*dest, destLen, status); @@ -224,7 +234,7 @@ getNote(const UChar* source, int32_t srcLen, UChar** dest, int32_t destCapacity, UErrorCode* status){ - UnicodeString notePatternString = "^note\\s*?(.*)"; + UnicodeString notePatternString("^note\\s*?(.*)"); int32_t destLen = getText(source, srcLen, dest, destCapacity, notePatternString, status); return trim(*dest, destLen, status); diff --git a/icu4c/source/tools/genrb/wrtxml.cpp b/icu4c/source/tools/genrb/wrtxml.cpp index 4a642b9eb87..c1031208bd1 100644 --- a/icu4c/source/tools/genrb/wrtxml.cpp +++ b/icu4c/source/tools/genrb/wrtxml.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2002-2012, International Business Machines +* Copyright (C) 2002-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -16,6 +16,17 @@ * ******************************************************************************* */ + +// Safer use of UnicodeString. +#ifndef UNISTR_FROM_CHAR_EXPLICIT +# define UNISTR_FROM_CHAR_EXPLICIT explicit +#endif + +// Less important, but still a good idea. +#ifndef UNISTR_FROM_STRING_EXPLICIT +# define UNISTR_FROM_STRING_EXPLICIT explicit +#endif + #include "reslist.h" #include "unewdata.h" #include "unicode/ures.h" @@ -1121,7 +1132,7 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu *status = U_FILE_ACCESS_ERROR; goto cleanup_bundle_write_xml; } - write_utf8_file(out, xmlHeader); + write_utf8_file(out, UnicodeString(xmlHeader)); if(outputEnc && *outputEnc!='\0'){ /* store the output encoding */ @@ -1131,9 +1142,9 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu goto cleanup_bundle_write_xml; } } - write_utf8_file(out, bundleStart); + write_utf8_file(out, UnicodeString(bundleStart)); write_tabs(out); - write_utf8_file(out, fileStart); + write_utf8_file(out, UnicodeString(fileStart)); /* check if lang and language are the same */ if(language != NULL && uprv_strcmp(lang, srBundle->fLocale)!=0){ fprintf(stderr,"Warning: The top level tag in the resource and language specified are not the same. Please check the input.\n"); @@ -1151,12 +1162,12 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu tabCount += 1; write_tabs(out); - write_utf8_file(out, headerStart); + write_utf8_file(out, UnicodeString(headerStart)); tabCount += 1; write_tabs(out); - write_utf8_file(out, tool_start); + write_utf8_file(out, UnicodeString(tool_start)); printAttribute("tool-id", tool_id, (int32_t) uprv_strlen(tool_id)); printAttribute("tool-name", tool_name, (int32_t) uprv_strlen(tool_name)); write_utf8_file(out, UnicodeString("/>\n"));