summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-30 21:26:43 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-30 21:26:43 +0000
commit5c723d4587630f0f5463f5dcbcd8878abd3b6fb2 (patch)
treee5c238db9f12ce430e93b8ec1235610e2586c8d8 /core
parentcbfcffdac2ba600cd612f2ec5aee61bc6a1ec504 (diff)
downloadpdfium-5c723d4587630f0f5463f5dcbcd8878abd3b6fb2.tar.xz
Simplify Unicode_GetNormalization() and caller.
Change-Id: I9a5acb59790fd8527ced745370bdfe35e4d21c36 Reviewed-on: https://pdfium-review.googlesource.com/31656 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 6e797e5c27..00ae5ad4d6 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -7,6 +7,7 @@
#include "core/fpdftext/cpdf_textpage.h"
#include <algorithm>
+#include <memory>
#include <utility>
#include <vector>
@@ -83,13 +84,9 @@ size_t Unicode_GetNormalization(wchar_t wch, wchar_t* pDst) {
wch = wFind & 0x0FFF;
wFind >>= 12;
}
- const uint16_t* pMap = g_UnicodeData_Normalization_Maps[wFind];
- if (pMap == g_UnicodeData_Normalization_Map4) {
- pMap = g_UnicodeData_Normalization_Map4 + wch;
+ const uint16_t* pMap = g_UnicodeData_Normalization_Maps[wFind] + wch;
+ if (wFind == 4)
wFind = (wchar_t)(*pMap++);
- } else {
- pMap += wch;
- }
if (pDst) {
wchar_t n = wFind;
while (n--)
@@ -628,18 +625,16 @@ void CPDF_TextPage::AddCharInfoByLRDirection(wchar_t wChar,
info2.m_Index = m_TextBuf.GetLength();
if (wChar >= 0xFB00 && wChar <= 0xFB06) {
- wchar_t* pDst = nullptr;
- size_t nCount = Unicode_GetNormalization(wChar, pDst);
+ size_t nCount = Unicode_GetNormalization(wChar, nullptr);
if (nCount >= 1) {
- pDst = FX_Alloc(wchar_t, nCount);
- Unicode_GetNormalization(wChar, pDst);
+ std::unique_ptr<wchar_t, FxFreeDeleter> pDst(FX_Alloc(wchar_t, nCount));
+ Unicode_GetNormalization(wChar, pDst.get());
for (size_t nIndex = 0; nIndex < nCount; nIndex++) {
- info2.m_Unicode = pDst[nIndex];
+ info2.m_Unicode = pDst.get()[nIndex];
info2.m_Flag = FPDFTEXT_CHAR_PIECE;
m_TextBuf.AppendChar(info2.m_Unicode);
m_CharList.push_back(info2);
}
- FX_Free(pDst);
return;
}
}
@@ -658,18 +653,16 @@ void CPDF_TextPage::AddCharInfoByRLDirection(wchar_t wChar,
info2.m_Index = m_TextBuf.GetLength();
wChar = FX_GetMirrorChar(wChar);
- wchar_t* pDst = nullptr;
- size_t nCount = Unicode_GetNormalization(wChar, pDst);
+ size_t nCount = Unicode_GetNormalization(wChar, nullptr);
if (nCount >= 1) {
- pDst = FX_Alloc(wchar_t, nCount);
- Unicode_GetNormalization(wChar, pDst);
+ std::unique_ptr<wchar_t, FxFreeDeleter> pDst(FX_Alloc(wchar_t, nCount));
+ Unicode_GetNormalization(wChar, pDst.get());
for (size_t nIndex = 0; nIndex < nCount; nIndex++) {
- info2.m_Unicode = pDst[nIndex];
+ info2.m_Unicode = pDst.get()[nIndex];
info2.m_Flag = FPDFTEXT_CHAR_PIECE;
m_TextBuf.AppendChar(info2.m_Unicode);
m_CharList.push_back(info2);
}
- FX_Free(pDst);
return;
}
info2.m_Unicode = wChar;