]> git.saurik.com Git - apple/cf.git/blob - CFXMLInputStream.h
CF-635.21.tar.gz
[apple/cf.git] / CFXMLInputStream.h
1 /*
2 * Copyright (c) 2012 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-2011, 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
37 struct __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
46 struct __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
78 typedef struct __CFXMLInputStream _CFXMLInputStream;
79
80 void _initializeInputStream(_CFXMLInputStream *stream, CFAllocatorRef alloc, CFURLRef dataSource, CFDataRef xmlData);
81 Boolean _openInputStream(_CFXMLInputStream *stream); // None of the subsequent calls will work until the input stream has been opened
82 void _freeInputStream(_CFXMLInputStream *stream);
83
84 CFStringEncoding _inputStreamGetEncoding(_CFXMLInputStream *stream);
85 CFIndex _inputStreamCurrentLocation(_CFXMLInputStream *stream);
86 CFIndex _inputStreamCurrentLine(_CFXMLInputStream *stream);
87 Boolean _inputStreamAtEOF(_CFXMLInputStream *stream);
88 Boolean _inputStreamComposingErrorOccurred(_CFXMLInputStream *stream);
89
90 Boolean _inputStreamPeekCharacter(_CFXMLInputStream *stream, UniChar *ch);
91 Boolean _inputStreamGetCharacter(_CFXMLInputStream *stream, UniChar *ch);
92 Boolean _inputStreamReturnCharacter(_CFXMLInputStream *stream, UniChar ch);
93 void _inputStreamSetMark(_CFXMLInputStream *stream);
94 void _inputStreamClearMark(_CFXMLInputStream *stream);
95 void _inputStreamGetCharactersFromMark(_CFXMLInputStream *stream, CFMutableStringRef string);
96 void _inputStreamBackUpToMark(_CFXMLInputStream *stream);
97 void _inputStringInitialize(_CFXMLInputStream *stream, UniChar *characters, CFIndex length);
98 CFIndex _inputStreamSkipWhitespace(_CFXMLInputStream *stream, CFMutableStringRef str);
99 Boolean _inputStreamScanToCharacters(_CFXMLInputStream *stream, const UniChar *scanChars, CFIndex numChars, CFMutableStringRef str);
100 Boolean _inputStreamMatchString(_CFXMLInputStream *stream, const UniChar *stringToMatch, CFIndex length);
101 Boolean _inputStreamScanQuotedString(_CFXMLInputStream *stream, CFMutableStringRef str);
102 Boolean _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
106 CFIndex CFXMLParserGetOffsetInCurrentLine(CFXMLParserRef parser); */
107
108 #endif /* ! __COREFOUNDATION_CFXMLINPUTSTREAM__ */
109