2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 2000-2005, Apple, Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFXMLINPUTSTREAM__)
28 #define __COREFOUNDATION_CFXMLINPUTSTREAM__ 1
30 #include <CoreFoundation/CFBase.h>
31 #include "CFInternal.h"
32 #include <CoreFoundation/CFString.h>
33 #include <CoreFoundation/CFSet.h>
34 #include <CoreFoundation/CFXMLNode.h>
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
;
40 CFXMLNodeTypeCode dataTypeID
;
41 CFStringRef dataString
;
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
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
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
;
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
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
77 typedef struct __CFXMLInputStream _CFXMLInputStream
;
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
);
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
);
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
);
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); */
107 #endif /* ! __COREFOUNDATION_CFXMLINPUTSTREAM__ */