diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp | 212 |
1 files changed, 98 insertions, 114 deletions
diff --git a/chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp b/chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp index 83342cb6900..c6d7486d4e0 100644 --- a/chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp +++ b/chromium/third_party/WebKit/Source/core/xml/XSLTUnicodeSort.cpp @@ -36,7 +36,13 @@ namespace WebCore { -// Based on default implementation from libxslt 1.1.22 and xsltICUSort.c example. +inline const xmlChar* toXMLChar(const char* string) +{ + return reinterpret_cast<const xmlChar*>(string); +} + +// Based on default implementation from libxslt 1.1.22 and xsltICUSort.c +// example. void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, int nbsorts) { #ifdef XSLT_REFACTORED @@ -44,124 +50,110 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in #else xsltStylePreCompPtr comp; #endif - xmlXPathObjectPtr *resultsTab[XSLT_MAX_SORT]; - xmlXPathObjectPtr *results = NULL, *res; - xmlNodeSetPtr list = NULL; - int descending, number, desc, numb; - int len = 0; - int i, j, incr; - int tst; + xmlXPathObjectPtr* resultsTab[XSLT_MAX_SORT]; + xmlXPathObjectPtr* results = 0; + xmlNodeSetPtr list = 0; int depth; xmlNodePtr node; - xmlXPathObjectPtr tmp; int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT]; - if ((ctxt == NULL) || (sorts == NULL) || (nbsorts <= 0) || - (nbsorts >= XSLT_MAX_SORT)) + if (!ctxt || !sorts || nbsorts <= 0 || nbsorts >= XSLT_MAX_SORT) return; - if (sorts[0] == NULL) + if (!sorts[0]) return; comp = static_cast<xsltStylePreComp*>(sorts[0]->psvi); - if (comp == NULL) + if (!comp) return; list = ctxt->nodeList; - if ((list == NULL) || (list->nodeNr <= 1)) - return; /* nothing to do */ + if (!list || list->nodeNr <= 1) + return; // Nothing to do. - for (j = 0; j < nbsorts; j++) { + for (int j = 0; j < nbsorts; ++j) { comp = static_cast<xsltStylePreComp*>(sorts[j]->psvi); tempstype[j] = 0; - if ((comp->stype == NULL) && (comp->has_stype != 0)) { - comp->stype = - xsltEvalAttrValueTemplate(ctxt, sorts[j], - (const xmlChar *) "data-type", - XSLT_NAMESPACE); - if (comp->stype != NULL) { + if (!comp->stype && comp->has_stype) { + comp->stype = xsltEvalAttrValueTemplate(ctxt, sorts[j], toXMLChar("data-type"), XSLT_NAMESPACE); + if (comp->stype) { tempstype[j] = 1; - if (xmlStrEqual(comp->stype, (const xmlChar *) "text")) + if (xmlStrEqual(comp->stype, toXMLChar("text"))) { comp->number = 0; - else if (xmlStrEqual(comp->stype, (const xmlChar *) "number")) + } else if (xmlStrEqual(comp->stype, toXMLChar("number"))) { comp->number = 1; - else { - xsltTransformError(ctxt, NULL, sorts[j], - "xsltDoSortFunction: no support for data-type = %s\n", - comp->stype); - comp->number = 0; /* use default */ + } else { + xsltTransformError(ctxt, 0, sorts[j], "xsltDoSortFunction: no support for data-type = %s\n", comp->stype); + comp->number = 0; // Use default. } } } temporder[j] = 0; - if ((comp->order == NULL) && (comp->has_order != 0)) { - comp->order = xsltEvalAttrValueTemplate(ctxt, sorts[j], - (const xmlChar *) "order", - XSLT_NAMESPACE); - if (comp->order != NULL) { + if (!comp->order && comp->has_order) { + comp->order = xsltEvalAttrValueTemplate(ctxt, sorts[j], toXMLChar("order"), XSLT_NAMESPACE); + if (comp->order) { temporder[j] = 1; - if (xmlStrEqual(comp->order, (const xmlChar *) "ascending")) + if (xmlStrEqual(comp->order, toXMLChar("ascending"))) { comp->descending = 0; - else if (xmlStrEqual(comp->order, - (const xmlChar *) "descending")) + } else if (xmlStrEqual(comp->order, toXMLChar("descending"))) { comp->descending = 1; - else { - xsltTransformError(ctxt, NULL, sorts[j], - "xsltDoSortFunction: invalid value %s for order\n", - comp->order); - comp->descending = 0; /* use default */ + } else { + xsltTransformError(ctxt, 0, sorts[j], "xsltDoSortFunction: invalid value %s for order\n", comp->order); + comp->descending = 0; // Use default. } } } } - len = list->nodeNr; + int len = list->nodeNr; resultsTab[0] = xsltComputeSortResult(ctxt, sorts[0]); - for (i = 1;i < XSLT_MAX_SORT;i++) - resultsTab[i] = NULL; + for (int i = 1; i < XSLT_MAX_SORT; ++i) + resultsTab[i] = 0; results = resultsTab[0]; comp = static_cast<xsltStylePreComp*>(sorts[0]->psvi); - descending = comp->descending; - number = comp->number; - if (results == NULL) + int descending = comp->descending; + int number = comp->number; + if (!results) return; - // 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 + // 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 // possible with language alone. - Collator collator(comp->has_lang ? (const char*)comp->lang : "en"); + Collator collator(comp->has_lang ? reinterpret_cast<const char*>(comp->lang) : "en"); collator.setOrderLowerFirst(comp->lower_first); - /* Shell's sort of node-set */ - for (incr = len / 2; incr > 0; incr /= 2) { - for (i = incr; i < len; i++) { - j = i - incr; - if (results[i] == NULL) + // Shell's sort of node-set. + for (int incr = len / 2; incr > 0; incr /= 2) { + for (int i = incr; i < len; ++i) { + int j = i - incr; + if (!results[i]) continue; while (j >= 0) { - if (results[j] == NULL) + int tst; + if (!results[j]) { tst = 1; - else { + } else { if (number) { - /* We make NaN smaller than number in accordance - with XSLT spec */ + // We make NaN smaller than number in accordance with + // XSLT spec. if (xmlXPathIsNaN(results[j]->floatval)) { if (xmlXPathIsNaN(results[j + incr]->floatval)) tst = 0; else tst = -1; - } else if (xmlXPathIsNaN(results[j + incr]->floatval)) + } else if (xmlXPathIsNaN(results[j + incr]->floatval)) { tst = 1; - else if (results[j]->floatval == - results[j + incr]->floatval) + } else if (results[j]->floatval == results[j + incr]->floatval) { tst = 0; - else if (results[j]->floatval > - results[j + incr]->floatval) + } else if (results[j]->floatval > results[j + incr]->floatval) { tst = 1; - else tst = -1; + } else { + tst = -1; + } } else { Vector<UChar> string1; Vector<UChar> string2; @@ -173,52 +165,45 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in tst = -tst; } if (tst == 0) { - /* - * Okay we need to use multi level sorts - */ + // Okay we need to use multi level sorts. depth = 1; while (depth < nbsorts) { - if (sorts[depth] == NULL) + if (!sorts[depth]) break; comp = static_cast<xsltStylePreComp*>(sorts[depth]->psvi); - if (comp == NULL) + if (!comp) break; - desc = comp->descending; - numb = comp->number; + int desc = comp->descending; + int numb = comp->number; - /* - * Compute the result of the next level for the - * full set, this might be optimized ... or not - */ - if (resultsTab[depth] == NULL) - resultsTab[depth] = xsltComputeSortResult(ctxt, - sorts[depth]); - res = resultsTab[depth]; - if (res == NULL) + // Compute the result of the next level for the full + // set, this might be optimized ... or not + if (!resultsTab[depth]) + resultsTab[depth] = xsltComputeSortResult(ctxt, sorts[depth]); + xmlXPathObjectPtr* res = resultsTab[depth]; + if (!res) break; - if (res[j] == NULL) { - if (res[j+incr] != NULL) + if (!res[j]) { + if (res[j + incr]) tst = 1; } else { if (numb) { - /* We make NaN smaller than number in - accordance with XSLT spec */ + // We make NaN smaller than number in accordance + // with XSLT spec. if (xmlXPathIsNaN(res[j]->floatval)) { - if (xmlXPathIsNaN(res[j + - incr]->floatval)) + if (xmlXPathIsNaN(res[j + incr]->floatval)) tst = 0; else tst = -1; - } else if (xmlXPathIsNaN(res[j + incr]-> - floatval)) + } else if (xmlXPathIsNaN(res[j + incr]->floatval)) { tst = 1; - else if (res[j]->floatval == res[j + incr]-> - floatval) + } else if (res[j]->floatval == res[j + incr]->floatval) { tst = 0; - else if (res[j]->floatval > - res[j + incr]->floatval) + } else if (res[j]->floatval > res[j + incr]->floatval) { tst = 1; - else tst = -1; + } else { + tst = -1; + } } else { Vector<UChar> string1; Vector<UChar> string2; @@ -230,10 +215,8 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in tst = -tst; } - /* - * if we still can't differenciate at this level - * try one level deeper. - */ + // if we still can't differenciate at this level try one + // level deeper. if (tst != 0) break; depth++; @@ -243,7 +226,7 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in tst = results[j]->index > results[j + incr]->index; } if (tst > 0) { - tmp = results[j]; + xmlXPathObjectPtr tmp = results[j]; results[j] = results[j + incr]; results[j + incr] = tmp; node = list->nodeTab[j]; @@ -251,37 +234,38 @@ void xsltUnicodeSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts, in list->nodeTab[j + incr] = node; depth = 1; while (depth < nbsorts) { - if (sorts[depth] == NULL) + if (!sorts[depth]) break; - if (resultsTab[depth] == NULL) + if (!resultsTab[depth]) break; - res = resultsTab[depth]; + xmlXPathObjectPtr* res = resultsTab[depth]; tmp = res[j]; res[j] = res[j + incr]; res[j + incr] = tmp; depth++; } j -= incr; - } else + } else { break; + } } } } - for (j = 0; j < nbsorts; j++) { + for (int j = 0; j < nbsorts; ++j) { comp = static_cast<xsltStylePreComp*>(sorts[j]->psvi); if (tempstype[j] == 1) { - /* The data-type needs to be recomputed each time */ - xmlFree((void *)(comp->stype)); - comp->stype = NULL; + // The data-type needs to be recomputed each time. + xmlFree(const_cast<xmlChar*>(comp->stype)); + comp->stype = 0; } if (temporder[j] == 1) { - /* The order needs to be recomputed each time */ - xmlFree((void *)(comp->order)); - comp->order = NULL; + // The order needs to be recomputed each time. + xmlFree(const_cast<xmlChar*>(comp->order)); + comp->order = 0; } - if (resultsTab[j] != NULL) { - for (i = 0;i < len;i++) + if (resultsTab[j]) { + for (int i = 0; i < len; ++i) xmlXPathFreeObject(resultsTab[j][i]); xmlFree(resultsTab[j]); } |