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 "xfa/fde/xml/fde_xml_imp.h" | 7 #include "xfa/fde/xml/fde_xml_imp.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
12 #include "xfa/fgas/crt/fgas_system.h" | 12 #include "xfa/fgas/crt/fgas_system.h" |
13 | 13 |
14 #define FDE_XMLVALIDCHARRANGENUM 5 | 14 #define FDE_XMLVALIDCHARRANGENUM 5 |
15 | 15 static const uint16_t g_XMLValidCharRange[FDE_XMLVALIDCHARRANGENUM][2] = { |
16 static const FX_WCHAR g_XMLValidCharRange[FDE_XMLVALIDCHARRANGENUM][2] = { | |
17 {0x09, 0x09}, | 16 {0x09, 0x09}, |
18 {0x0A, 0x0A}, | 17 {0x0A, 0x0A}, |
19 {0x0D, 0x0D}, | 18 {0x0D, 0x0D}, |
20 {0x20, 0xD7FF}, | 19 {0x20, 0xD7FF}, |
21 {0xE000, 0xFFFD}}; | 20 {0xE000, 0xFFFD}}; |
22 | 21 |
23 FX_BOOL FDE_IsXMLValidChar(FX_WCHAR ch) { | 22 FX_BOOL FDE_IsXMLValidChar(FX_WCHAR ch) { |
24 int32_t iStart = 0, iEnd = FDE_XMLVALIDCHARRANGENUM - 1, iMid; | 23 int32_t iStart = 0, iEnd = FDE_XMLVALIDCHARRANGENUM - 1, iMid; |
25 while (iStart <= iEnd) { | 24 while (iStart <= iEnd) { |
26 iMid = (iStart + iEnd) / 2; | 25 iMid = (iStart + iEnd) / 2; |
27 if (ch < g_XMLValidCharRange[iMid][0]) { | 26 if (ch < g_XMLValidCharRange[iMid][0]) { |
28 iEnd = iMid - 1; | 27 iEnd = iMid - 1; |
29 } else if (ch > g_XMLValidCharRange[iMid][1]) { | 28 } else if (ch > g_XMLValidCharRange[iMid][1]) { |
30 iStart = iMid + 1; | 29 iStart = iMid + 1; |
31 } else { | 30 } else { |
32 return TRUE; | 31 return TRUE; |
33 } | 32 } |
34 } | 33 } |
35 return FALSE; | 34 return FALSE; |
36 } | 35 } |
37 FX_BOOL FDE_IsXMLWhiteSpace(FX_WCHAR ch) { | 36 FX_BOOL FDE_IsXMLWhiteSpace(FX_WCHAR ch) { |
38 return ch == L' ' || ch == 0x0A || ch == 0x0D || ch == 0x09; | 37 return ch == L' ' || ch == 0x0A || ch == 0x0D || ch == 0x09; |
39 } | 38 } |
40 | 39 |
41 struct FDE_XMLNAMECHAR { | 40 struct FDE_XMLNAMECHAR { |
42 FX_WCHAR wStart; | 41 uint16_t wStart; |
43 FX_WCHAR wEnd; | 42 uint16_t wEnd; |
44 FX_BOOL bStartChar; | 43 bool bStartChar; |
45 }; | 44 }; |
46 | 45 |
47 #define FDE_XMLNAMECHARSNUM 20 | 46 #define FDE_XMLNAMECHARSNUM 20 |
48 static FDE_XMLNAMECHAR g_XMLNameChars[FDE_XMLNAMECHARSNUM] = { | 47 static const FDE_XMLNAMECHAR g_XMLNameChars[FDE_XMLNAMECHARSNUM] = { |
49 {L'-', L'.', FALSE}, {L'0', L'9', FALSE}, {L':', L':', FALSE}, | 48 {L'-', L'.', false}, {L'0', L'9', false}, {L':', L':', false}, |
50 {L'A', L'Z', TRUE}, {L'_', L'_', TRUE}, {L'a', L'z', TRUE}, | 49 {L'A', L'Z', true}, {L'_', L'_', true}, {L'a', L'z', true}, |
51 {0xB7, 0xB7, FALSE}, {0xC0, 0xD6, TRUE}, {0xD8, 0xF6, TRUE}, | 50 {0xB7, 0xB7, false}, {0xC0, 0xD6, true}, {0xD8, 0xF6, true}, |
52 {0xF8, 0x02FF, TRUE}, {0x0300, 0x036F, FALSE}, {0x0370, 0x037D, TRUE}, | 51 {0xF8, 0x02FF, true}, {0x0300, 0x036F, false}, {0x0370, 0x037D, true}, |
53 {0x037F, 0x1FFF, TRUE}, {0x200C, 0x200D, TRUE}, {0x203F, 0x2040, FALSE}, | 52 {0x037F, 0x1FFF, true}, {0x200C, 0x200D, true}, {0x203F, 0x2040, false}, |
54 {0x2070, 0x218F, TRUE}, {0x2C00, 0x2FEF, TRUE}, {0x3001, 0xD7FF, TRUE}, | 53 {0x2070, 0x218F, true}, {0x2C00, 0x2FEF, true}, {0x3001, 0xD7FF, true}, |
55 {0xF900, 0xFDCF, TRUE}, {0xFDF0, 0xFFFD, TRUE}, | 54 {0xF900, 0xFDCF, true}, {0xFDF0, 0xFFFD, true}, |
56 }; | 55 }; |
57 | 56 |
58 FX_BOOL FDE_IsXMLNameChar(FX_WCHAR ch, FX_BOOL bFirstChar) { | 57 FX_BOOL FDE_IsXMLNameChar(FX_WCHAR ch, FX_BOOL bFirstChar) { |
59 int32_t iStart = 0, iEnd = FDE_XMLNAMECHARSNUM - 1, iMid; | 58 int32_t iStart = 0, iEnd = FDE_XMLNAMECHARSNUM - 1, iMid; |
60 while (iStart <= iEnd) { | 59 while (iStart <= iEnd) { |
61 iMid = (iStart + iEnd) / 2; | 60 iMid = (iStart + iEnd) / 2; |
62 if (ch < g_XMLNameChars[iMid].wStart) { | 61 if (ch < g_XMLNameChars[iMid].wStart) { |
63 iEnd = iMid - 1; | 62 iEnd = iMid - 1; |
64 } else if (ch > g_XMLNameChars[iMid].wEnd) { | 63 } else if (ch > g_XMLNameChars[iMid].wEnd) { |
65 iStart = iMid + 1; | 64 iStart = iMid + 1; |
(...skipping 2025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); | 2090 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); |
2092 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); | 2091 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); |
2093 m_iEntityStart = -1; | 2092 m_iEntityStart = -1; |
2094 } else { | 2093 } else { |
2095 if (m_iEntityStart < 0 && ch == L'&') { | 2094 if (m_iEntityStart < 0 && ch == L'&') { |
2096 m_iEntityStart = m_iDataLength - 1; | 2095 m_iEntityStart = m_iDataLength - 1; |
2097 } | 2096 } |
2098 } | 2097 } |
2099 m_pStart++; | 2098 m_pStart++; |
2100 } | 2099 } |
OLD | NEW |