summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-20 14:31:18 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-20 22:44:39 +0000
commitaeee187c927c07f47a9e5886a417dcc58badefb6 (patch)
tree270351e970de6ac9f6530ca9c7448dc7b8c499e2 /core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
parentc16ab75eb98733c857723f9c2947c77a56b2bb02 (diff)
downloadpdfium-aeee187c927c07f47a9e5886a417dcc58badefb6.tar.xz
Remove hand-written bsearch from cfx_xmlsyntaxparser.cppchromium/3077
Convert IsXMLNameChar() to static method for easier testing without namespace pollution. Change-Id: I004557e74fde94d3582b0a2326e5e68b907b9690 Reviewed-on: https://pdfium-review.googlesource.com/4397 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/xml/cfx_xmlsyntaxparser.cpp')
-rw-r--r--core/fxcrt/xml/cfx_xmlsyntaxparser.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
index aa455d5971..ac3f1b5c5d 100644
--- a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
@@ -7,6 +7,7 @@
#include "core/fxcrt/xml/cfx_xmlsyntaxparser.h"
#include <algorithm>
+#include <iterator>
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -35,21 +36,6 @@ const FX_XMLNAMECHAR g_XMLNameChars[] = {
{0xF900, 0xFDCF, true}, {0xFDF0, 0xFFFD, true},
};
-bool IsXMLNameChar(wchar_t ch, bool bFirstChar) {
- int32_t iStart = 0;
- int32_t iEnd = FX_ArraySize(g_XMLNameChars) - 1;
- while (iStart <= iEnd) {
- int32_t iMid = (iStart + iEnd) / 2;
- if (ch < g_XMLNameChars[iMid].wStart) {
- iEnd = iMid - 1;
- } else if (ch > g_XMLNameChars[iMid].wEnd) {
- iStart = iMid + 1;
- } else {
- return bFirstChar ? g_XMLNameChars[iMid].bStartChar : true;
- }
- }
- return false;
-}
int32_t GetUTF8EncodeLength(const std::vector<wchar_t>& src,
FX_FILESIZE iSrcLen) {
@@ -79,6 +65,15 @@ int32_t GetUTF8EncodeLength(const std::vector<wchar_t>& src,
} // namespace
+// static
+bool CFX_XMLSyntaxParser::IsXMLNameChar(wchar_t ch, bool bFirstChar) {
+ auto* it = std::lower_bound(
+ std::begin(g_XMLNameChars), std::end(g_XMLNameChars), ch,
+ [](const FX_XMLNAMECHAR& arg, wchar_t ch) { return arg.wEnd < ch; });
+ return it != std::end(g_XMLNameChars) && ch >= it->wStart &&
+ (!bFirstChar || it->bStartChar);
+}
+
CFX_XMLSyntaxParser::CFX_XMLSyntaxParser(
const CFX_RetainPtr<CFX_SeekableStreamProxy>& pStream)
: m_pStream(pStream),