1/*
2 * Copyright (c) 2014 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24/*	CFXMLInputStream.h
25	Copyright (c) 2000-2013, Apple Inc. All rights reserved.
26*/
27
28#if !defined(__COREFOUNDATION_CFXMLINPUTSTREAM__)
29#define __COREFOUNDATION_CFXMLINPUTSTREAM__ 1
30
31#include <CoreFoundation/CFBase.h>
32#include "CFInternal.h"
33#include <CoreFoundation/CFString.h>
34#include <CoreFoundation/CFSet.h>
35#include <CoreFoundation/CFXMLNode.h>
36
37struct __CFXMLNode {
38    // additionalData currently always points off the bottom of this struct; we could just eliminate it.  Also, we may want to add a flags/version argument, and could use it to mark whether the node was the special one that CFXMLParser mucks with, as well as whether the allocator was "special" (could save us the alloc instance variable, below) -- REW, 3/8/2000
39    CFRuntimeBase _cfBase;
40    CFIndex version;
41    CFXMLNodeTypeCode dataTypeID;
42    CFStringRef dataString;
43    void *additionalData;
44};
45
46struct __CFXMLInputStream {
47    CFDataRef data;               // The XML data
48    CFURLRef url;                 // the source URL for the data
49    CFStringEncoding encoding;    // the data's encoding
50    const UInt8 *currentByte;     // pointer into data at the first byte not yet translated to a character
51
52    UniChar *charBuffer;          // the buffer of characters translated from data
53    UniChar *currentChar;         // pointer into charBuffer at the current stream location.  MUST be NULL if there are no more characters in charBuffer to consume.
54    UniChar *mark;                // The point at which the mark was dropped.  NULL if the mark is currently unset.
55    UniChar *parserMark;          // mark available only for the parser's use
56    CFIndex bufferLength;         // The number of meaningful characters in charBuffer
57    CFIndex bufferCapacity;       // The current maximum capacity of charBuffer in UniChars
58
59    CFIndex charIndex, lineNum;   // location in the file
60    UInt32 flags;                 // See #defines below for bit flag meanings
61    CFMutableSetRef nameSet;             // set of all names we've encountered; used for uniquing
62    CFMutableStringRef tempString;
63
64    CFAllocatorRef allocator; // This is unfortunate; this is always the same as the parser's allocator.  We'd like to get rid of it at some point, but that would mean adding an allocator to all the function calls, which means risking that the allocator passed in gets out-of-sync.  Maybe once we have CFStreams, we can encapsulate it all in that.  REW, 5/22/2000
65};
66
67// whether the stream has been opened for reading
68#define STREAM_OPEN            0x1
69// whether the encoding matches ASCII over 0x0-0x7F
70#define ENCODING_MATCHES_ASCII 0x2
71// whether the encoding is Unicode with the "natural" byte ordering
72#define ENCODING_IS_UNICODE_NATURAL    0x4
73// whether the encoding is Unicode with the bytes swapped
74#define ENCODING_IS_UNICODE_SWAPPED    0x8
75// whether the stream has encountered an error in encodings.
76#define ENCODING_COMPOSITION_ERROR	0x10
77
78typedef struct __CFXMLInputStream _CFXMLInputStream;
79
80void _initializeInputStream(_CFXMLInputStream *stream, CFAllocatorRef alloc, CFURLRef dataSource, CFDataRef xmlData);
81Boolean _openInputStream(_CFXMLInputStream *stream); // None of the subsequent calls will work until the input stream has been opened
82void _freeInputStream(_CFXMLInputStream *stream);
83
84CFStringEncoding _inputStreamGetEncoding(_CFXMLInputStream *stream);
85CFIndex _inputStreamCurrentLocation(_CFXMLInputStream *stream);
86CFIndex _inputStreamCurrentLine(_CFXMLInputStream *stream);
87Boolean _inputStreamAtEOF(_CFXMLInputStream *stream);
88Boolean _inputStreamComposingErrorOccurred(_CFXMLInputStream *stream);
89
90Boolean _inputStreamPeekCharacter(_CFXMLInputStream *stream, UniChar *ch);
91Boolean _inputStreamGetCharacter(_CFXMLInputStream *stream, UniChar *ch);
92Boolean _inputStreamReturnCharacter(_CFXMLInputStream *stream, UniChar ch);
93void _inputStreamSetMark(_CFXMLInputStream *stream);
94void _inputStreamClearMark(_CFXMLInputStream *stream);
95void _inputStreamGetCharactersFromMark(_CFXMLInputStream *stream, CFMutableStringRef string);
96void _inputStreamBackUpToMark(_CFXMLInputStream *stream);
97void _inputStringInitialize(_CFXMLInputStream *stream, UniChar *characters, CFIndex length);
98CFIndex _inputStreamSkipWhitespace(_CFXMLInputStream *stream, CFMutableStringRef str);
99Boolean _inputStreamScanToCharacters(_CFXMLInputStream *stream, const UniChar *scanChars, CFIndex numChars, CFMutableStringRef str);
100Boolean _inputStreamMatchString(_CFXMLInputStream *stream, const UniChar *stringToMatch, CFIndex length);
101Boolean _inputStreamScanQuotedString(_CFXMLInputStream *stream, CFMutableStringRef str);
102Boolean _inputStreamScanXMLName(_CFXMLInputStream *stream, Boolean isNMToken, CFStringRef *str);
103
104/* Returns the character index within the current line of the current parse location */
105/* To add someday -- CF_EXPORT
106CFIndex CFXMLParserGetOffsetInCurrentLine(CFXMLParserRef parser); */
107
108#endif /* ! __COREFOUNDATION_CFXMLINPUTSTREAM__ */
109
110