forked from nolanw/HTMLReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLPreprocessedInputStream.h
More file actions
100 lines (84 loc) · 3.38 KB
/
HTMLPreprocessedInputStream.h
File metadata and controls
100 lines (84 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// HTMLPreprocessedInputStream.h
//
// Public domain. https://github.com/nolanw/HTMLReader
#import <Foundation/Foundation.h>
#import "HTMLSupport.h"
/**
* An HTMLPreprocessedInputStream handles carriage returns, disallowed characters, and surrogate pairs.
*
* For more information, see http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#preprocessing-the-input-stream
*/
@interface HTMLPreprocessedInputStream : NSObject
- (instancetype)initWithString:(NSString *)string NS_DESIGNATED_INITIALIZER;
/**
* The string backing an input stream.
*/
@property (readonly, copy, nonatomic) NSString *string;
/**
* Consumes matching input characters.
*
* @param string The string to match. The whole string must match for any characters to be consumed.
* @param caseSensitive YES if matching should consider ASCII case, otherwise NO.
*
* @return YES if input characters were consumed, otherwise NO.
*/
- (BOOL)consumeString:(NSString *)string matchingCase:(BOOL)caseSensitive;
/**
* Continually consumes characters until a certain character is encountered.
*
* @param predicate A block that is called with each character consumed. When the block returns YES, character consumption stops.
*
* @return A string of the characters consumed, or nil if the stream is fully consumed before the block returns YES.
*/
- (NSString *)consumeCharactersUpToFirstPassingTest:(BOOL(^)(UTF32Char character))test;
/**
* Consumes characters matching hexadecimal digits.
*
* @param number On return, the number represented by the matched digits. Pass NULL to skip over the digits.
*
* @return YES if any input characters were consumed, otherwise NO.
*/
- (BOOL)consumeHexInt:(out unsigned int *)number;
/**
* Consumes characters matching decimal digits.
*
* @param number On return, the number represented by the matched digits. Pass NULL to skip over the digits.
*
* @return YES if any input characters were consumed, otherwise NO.
*/
- (BOOL)consumeUnsignedInt:(out unsigned int *)number;
/**
* Returns, but does not consume, the next input character. No parse errors are emitted. If a stream is fully consumed, returns EOF.
*/
@property (readonly, assign, nonatomic) UTF32Char nextInputCharacter;
/**
* Returns a string of characters from the stream's current position. The characters are not preprocessed for carriage returns, and no parse errors are emitted.
*
* @param length The maximum length of the returned string.
*
* @return A string, or nil if the stream has no characters remaining.
*/
- (NSString *)nextUnprocessedCharactersWithMaximumLength:(NSUInteger)length;
/**
* Returns a scanner for the stream's unprocessed characters whose scan location is set to the stream's current location.
*/
- (NSScanner *)unprocessedScanner;
/**
* Returns the next input character and moves scanLocation ahead, emitting parse errors as appropriate. If a stream is fully consumed, returns EOF.
*/
- (UTF32Char)consumeNextInputCharacter;
/**
* Set the next input character to the current input character. This method is idempotent.
*/
- (void)reconsumeCurrentInputCharacter;
/**
* Rewinds the stream.
*/
- (void)unconsumeInputCharacters:(NSUInteger)numberOfCharactersToUnconsume;
/**
* A block called whenever a parse error occurs. The block has no return value and takes as parameters:
*
* @param error A description of the error.
*/
@property (copy, nonatomic) void (^errorBlock)(NSString *error);
@end