| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdftext/unicodenormalization.h" |
| 8 |
| 7 #include "core/fpdftext/unicodenormalizationdata.h" | 9 #include "core/fpdftext/unicodenormalizationdata.h" |
| 8 #include "core/include/fxcrt/fx_string.h" | 10 #include "core/include/fxcrt/fx_string.h" |
| 9 | 11 |
| 12 namespace { |
| 13 |
| 10 const FX_WCHAR* const g_UnicodeData_Normalization_Maps[5] = { | 14 const FX_WCHAR* const g_UnicodeData_Normalization_Maps[5] = { |
| 11 nullptr, g_UnicodeData_Normalization_Map1, g_UnicodeData_Normalization_Map2, | 15 nullptr, g_UnicodeData_Normalization_Map1, g_UnicodeData_Normalization_Map2, |
| 12 g_UnicodeData_Normalization_Map3, g_UnicodeData_Normalization_Map4}; | 16 g_UnicodeData_Normalization_Map3, g_UnicodeData_Normalization_Map4}; |
| 13 | 17 |
| 18 } // namespace |
| 19 |
| 14 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) { | 20 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) { |
| 15 wch = wch & 0xFFFF; | 21 wch = wch & 0xFFFF; |
| 16 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; | 22 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; |
| 17 if (!wFind) { | 23 if (!wFind) { |
| 18 if (pDst) { | 24 if (pDst) { |
| 19 *pDst = wch; | 25 *pDst = wch; |
| 20 } | 26 } |
| 21 return 1; | 27 return 1; |
| 22 } | 28 } |
| 23 if (wFind >= 0x8000) { | 29 if (wFind >= 0x8000) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 pMap += wch; | 41 pMap += wch; |
| 36 } | 42 } |
| 37 if (pDst) { | 43 if (pDst) { |
| 38 FX_WCHAR n = wFind; | 44 FX_WCHAR n = wFind; |
| 39 while (n--) { | 45 while (n--) { |
| 40 *pDst++ = *pMap++; | 46 *pDst++ = *pMap++; |
| 41 } | 47 } |
| 42 } | 48 } |
| 43 return (FX_STRSIZE)wFind; | 49 return (FX_STRSIZE)wFind; |
| 44 } | 50 } |
| 45 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, | |
| 46 FX_WCHAR* pDst) { | |
| 47 FX_STRSIZE nCount = 0; | |
| 48 for (FX_STRSIZE len = 0; len < wsSrc.GetLength(); len++) { | |
| 49 FX_WCHAR wch = wsSrc.GetAt(len); | |
| 50 if (pDst) { | |
| 51 nCount += FX_Unicode_GetNormalization(wch, pDst + nCount); | |
| 52 } else { | |
| 53 nCount += FX_Unicode_GetNormalization(wch, pDst); | |
| 54 } | |
| 55 } | |
| 56 return nCount; | |
| 57 } | |
| 58 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, | |
| 59 CFX_WideString& wsDst) { | |
| 60 FX_STRSIZE nLen = FX_WideString_GetNormalization(wsSrc, (FX_WCHAR*)NULL); | |
| 61 if (!nLen) { | |
| 62 return 0; | |
| 63 } | |
| 64 FX_WCHAR* pBuf = wsDst.GetBuffer(nLen); | |
| 65 FX_WideString_GetNormalization(wsSrc, pBuf); | |
| 66 wsDst.ReleaseBuffer(nLen); | |
| 67 return nLen; | |
| 68 } | |
| OLD | NEW |