| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 public: | 51 public: |
| 52 explicit VTTScanner(const String& line); | 52 explicit VTTScanner(const String& line); |
| 53 | 53 |
| 54 typedef const LChar* Position; | 54 typedef const LChar* Position; |
| 55 | 55 |
| 56 class Run { | 56 class Run { |
| 57 public: | 57 public: |
| 58 Run(Position start, Position end, bool is8Bit) | 58 Run(Position start, Position end, bool is8Bit) |
| 59 : m_start(start), m_end(end), m_is8Bit(is8Bit) { } | 59 : m_start(start), m_end(end), m_is8Bit(is8Bit) { } |
| 60 | 60 |
| 61 Position start() const { return m_start; } |
| 61 Position end() const { return m_end; } | 62 Position end() const { return m_end; } |
| 62 | 63 |
| 63 bool isEmpty() const { return m_start == m_end; } | 64 bool isEmpty() const { return m_start == m_end; } |
| 64 size_t length() const; | 65 size_t length() const; |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 Position m_start; | 68 Position m_start; |
| 68 Position m_end; | 69 Position m_end; |
| 69 bool m_is8Bit; | 70 bool m_is8Bit; |
| 70 }; | 71 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 89 // the end of the input. | 90 // the end of the input. |
| 90 template<bool characterPredicate(UChar)> | 91 template<bool characterPredicate(UChar)> |
| 91 void skipWhile(); | 92 void skipWhile(); |
| 92 | 93 |
| 93 // Return the run of characters for which the specified | 94 // Return the run of characters for which the specified |
| 94 // |characterPredicate| returns true. The start of the run will be the | 95 // |characterPredicate| returns true. The start of the run will be the |
| 95 // current input pointer. | 96 // current input pointer. |
| 96 template<bool characterPredicate(UChar)> | 97 template<bool characterPredicate(UChar)> |
| 97 Run collectWhile(); | 98 Run collectWhile(); |
| 98 | 99 |
| 100 // Like collectWhile, but using a negated predicate. |
| 101 template<bool characterPredicate(UChar)> |
| 102 Run collectUntil(); |
| 103 |
| 104 // Scan the string |toMatch|, using the specified |run| as the sequence to |
| 105 // match against. |
| 106 bool scanRun(const Run&, const String& toMatch); |
| 107 |
| 108 // Skip to the end of the specified |run|. |
| 109 void skipRun(const Run&); |
| 110 |
| 111 // Return the String made up of the characters in |run|, and advance the |
| 112 // input pointer to the end of the run. |
| 113 String extractString(const Run&); |
| 114 |
| 99 // Return a String constructed from the rest of the input (between input | 115 // Return a String constructed from the rest of the input (between input |
| 100 // pointer and end of input), and advance the input pointer accordingly. | 116 // pointer and end of input), and advance the input pointer accordingly. |
| 101 String restOfInputAsString(); | 117 String restOfInputAsString(); |
| 102 | 118 |
| 103 // Scan a set of ASCII digits from the input. Return the number of digits | 119 // Scan a set of ASCII digits from the input. Return the number of digits |
| 104 // scanned, and set |number| to the computed value. If the digits make up a | 120 // scanned, and set |number| to the computed value. If the digits make up a |
| 105 // number that does not fit the 'int' type, |number| is set to INT_MAX. | 121 // number that does not fit the 'int' type, |number| is set to INT_MAX. |
| 106 // Note: Does not handle sign. | 122 // Note: Does not handle sign. |
| 107 unsigned scanDigits(int& number); | 123 unsigned scanDigits(int& number); |
| 108 | 124 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (m_is8Bit) { | 171 if (m_is8Bit) { |
| 156 const LChar* current = m_data.characters8; | 172 const LChar* current = m_data.characters8; |
| 157 ::skipWhile<LChar, LCharPredicateAdapter<characterPredicate> >(current,
m_end.characters8); | 173 ::skipWhile<LChar, LCharPredicateAdapter<characterPredicate> >(current,
m_end.characters8); |
| 158 return Run(position(), current, m_is8Bit); | 174 return Run(position(), current, m_is8Bit); |
| 159 } | 175 } |
| 160 const UChar* current = m_data.characters16; | 176 const UChar* current = m_data.characters16; |
| 161 ::skipWhile<UChar, characterPredicate>(current, m_end.characters16); | 177 ::skipWhile<UChar, characterPredicate>(current, m_end.characters16); |
| 162 return Run(position(), reinterpret_cast<Position>(current), m_is8Bit); | 178 return Run(position(), reinterpret_cast<Position>(current), m_is8Bit); |
| 163 } | 179 } |
| 164 | 180 |
| 181 template<bool characterPredicate(UChar)> |
| 182 inline VTTScanner::Run VTTScanner::collectUntil() |
| 183 { |
| 184 if (m_is8Bit) { |
| 185 const LChar* current = m_data.characters8; |
| 186 ::skipUntil<LChar, LCharPredicateAdapter<characterPredicate> >(current,
m_end.characters8); |
| 187 return Run(position(), current, m_is8Bit); |
| 188 } |
| 189 const UChar* current = m_data.characters16; |
| 190 ::skipUntil<UChar, characterPredicate>(current, m_end.characters16); |
| 191 return Run(position(), reinterpret_cast<Position>(current), m_is8Bit); |
| 192 } |
| 193 |
| 165 inline void VTTScanner::seekTo(Position position) | 194 inline void VTTScanner::seekTo(Position position) |
| 166 { | 195 { |
| 167 ASSERT(position <= end()); | 196 ASSERT(position <= end()); |
| 168 m_data.characters8 = position; | 197 m_data.characters8 = position; |
| 169 } | 198 } |
| 170 | 199 |
| 171 inline UChar VTTScanner::currentChar() const | 200 inline UChar VTTScanner::currentChar() const |
| 172 { | 201 { |
| 173 ASSERT(position() < end()); | 202 ASSERT(position() < end()); |
| 174 return m_is8Bit ? *m_data.characters8 : *m_data.characters16; | 203 return m_is8Bit ? *m_data.characters8 : *m_data.characters16; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 unsigned* m_outPosition; | 241 unsigned* m_outPosition; |
| 213 union { | 242 union { |
| 214 const LChar* characters8; | 243 const LChar* characters8; |
| 215 const UChar* characters16; | 244 const UChar* characters16; |
| 216 } m_start; | 245 } m_start; |
| 217 }; | 246 }; |
| 218 | 247 |
| 219 } | 248 } |
| 220 | 249 |
| 221 #endif | 250 #endif |
| OLD | NEW |