1 /* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ 4 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef MarkupTokenizerInlines_h 29 #define MarkupTokenizerInlines_h 30 31 #include "platform/text/SegmentedString.h" 32 33 namespace WebCore { 34 35 inline bool isTokenizerWhitespace(UChar cc) 36 { 37 return cc == ' ' || cc == '\x0A' || cc == '\x09' || cc == '\x0C'; 38 } 39 40 inline void advanceStringAndASSERTIgnoringCase(SegmentedString& source, const char* expectedCharacters) 41 { 42 while (*expectedCharacters) 43 source.advanceAndASSERTIgnoringCase(*expectedCharacters++); 44 } 45 46 inline void advanceStringAndASSERT(SegmentedString& source, const char* expectedCharacters) 47 { 48 while (*expectedCharacters) 49 source.advanceAndASSERT(*expectedCharacters++); 50 } 51 52 #if COMPILER(MSVC) 53 // We need to disable the "unreachable code" warning because we want to assert 54 // that some code points aren't reached in the state machine. 55 #pragma warning(disable: 4702) 56 #endif 57 58 #define BEGIN_STATE(prefix, stateName) case prefix::stateName: stateName: 59 #define END_STATE() ASSERT_NOT_REACHED(); break; 60 61 // We use this macro when the HTML5 spec says "reconsume the current input 62 // character in the <mumble> state." 63 #define RECONSUME_IN(prefix, stateName) \ 64 do { \ 65 m_state = prefix::stateName; \ 66 goto stateName; \ 67 } while (false) 68 69 // We use this macro when the HTML5 spec says "consume the next input 70 // character ... and switch to the <mumble> state." 71 #define ADVANCE_TO(prefix, stateName) \ 72 do { \ 73 m_state = prefix::stateName; \ 74 if (!m_inputStreamPreprocessor.advance(source)) \ 75 return haveBufferedCharacterToken(); \ 76 cc = m_inputStreamPreprocessor.nextInputCharacter(); \ 77 goto stateName; \ 78 } while (false) 79 80 // Sometimes there's more complicated logic in the spec that separates when 81 // we consume the next input character and when we switch to a particular 82 // state. We handle those cases by advancing the source directly and using 83 // this macro to switch to the indicated state. 84 #define SWITCH_TO(prefix, stateName) \ 85 do { \ 86 m_state = prefix::stateName; \ 87 if (source.isEmpty() || !m_inputStreamPreprocessor.peek(source)) \ 88 return haveBufferedCharacterToken(); \ 89 cc = m_inputStreamPreprocessor.nextInputCharacter(); \ 90 goto stateName; \ 91 } while (false) 92 93 } 94 95 #endif // MarkupTokenizerInlines_h 96