From 5cc13d0b2a8663ea766423c28a08d189bc824c4e Mon Sep 17 00:00:00 2001 From: iska Date: Sat, 20 Sep 2014 23:05:55 +0200 Subject: [PATCH] Add methods to mark location and rewind-to-mark in HTML stream reader This will allows us to unconsume/reconsume characters during tokenization --- HTMLKit/HTMLInputStreamReader.h | 6 ++++++ HTMLKit/HTMLInputStreamReader.m | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/HTMLKit/HTMLInputStreamReader.h b/HTMLKit/HTMLInputStreamReader.h index f59d394..0ae10cd 100644 --- a/HTMLKit/HTMLInputStreamReader.h +++ b/HTMLKit/HTMLInputStreamReader.h @@ -23,4 +23,10 @@ - (UTF32Char)currentInputCharacter; - (UTF32Char)nextInputCharacter; +- (UTF32Char)consumeNextInputCharacter; +- (void)unconsumeCurrentInputCharacter; + +- (void)markCurrentLocation; +- (void)rewindToMarkedLocation; + @end diff --git a/HTMLKit/HTMLInputStreamReader.m b/HTMLKit/HTMLInputStreamReader.m index e373791..beb18a6 100644 --- a/HTMLKit/HTMLInputStreamReader.m +++ b/HTMLKit/HTMLInputStreamReader.m @@ -65,6 +65,7 @@ NS_INLINE BOOL isControlOrUndefinedCharacter(UTF32Char character) NSScanner *_scanner; CFStringInlineBuffer _buffer; NSUInteger _location; + NSUInteger _mark; UTF32Char _currentInputCharacter; NSUInteger _consume; HTMLStreamReaderErrorCallback _errorCallback; @@ -153,4 +154,16 @@ NS_INLINE BOOL isControlOrUndefinedCharacter(UTF32Char character) _consume = 0; } +- (void)markCurrentLocation +{ + _mark = _location; +} + +- (void)rewindToMarkedLocation +{ + _location = _mark; + _scanner.scanLocation = _mark; + _consume = 0; +} + @end