| 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 "../../include/fxcrt/fx_string.h" | 7 #include "../../include/fxcrt/fx_string.h" |
| 8 | 8 |
| 9 extern const FX_WCHAR g_UnicodeData_Normalization[]; | 9 extern const FX_WCHAR g_UnicodeData_Normalization[]; |
| 10 extern const FX_WCHAR g_UnicodeData_Normalization_Map1[]; | 10 extern const FX_WCHAR g_UnicodeData_Normalization_Map1[]; |
| 11 extern const FX_WCHAR g_UnicodeData_Normalization_Map2[]; | 11 extern const FX_WCHAR g_UnicodeData_Normalization_Map2[]; |
| 12 extern const FX_WCHAR g_UnicodeData_Normalization_Map3[]; | 12 extern const FX_WCHAR g_UnicodeData_Normalization_Map3[]; |
| 13 extern const FX_WCHAR g_UnicodeData_Normalization_Map4[]; | 13 extern const FX_WCHAR g_UnicodeData_Normalization_Map4[]; |
| 14 const FX_WCHAR* g_UnicodeData_Normalization_Maps[5] = { | 14 const FX_WCHAR* g_UnicodeData_Normalization_Maps[5] = { |
| 15 NULL, | 15 NULL, g_UnicodeData_Normalization_Map1, g_UnicodeData_Normalization_Map2, |
| 16 g_UnicodeData_Normalization_Map1, | 16 g_UnicodeData_Normalization_Map3, g_UnicodeData_Normalization_Map4}; |
| 17 g_UnicodeData_Normalization_Map2, | 17 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) { |
| 18 g_UnicodeData_Normalization_Map3, | 18 wch = wch & 0xFFFF; |
| 19 g_UnicodeData_Normalization_Map4 | 19 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; |
| 20 }; | 20 if (!wFind) { |
| 21 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) | 21 if (pDst) { |
| 22 { | 22 *pDst = wch; |
| 23 wch = wch & 0xFFFF; | |
| 24 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; | |
| 25 if (!wFind) { | |
| 26 if (pDst) { | |
| 27 *pDst = wch; | |
| 28 } | |
| 29 return 1; | |
| 30 } | 23 } |
| 31 if(wFind >= 0x8000) { | 24 return 1; |
| 32 wch = wFind - 0x8000; | 25 } |
| 33 wFind = 1; | 26 if (wFind >= 0x8000) { |
| 27 wch = wFind - 0x8000; |
| 28 wFind = 1; |
| 29 } else { |
| 30 wch = wFind & 0x0FFF; |
| 31 wFind >>= 12; |
| 32 } |
| 33 const FX_WCHAR* pMap = g_UnicodeData_Normalization_Maps[wFind]; |
| 34 if (pMap == g_UnicodeData_Normalization_Map4) { |
| 35 pMap = g_UnicodeData_Normalization_Map4 + wch; |
| 36 wFind = (FX_WCHAR)(*pMap++); |
| 37 } else { |
| 38 pMap += wch; |
| 39 } |
| 40 if (pDst) { |
| 41 FX_WCHAR n = wFind; |
| 42 while (n--) { |
| 43 *pDst++ = *pMap++; |
| 44 } |
| 45 } |
| 46 return (FX_STRSIZE)wFind; |
| 47 } |
| 48 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, |
| 49 FX_WCHAR* pDst) { |
| 50 FX_STRSIZE nCount = 0; |
| 51 for (FX_STRSIZE len = 0; len < wsSrc.GetLength(); len++) { |
| 52 FX_WCHAR wch = wsSrc.GetAt(len); |
| 53 if (pDst) { |
| 54 nCount += FX_Unicode_GetNormalization(wch, pDst + nCount); |
| 34 } else { | 55 } else { |
| 35 wch = wFind & 0x0FFF; | 56 nCount += FX_Unicode_GetNormalization(wch, pDst); |
| 36 wFind >>= 12; | |
| 37 } | 57 } |
| 38 const FX_WCHAR* pMap = g_UnicodeData_Normalization_Maps[wFind]; | 58 } |
| 39 if (pMap == g_UnicodeData_Normalization_Map4) { | 59 return nCount; |
| 40 pMap = g_UnicodeData_Normalization_Map4 + wch; | |
| 41 wFind = (FX_WCHAR)(*pMap ++); | |
| 42 } else { | |
| 43 pMap += wch; | |
| 44 } | |
| 45 if (pDst) { | |
| 46 FX_WCHAR n = wFind; | |
| 47 while (n --) { | |
| 48 *pDst ++ = *pMap ++; | |
| 49 } | |
| 50 } | |
| 51 return (FX_STRSIZE)wFind; | |
| 52 } | 60 } |
| 53 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, FX_WCHAR
* pDst) | 61 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, |
| 54 { | 62 CFX_WideString& wsDst) { |
| 55 FX_STRSIZE nCount = 0; | 63 FX_STRSIZE nLen = FX_WideString_GetNormalization(wsSrc, (FX_WCHAR*)NULL); |
| 56 for (FX_STRSIZE len = 0; len < wsSrc.GetLength(); len ++) { | 64 if (!nLen) { |
| 57 FX_WCHAR wch = wsSrc.GetAt(len); | 65 return 0; |
| 58 if(pDst) { | 66 } |
| 59 nCount += FX_Unicode_GetNormalization(wch, pDst + nCount); | 67 FX_WCHAR* pBuf = wsDst.GetBuffer(nLen); |
| 60 } else { | 68 FX_WideString_GetNormalization(wsSrc, pBuf); |
| 61 nCount += FX_Unicode_GetNormalization(wch, pDst); | 69 wsDst.ReleaseBuffer(nLen); |
| 62 } | 70 return nLen; |
| 63 } | |
| 64 return nCount; | |
| 65 } | 71 } |
| 66 FX_STRSIZE FX_WideString_GetNormalization(const CFX_WideStringC& wsSrc, CFX_Wide
String &wsDst) | |
| 67 { | |
| 68 FX_STRSIZE nLen = FX_WideString_GetNormalization(wsSrc, (FX_WCHAR*)NULL); | |
| 69 if (!nLen) { | |
| 70 return 0; | |
| 71 } | |
| 72 FX_WCHAR* pBuf = wsDst.GetBuffer(nLen); | |
| 73 FX_WideString_GetNormalization(wsSrc, pBuf); | |
| 74 wsDst.ReleaseBuffer(nLen); | |
| 75 return nLen; | |
| 76 } | |
| OLD | NEW |