1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifdef IS_LITTLE_ENDIAN
8 #define PREFIX(ident) little2_ ## ident
9 #define BYTE_TYPE(p) LITTLE2_BYTE_TYPE(XmlGetUtf16InternalEncodingNS(), p)
10 #define IS_NAME_CHAR_MINBPC(p) LITTLE2_IS_NAME_CHAR_MINBPC(0, p)
11 #define IS_NMSTRT_CHAR_MINBPC(p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(0, p)
15 #define PREFIX(ident) big2_ ## ident
16 #define BYTE_TYPE(p) BIG2_BYTE_TYPE(XmlGetUtf16InternalEncodingNS(), p)
17 #define IS_NAME_CHAR_MINBPC(p) BIG2_IS_NAME_CHAR_MINBPC(0, p)
18 #define IS_NMSTRT_CHAR_MINBPC(p) BIG2_IS_NMSTRT_CHAR_MINBPC(0, p)
22 #define MOZ_EXPAT_VALID_QNAME (0)
23 #define MOZ_EXPAT_EMPTY_QNAME (1 << 0)
24 #define MOZ_EXPAT_INVALID_CHARACTER (1 << 1)
25 #define MOZ_EXPAT_MALFORMED (1 << 2)
27 int MOZ_XMLCheckQName(const char* ptr
, const char* end
, int ns_aware
,
30 int result
= MOZ_EXPAT_VALID_QNAME
;
34 return MOZ_EXPAT_EMPTY_QNAME
;
37 switch (BYTE_TYPE(ptr
)) {
39 /* We're namespace-aware and either first or last character is a colon
40 or we've already seen a colon. */
41 if (ns_aware
&& (nmstrt
|| *colon
|| ptr
+ 2 == end
)) {
42 return MOZ_EXPAT_MALFORMED
;
45 nmstrt
= ns_aware
; /* e.g. "a:0" should be valid if !ns_aware */
48 if (nmstrt
&& !IS_NMSTRT_CHAR_MINBPC(ptr
)) {
49 /* If this is a valid name character and we're namespace-aware, the
50 QName is malformed. Otherwise, this character's invalid at the
51 start of a name (or, if we're namespace-aware, at the start of a
53 return (IS_NAME_CHAR_MINBPC(ptr
) && ns_aware
) ?
55 MOZ_EXPAT_INVALID_CHARACTER
;
57 if (!IS_NAME_CHAR_MINBPC(ptr
)) {
58 return MOZ_EXPAT_INVALID_CHARACTER
;
70 return MOZ_EXPAT_INVALID_CHARACTER
;
74 return MOZ_EXPAT_INVALID_CHARACTER
;
81 int MOZ_XMLIsLetter(const char* ptr
)
83 switch (BYTE_TYPE(ptr
)) {
85 if (!IS_NMSTRT_CHAR_MINBPC(ptr
)) {
97 int MOZ_XMLIsNCNameChar(const char* ptr
)
99 switch (BYTE_TYPE(ptr
)) {
101 if (!IS_NAME_CHAR_MINBPC(ptr
)) {
116 int MOZ_XMLTranslateEntity(const char* ptr
, const char* end
, const char** next
,
119 const ENCODING
* enc
= XmlGetUtf16InternalEncodingNS();
120 int tok
= PREFIX(scanRef
)(enc
, ptr
, end
, next
);
121 if (tok
<= XML_TOK_INVALID
) {
125 if (tok
== XML_TOK_CHAR_REF
) {
126 int n
= XmlCharRefNumber(enc
, ptr
);
128 /* We could get away with just < 0, but better safe than sorry. */
133 return XmlUtf16Encode(n
, (unsigned short*)result
);
136 if (tok
== XML_TOK_ENTITY_REF
) {
137 /* *next points to after the semicolon, so the entity ends at
138 *next - enc->minBytesPerChar. */
140 (XML_Char
)XmlPredefinedEntityName(enc
, ptr
, *next
- enc
->minBytesPerChar
);
154 #undef IS_NAME_CHAR_MINBPC
155 #undef IS_NMSTRT_CHAR_MINBPC