]> git.saurik.com Git - apple/cf.git/blob - Parsing.subproj/CFXMLInputStream.h
CF-368.27.tar.gz
[apple/cf.git] / Parsing.subproj / CFXMLInputStream.h
1 /*
2 * Copyright (c) 2005 Apple Computer, 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 /* CFXMLInputStream.h
24 Copyright (c) 2000-2005, Apple, Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFXMLINPUTSTREAM__)
28 #define __COREFOUNDATION_CFXMLINPUTSTREAM__ 1
29
30 #include <CoreFoundation/CFBase.h>
31 #include "CFInternal.h"
32 #include <CoreFoundation/CFString.h>
33 #include <CoreFoundation/CFSet.h>
34 #include <CoreFoundation/CFXMLNode.h>
35
36 struct __CFXMLNode {
37 // 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
38 CFRuntimeBase _cfBase;
39 CFIndex version;
40 CFXMLNodeTypeCode dataTypeID;
41 CFStringRef dataString;
42 void *additionalData;
43 };
44
45 struct __CFXMLInputStream {
46 CFDataRef data; // The XML data
47 CFURLRef url; // the source URL for the data
48 CFStringEncoding encoding; // the data's encoding
49 const UInt8 *currentByte; // pointer into data at the first byte not yet translated to a character
50
51 UniChar *charBuffer; // the buffer of characters translated from data
52 UniChar *currentChar; // pointer into charBuffer at the current stream location. MUST be NULL if there are no more characters in charBuffer to consume.
53 UniChar *mark; // The point at which the mark was dropped. NULL if the mark is currently unset.
54 UniChar *parserMark; // mark available only for the parser's use
55 CFIndex bufferLength; // The number of meaningful characters in charBuffer
56 CFIndex bufferCapacity; // The current maximum capacity of charBuffer in UniChars
57
58 CFIndex charIndex, lineNum; // location in the file
59 UInt32 flags; // See #defines below for bit flag meanings
60 CFMutableSetRef nameSet; // set of all names we've encountered; used for uniquing
61 CFMutableStringRef tempString;
62
63 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
64 };
65
66 // whether the stream has been opened for reading
67 #define STREAM_OPEN 0x1
68 // whether the encoding matches ASCII over 0x0-0x7F
69 #define ENCODING_MATCHES_ASCII 0x2
70 // whether the encoding is Unicode with the "natural" byte ordering
71 #define ENCODING_IS_UNICODE_NATURAL 0x4
72 // whether the encoding is Unicode with the bytes swapped
73 #define ENCODING_IS_UNICODE_SWAPPED 0x8
74 // whether the stream has encountered an error in encodings.
75 #define ENCODING_COMPOSITION_ERROR 0x10
76
77 typedef struct __CFXMLInputStream _CFXMLInputStream;
78
79 void _initializeInputStream(_CFXMLInputStream *stream, CFAllocatorRef alloc, CFURLRef dataSource, CFDataRef xmlData);
80 Boolean _openInputStream(_CFXMLInputStream *stream); // None of the subsequent calls will work until the input stream has been opened
81 void _freeInputStream(_CFXMLInputStream *stream);
82
83 CFStringEncoding _inputStreamGetEncoding(_CFXMLInputStream *stream);
84 CFIndex _inputStreamCurrentLocation(_CFXMLInputStream *stream);
85 CFIndex _inputStreamCurrentLine(_CFXMLInputStream *stream);
86 Boolean _inputStreamAtEOF(_CFXMLInputStream *stream);
87 Boolean _inputStreamComposingErrorOccurred(_CFXMLInputStream *stream);
88
89 Boolean _inputStreamPeekCharacter(_CFXMLInputStream *stream, UniChar *ch);
90 Boolean _inputStreamGetCharacter(_CFXMLInputStream *stream, UniChar *ch);
91 Boolean _inputStreamReturnCharacter(_CFXMLInputStream *stream, UniChar ch);
92 void _inputStreamSetMark(_CFXMLInputStream *stream);
93 void _inputStreamClearMark(_CFXMLInputStream *stream);
94 void _inputStreamGetCharactersFromMark(_CFXMLInputStream *stream, CFMutableStringRef string);
95 void _inputStreamBackUpToMark(_CFXMLInputStream *stream);
96 void _inputStringInitialize(_CFXMLInputStream *stream, UniChar *characters, CFIndex length);
97 CFIndex _inputStreamSkipWhitespace(_CFXMLInputStream *stream, CFMutableStringRef str);
98 Boolean _inputStreamScanToCharacters(_CFXMLInputStream *stream, const UniChar *scanChars, CFIndex numChars, CFMutableStringRef str);
99 Boolean _inputStreamMatchString(_CFXMLInputStream *stream, const UniChar *stringToMatch, CFIndex length);
100 Boolean _inputStreamScanQuotedString(_CFXMLInputStream *stream, CFMutableStringRef str);
101 Boolean _inputStreamScanXMLName(_CFXMLInputStream *stream, Boolean isNMToken, CFStringRef *str);
102
103 /* Returns the character index within the current line of the current parse location */
104 /* To add someday -- CF_EXPORT
105 CFIndex CFXMLParserGetOffsetInCurrentLine(CFXMLParserRef parser); */
106
107 #endif /* ! __COREFOUNDATION_CFXMLINPUTSTREAM__ */
108