diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/xml/XSLTUnicodeSort.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/xml/XSLTUnicodeSort.cpp')
-rw-r--r-- | Source/WebCore/xml/XSLTUnicodeSort.cpp | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/Source/WebCore/xml/XSLTUnicodeSort.cpp b/Source/WebCore/xml/XSLTUnicodeSort.cpp index a8537340a..142e960a3 100644 --- a/Source/WebCore/xml/XSLTUnicodeSort.cpp +++ b/Source/WebCore/xml/XSLTUnicodeSort.cpp @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -33,14 +33,15 @@ #include <libxslt/templates.h> #include <libxslt/xsltutils.h> -#include <wtf/text/WTFString.h> +#include <wtf/StringExtras.h> +#include <wtf/Vector.h> #include <wtf/unicode/Collator.h> -#if PLATFORM(MAC) +#if OS(DARWIN) && !PLATFORM(GTK) #include "SoftLinking.h" #endif -#if PLATFORM(MAC) +#if OS(DARWIN) && !PLATFORM(GTK) SOFT_LINK_LIBRARY(libxslt) SOFT_LINK(libxslt, xsltComputeSortResult, xmlXPathObjectPtr*, (xsltTransformContextPtr ctxt, xmlNodePtr sort), (ctxt, sort)) @@ -52,15 +53,19 @@ void xsltTransformErrorTrampoline(xsltTransformContextPtr context, xsltStyleshee { va_list args; va_start(args, message); - char* messageWithArgs; - vasprintf(&messageWithArgs, message, args); + + va_list preflightArgs; + va_copy(preflightArgs, args); + size_t stringLength = vsnprintf(nullptr, 0, message, preflightArgs); + va_end(preflightArgs); + + Vector<char, 1024> buffer(stringLength + 1); + vsnprintf(buffer.data(), stringLength + 1, message, args); va_end(args); static void (*xsltTransformErrorPointer)(xsltTransformContextPtr, xsltStylesheetPtr, xmlNodePtr, const char*, ...) WTF_ATTRIBUTE_PRINTF(4, 5) = reinterpret_cast<void (*)(xsltTransformContextPtr, xsltStylesheetPtr, xmlNodePtr, const char*, ...)>(dlsym(libxsltLibrary(), "xsltTransformError")); - xsltTransformErrorPointer(context, style, node, "%s", messageWithArgs); - - free(messageWithArgs); + xsltTransformErrorPointer(context, style, node, "%s", buffer.data()); } #define xsltTransformError xsltTransformErrorTrampoline @@ -162,10 +167,9 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in // We are passing a language identifier to a function that expects a locale identifier. // The implementation of Collator should be lenient, and accept both "en-US" and "en_US", for example. - // This lets an author to really specify sorting rules, e.g. "de_DE@collation=phonebook", which isn't + // This lets an author specify sorting rules, e.g. "de_DE@collation=phonebook", which isn't // possible with language alone. - Collator collator(comp->has_lang ? (const char*)comp->lang : "en"); - collator.setOrderLowerFirst(comp->lower_first); + Collator collator(comp->has_lang ? reinterpret_cast<const char*>(comp->lang) : "en", comp->lower_first); /* Shell's sort of node-set */ for (incr = len / 2; incr > 0; incr /= 2) { @@ -195,11 +199,8 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in results[j + incr]->floatval) tst = 1; else tst = -1; - } else { - String str1 = String::fromUTF8((const char*)results[j]->stringval); - String str2 = String::fromUTF8((const char*)results[j + incr]->stringval); - tst = collator.collate(str1.deprecatedCharacters(), str1.length(), str2.deprecatedCharacters(), str2.length()); - } + } else + tst = collator.collateUTF8(reinterpret_cast<const char*>(results[j]->stringval), reinterpret_cast<const char*>(results[j + incr]->stringval)); if (descending) tst = -tst; } @@ -250,11 +251,8 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in res[j + incr]->floatval) tst = 1; else tst = -1; - } else { - String str1 = String::fromUTF8((const char*)res[j]->stringval); - String str2 = String::fromUTF8((const char*)res[j + incr]->stringval); - tst = collator.collate(str1.deprecatedCharacters(), str1.length(), str2.deprecatedCharacters(), str2.length()); - } + } else + tst = collator.collateUTF8(reinterpret_cast<const char*>(res[j]->stringval), reinterpret_cast<const char*>(res[j + incr]->stringval)); if (desc) tst = -tst; } |