/src/exiv2/xmpsdk/src/UnicodeInlines.incl_cpp
Line | Count | Source |
1 | | #ifndef __UnicodeInlines_incl_cpp__ |
2 | | #define __UnicodeInlines_incl_cpp__ |
3 | | |
4 | | // ================================================================================================= |
5 | | // Copyright 2002-2007 Adobe Systems Incorporated |
6 | | // All Rights Reserved. |
7 | | // |
8 | | // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms |
9 | | // of the Adobe license agreement accompanying it. |
10 | | // ================================================================================================= |
11 | | |
12 | | #include "UnicodeConversions.hpp" |
13 | | |
14 | | // ================================================================================================= |
15 | | // Inner loop utilities that need to be inlined. |
16 | | // ================================================================================================= |
17 | | |
18 | | static inline XMP_Uns32 GetCodePoint ( const XMP_Uns8 ** utf8Str_io ) |
19 | 61.2k | { |
20 | 61.2k | const XMP_Uns8 * u8Ptr = *utf8Str_io; |
21 | 61.2k | XMP_Uns32 cp; |
22 | 61.2k | size_t u8Len; |
23 | 61.2k | CodePoint_from_UTF8 ( u8Ptr, 4, &cp, &u8Len ); // Throws an exception for errors. |
24 | 61.2k | *utf8Str_io = u8Ptr + u8Len; |
25 | 61.2k | return cp; |
26 | 61.2k | } XMPCore_Impl.cpp:GetCodePoint(unsigned char const**) Line | Count | Source | 19 | 29.7k | { | 20 | 29.7k | const XMP_Uns8 * u8Ptr = *utf8Str_io; | 21 | 29.7k | XMP_Uns32 cp; | 22 | 29.7k | size_t u8Len; | 23 | 29.7k | CodePoint_from_UTF8 ( u8Ptr, 4, &cp, &u8Len ); // Throws an exception for errors. | 24 | 29.7k | *utf8Str_io = u8Ptr + u8Len; | 25 | 29.7k | return cp; | 26 | 29.7k | } |
XMPMeta-GetSet.cpp:GetCodePoint(unsigned char const**) Line | Count | Source | 19 | 9.64k | { | 20 | 9.64k | const XMP_Uns8 * u8Ptr = *utf8Str_io; | 21 | 9.64k | XMP_Uns32 cp; | 22 | 9.64k | size_t u8Len; | 23 | 9.64k | CodePoint_from_UTF8 ( u8Ptr, 4, &cp, &u8Len ); // Throws an exception for errors. | 24 | 9.64k | *utf8Str_io = u8Ptr + u8Len; | 25 | 9.64k | return cp; | 26 | 9.64k | } |
Unexecuted instantiation: XMPMeta-Parse.cpp:GetCodePoint(unsigned char const**) Unexecuted instantiation: XMPMeta-Serialize.cpp:GetCodePoint(unsigned char const**) XMPMeta.cpp:GetCodePoint(unsigned char const**) Line | Count | Source | 19 | 21.8k | { | 20 | 21.8k | const XMP_Uns8 * u8Ptr = *utf8Str_io; | 21 | 21.8k | XMP_Uns32 cp; | 22 | 21.8k | size_t u8Len; | 23 | 21.8k | CodePoint_from_UTF8 ( u8Ptr, 4, &cp, &u8Len ); // Throws an exception for errors. | 24 | 21.8k | *utf8Str_io = u8Ptr + u8Len; | 25 | 21.8k | return cp; | 26 | 21.8k | } |
|
27 | | |
28 | | // ================================================================================================= |
29 | | |
30 | | static inline bool IsStartChar_ASCII ( XMP_Uns32 cp ) |
31 | 111M | { |
32 | | // ASCII starting characters for an XML name. |
33 | 111M | if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true; |
34 | 627k | return false; |
35 | 111M | } XMPCore_Impl.cpp:IsStartChar_ASCII(unsigned int) Line | Count | Source | 31 | 94.8M | { | 32 | | // ASCII starting characters for an XML name. | 33 | 94.8M | if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true; | 34 | 480k | return false; | 35 | 94.8M | } |
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsStartChar_ASCII(unsigned int) Unexecuted instantiation: XMPMeta-Parse.cpp:IsStartChar_ASCII(unsigned int) Unexecuted instantiation: XMPMeta-Serialize.cpp:IsStartChar_ASCII(unsigned int) XMPMeta.cpp:IsStartChar_ASCII(unsigned int) Line | Count | Source | 31 | 16.1M | { | 32 | | // ASCII starting characters for an XML name. | 33 | 16.1M | if ( (('a' <= cp) && (cp <= 'z')) || (('A' <= cp) && (cp <= 'Z')) || (cp == '_') ) return true; | 34 | 146k | return false; | 35 | 16.1M | } |
|
36 | | |
37 | | // ------------------------------------------------------------------------------------------------- |
38 | | |
39 | | static inline bool IsStartChar_NonASCII ( XMP_Uns32 cp ) |
40 | 51.6k | { |
41 | | // Non-ASCII starting characters for an XML name. |
42 | | |
43 | 51.6k | if ( ((0xC0 <= cp) && (cp <= 0xD6)) || ((0xD8 <= cp) && (cp <= 0xF6)) ) return true; |
44 | 46.0k | if ( ((0xF8 <= cp) && (cp <= 0x2FF)) || ((0x370 <= cp) && (cp <= 0x37D)) ) return true; |
45 | | |
46 | 35.7k | if ( ((0x37F <= cp) && (cp <= 0x1FFF)) || ((0x200C <= cp) && (cp <= 0x200D)) ) return true; |
47 | 29.7k | if ( ((0x2070 <= cp) && (cp <= 0x218F)) || ((0x2C00 <= cp) && (cp <= 0x2FEF)) ) return true; |
48 | 29.7k | if ( ((0x3001 <= cp) && (cp <= 0xD7FF)) || ((0xF900 <= cp) && (cp <= 0xFDCF)) ) return true; |
49 | 28.5k | if ( ((0xFDF0 <= cp) && (cp <= 0xFFFD)) || ((0x10000 <= cp) && (cp <= 0xEFFFF)) ) return true; |
50 | | |
51 | 28.5k | return false; |
52 | | |
53 | 28.5k | } XMPCore_Impl.cpp:IsStartChar_NonASCII(unsigned int) Line | Count | Source | 40 | 29.7k | { | 41 | | // Non-ASCII starting characters for an XML name. | 42 | | | 43 | 29.7k | if ( ((0xC0 <= cp) && (cp <= 0xD6)) || ((0xD8 <= cp) && (cp <= 0xF6)) ) return true; | 44 | 24.6k | if ( ((0xF8 <= cp) && (cp <= 0x2FF)) || ((0x370 <= cp) && (cp <= 0x37D)) ) return true; | 45 | | | 46 | 18.8k | if ( ((0x37F <= cp) && (cp <= 0x1FFF)) || ((0x200C <= cp) && (cp <= 0x200D)) ) return true; | 47 | 15.4k | if ( ((0x2070 <= cp) && (cp <= 0x218F)) || ((0x2C00 <= cp) && (cp <= 0x2FEF)) ) return true; | 48 | 15.4k | if ( ((0x3001 <= cp) && (cp <= 0xD7FF)) || ((0xF900 <= cp) && (cp <= 0xFDCF)) ) return true; | 49 | 15.2k | if ( ((0xFDF0 <= cp) && (cp <= 0xFFFD)) || ((0x10000 <= cp) && (cp <= 0xEFFFF)) ) return true; | 50 | | | 51 | 15.2k | return false; | 52 | | | 53 | 15.2k | } |
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsStartChar_NonASCII(unsigned int) Unexecuted instantiation: XMPMeta-Parse.cpp:IsStartChar_NonASCII(unsigned int) Unexecuted instantiation: XMPMeta-Serialize.cpp:IsStartChar_NonASCII(unsigned int) XMPMeta.cpp:IsStartChar_NonASCII(unsigned int) Line | Count | Source | 40 | 21.8k | { | 41 | | // Non-ASCII starting characters for an XML name. | 42 | | | 43 | 21.8k | if ( ((0xC0 <= cp) && (cp <= 0xD6)) || ((0xD8 <= cp) && (cp <= 0xF6)) ) return true; | 44 | 21.3k | if ( ((0xF8 <= cp) && (cp <= 0x2FF)) || ((0x370 <= cp) && (cp <= 0x37D)) ) return true; | 45 | | | 46 | 16.8k | if ( ((0x37F <= cp) && (cp <= 0x1FFF)) || ((0x200C <= cp) && (cp <= 0x200D)) ) return true; | 47 | 14.3k | if ( ((0x2070 <= cp) && (cp <= 0x218F)) || ((0x2C00 <= cp) && (cp <= 0x2FEF)) ) return true; | 48 | 14.3k | if ( ((0x3001 <= cp) && (cp <= 0xD7FF)) || ((0xF900 <= cp) && (cp <= 0xFDCF)) ) return true; | 49 | 13.3k | if ( ((0xFDF0 <= cp) && (cp <= 0xFFFD)) || ((0x10000 <= cp) && (cp <= 0xEFFFF)) ) return true; | 50 | | | 51 | 13.3k | return false; | 52 | | | 53 | 13.3k | } |
|
54 | | |
55 | | // ------------------------------------------------------------------------------------------------- |
56 | | |
57 | | static inline bool IsOtherChar_ASCII ( XMP_Uns32 cp ) |
58 | 627k | { |
59 | | // ASCII following characters for an XML name. |
60 | 627k | if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true; |
61 | 0 | return false; |
62 | 627k | } XMPCore_Impl.cpp:IsOtherChar_ASCII(unsigned int) Line | Count | Source | 58 | 480k | { | 59 | | // ASCII following characters for an XML name. | 60 | 480k | if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true; | 61 | 0 | return false; | 62 | 480k | } |
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsOtherChar_ASCII(unsigned int) Unexecuted instantiation: XMPMeta-Parse.cpp:IsOtherChar_ASCII(unsigned int) Unexecuted instantiation: XMPMeta-Serialize.cpp:IsOtherChar_ASCII(unsigned int) XMPMeta.cpp:IsOtherChar_ASCII(unsigned int) Line | Count | Source | 58 | 146k | { | 59 | | // ASCII following characters for an XML name. | 60 | 146k | if ( (('0' <= cp) && (cp <= '9')) || (cp == '-') || (cp == '.') ) return true; | 61 | 0 | return false; | 62 | 146k | } |
|
63 | | |
64 | | // ------------------------------------------------------------------------------------------------- |
65 | | |
66 | | static inline bool IsOtherChar_NonASCII ( XMP_Uns32 cp ) |
67 | 28.5k | { |
68 | | // Non-ASCII following characters for an XML name. |
69 | 28.5k | if ( (cp == 0xB7) || ((0x300 <= cp) && (cp <= 0x36F)) || ((0x203F <= cp) && (cp <= 0x2040)) ) return true; |
70 | 0 | return false; |
71 | 28.5k | } XMPCore_Impl.cpp:IsOtherChar_NonASCII(unsigned int) Line | Count | Source | 67 | 15.2k | { | 68 | | // Non-ASCII following characters for an XML name. | 69 | 15.2k | if ( (cp == 0xB7) || ((0x300 <= cp) && (cp <= 0x36F)) || ((0x203F <= cp) && (cp <= 0x2040)) ) return true; | 70 | 0 | return false; | 71 | 15.2k | } |
Unexecuted instantiation: XMPMeta-GetSet.cpp:IsOtherChar_NonASCII(unsigned int) Unexecuted instantiation: XMPMeta-Parse.cpp:IsOtherChar_NonASCII(unsigned int) Unexecuted instantiation: XMPMeta-Serialize.cpp:IsOtherChar_NonASCII(unsigned int) XMPMeta.cpp:IsOtherChar_NonASCII(unsigned int) Line | Count | Source | 67 | 13.3k | { | 68 | | // Non-ASCII following characters for an XML name. | 69 | 13.3k | if ( (cp == 0xB7) || ((0x300 <= cp) && (cp <= 0x36F)) || ((0x203F <= cp) && (cp <= 0x2040)) ) return true; | 70 | 0 | return false; | 71 | 13.3k | } |
|
72 | | |
73 | | // ------------------------------------------------------------------------------------------------- |
74 | | |
75 | | static inline void VerifyUTF8 ( XMP_StringPtr str ) |
76 | 0 | { |
77 | 0 | const XMP_Uns8 * utf8Str = (XMP_Uns8*)str; |
78 | 0 | while ( *utf8Str != 0 ) { |
79 | 0 | while ( (*utf8Str != 0) && (*utf8Str < 0x80) ) ++utf8Str; |
80 | 0 | if ( *utf8Str >= 0x80 ) (void) GetCodePoint ( &utf8Str ); // Throws for bad UTF-8. |
81 | 0 | } |
82 | 0 | } Unexecuted instantiation: XMPCore_Impl.cpp:VerifyUTF8(char const*) Unexecuted instantiation: XMPMeta-GetSet.cpp:VerifyUTF8(char const*) Unexecuted instantiation: XMPMeta-Parse.cpp:VerifyUTF8(char const*) Unexecuted instantiation: XMPMeta-Serialize.cpp:VerifyUTF8(char const*) Unexecuted instantiation: XMPMeta.cpp:VerifyUTF8(char const*) |
83 | | |
84 | | // ------------------------------------------------------------------------------------------------- |
85 | | |
86 | | static inline void VerifySimpleXMLName ( XMP_StringPtr _nameStart, XMP_StringPtr _nameEnd ) |
87 | 817k | { |
88 | | |
89 | 817k | const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart; |
90 | 817k | const XMP_Uns8 * nameEnd = (const XMP_Uns8 *) _nameEnd; |
91 | 817k | const XMP_Uns8 * namePos = nameStart; |
92 | 817k | XMP_Uns32 cp; |
93 | | |
94 | | // The first character is more restricted. |
95 | | |
96 | 817k | if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath ); |
97 | | |
98 | 817k | cp = *namePos; |
99 | 817k | if ( cp < 0x80 ) { |
100 | 815k | ++namePos; |
101 | 815k | if ( ! IsStartChar_ASCII(cp) ) goto NameError; |
102 | 815k | } else { |
103 | 2.08k | cp = GetCodePoint ( &namePos ); |
104 | 2.08k | if ( ! IsStartChar_NonASCII(cp) ) goto NameError; |
105 | 2.08k | } |
106 | | |
107 | | // Check the rest of the name. |
108 | | |
109 | 111M | while ( namePos < nameEnd ) { |
110 | 110M | cp = *namePos; |
111 | 110M | if ( cp < 0x80 ) { |
112 | 110M | ++namePos; |
113 | 110M | if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError; |
114 | 110M | } else { |
115 | 49.5k | cp = GetCodePoint ( &namePos ); |
116 | 49.5k | if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError; |
117 | 49.5k | } |
118 | 110M | } |
119 | | |
120 | 817k | return; |
121 | | |
122 | 817k | NameError: |
123 | 0 | XMP_Throw ( "Bad XML name", kXMPErr_BadXPath ); |
124 | | |
125 | 0 | } // VerifySimpleXMLName XMPCore_Impl.cpp:VerifySimpleXMLName(char const*, char const*) Line | Count | Source | 87 | 767k | { | 88 | | | 89 | 767k | const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart; | 90 | 767k | const XMP_Uns8 * nameEnd = (const XMP_Uns8 *) _nameEnd; | 91 | 767k | const XMP_Uns8 * namePos = nameStart; | 92 | 767k | XMP_Uns32 cp; | 93 | | | 94 | | // The first character is more restricted. | 95 | | | 96 | 767k | if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath ); | 97 | | | 98 | 767k | cp = *namePos; | 99 | 767k | if ( cp < 0x80 ) { | 100 | 766k | ++namePos; | 101 | 766k | if ( ! IsStartChar_ASCII(cp) ) goto NameError; | 102 | 766k | } else { | 103 | 1.05k | cp = GetCodePoint ( &namePos ); | 104 | 1.05k | if ( ! IsStartChar_NonASCII(cp) ) goto NameError; | 105 | 1.05k | } | 106 | | | 107 | | // Check the rest of the name. | 108 | | | 109 | 94.9M | while ( namePos < nameEnd ) { | 110 | 94.1M | cp = *namePos; | 111 | 94.1M | if ( cp < 0x80 ) { | 112 | 94.1M | ++namePos; | 113 | 94.1M | if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError; | 114 | 94.1M | } else { | 115 | 28.7k | cp = GetCodePoint ( &namePos ); | 116 | 28.7k | if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError; | 117 | 28.7k | } | 118 | 94.1M | } | 119 | | | 120 | 767k | return; | 121 | | | 122 | 767k | NameError: | 123 | 0 | XMP_Throw ( "Bad XML name", kXMPErr_BadXPath ); | 124 | | | 125 | 0 | } // VerifySimpleXMLName |
Unexecuted instantiation: XMPMeta-GetSet.cpp:VerifySimpleXMLName(char const*, char const*) Unexecuted instantiation: XMPMeta-Parse.cpp:VerifySimpleXMLName(char const*, char const*) Unexecuted instantiation: XMPMeta-Serialize.cpp:VerifySimpleXMLName(char const*, char const*) XMPMeta.cpp:VerifySimpleXMLName(char const*, char const*) Line | Count | Source | 87 | 49.9k | { | 88 | | | 89 | 49.9k | const XMP_Uns8 * nameStart = (const XMP_Uns8 *) _nameStart; | 90 | 49.9k | const XMP_Uns8 * nameEnd = (const XMP_Uns8 *) _nameEnd; | 91 | 49.9k | const XMP_Uns8 * namePos = nameStart; | 92 | 49.9k | XMP_Uns32 cp; | 93 | | | 94 | | // The first character is more restricted. | 95 | | | 96 | 49.9k | if ( nameStart >= nameEnd ) XMP_Throw ( "Empty XML name", kXMPErr_BadXPath ); | 97 | | | 98 | 49.9k | cp = *namePos; | 99 | 49.9k | if ( cp < 0x80 ) { | 100 | 48.9k | ++namePos; | 101 | 48.9k | if ( ! IsStartChar_ASCII(cp) ) goto NameError; | 102 | 48.9k | } else { | 103 | 1.02k | cp = GetCodePoint ( &namePos ); | 104 | 1.02k | if ( ! IsStartChar_NonASCII(cp) ) goto NameError; | 105 | 1.02k | } | 106 | | | 107 | | // Check the rest of the name. | 108 | | | 109 | 16.1M | while ( namePos < nameEnd ) { | 110 | 16.1M | cp = *namePos; | 111 | 16.1M | if ( cp < 0x80 ) { | 112 | 16.1M | ++namePos; | 113 | 16.1M | if ( (! IsStartChar_ASCII(cp)) && (! IsOtherChar_ASCII(cp)) ) goto NameError; | 114 | 16.1M | } else { | 115 | 20.8k | cp = GetCodePoint ( &namePos ); | 116 | 20.8k | if ( (! IsStartChar_NonASCII(cp)) && (! IsOtherChar_NonASCII(cp)) ) goto NameError; | 117 | 20.8k | } | 118 | 16.1M | } | 119 | | | 120 | 49.9k | return; | 121 | | | 122 | 49.9k | NameError: | 123 | 0 | XMP_Throw ( "Bad XML name", kXMPErr_BadXPath ); | 124 | | | 125 | 0 | } // VerifySimpleXMLName |
|
126 | | |
127 | | // ================================================================================================= |
128 | | |
129 | | #endif // __UnicodeInlines_incl_cpp__ |