| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59     bool matched; | 59     bool matched; | 
| 60     if (m_is8Bit) | 60     if (m_is8Bit) | 
| 61         matched = WTF::equal(m_data.characters8, characters, charactersCount); | 61         matched = WTF::equal(m_data.characters8, characters, charactersCount); | 
| 62     else | 62     else | 
| 63         matched = WTF::equal(m_data.characters16, characters, charactersCount); | 63         matched = WTF::equal(m_data.characters16, characters, charactersCount); | 
| 64     if (matched) | 64     if (matched) | 
| 65         advance(charactersCount); | 65         advance(charactersCount); | 
| 66     return matched; | 66     return matched; | 
| 67 } | 67 } | 
| 68 | 68 | 
|  | 69 bool VTTScanner::scanRun(const Run& run, const String& toMatch) | 
|  | 70 { | 
|  | 71     ASSERT(run.start() == position()); | 
|  | 72     ASSERT(run.start() <= end()); | 
|  | 73     ASSERT(run.end() >= run.start()); | 
|  | 74     ASSERT(run.end() <= end()); | 
|  | 75     size_t matchLength = run.length(); | 
|  | 76     if (toMatch.length() > matchLength) | 
|  | 77         return false; | 
|  | 78     bool matched; | 
|  | 79     if (m_is8Bit) | 
|  | 80         matched = WTF::equal(toMatch.impl(), m_data.characters8, matchLength); | 
|  | 81     else | 
|  | 82         matched = WTF::equal(toMatch.impl(), m_data.characters16, matchLength); | 
|  | 83     if (matched) | 
|  | 84         seekTo(run.end()); | 
|  | 85     return matched; | 
|  | 86 } | 
|  | 87 | 
|  | 88 void VTTScanner::skipRun(const Run& run) | 
|  | 89 { | 
|  | 90     ASSERT(run.start() <= end()); | 
|  | 91     ASSERT(run.end() >= run.start()); | 
|  | 92     ASSERT(run.end() <= end()); | 
|  | 93     seekTo(run.end()); | 
|  | 94 } | 
|  | 95 | 
|  | 96 String VTTScanner::extractString(const Run& run) | 
|  | 97 { | 
|  | 98     ASSERT(run.start() == position()); | 
|  | 99     ASSERT(run.start() <= end()); | 
|  | 100     ASSERT(run.end() >= run.start()); | 
|  | 101     ASSERT(run.end() <= end()); | 
|  | 102     String s; | 
|  | 103     if (m_is8Bit) | 
|  | 104         s = String(m_data.characters8, run.length()); | 
|  | 105     else | 
|  | 106         s = String(m_data.characters16, run.length()); | 
|  | 107     seekTo(run.end()); | 
|  | 108     return s; | 
|  | 109 } | 
|  | 110 | 
| 69 String VTTScanner::restOfInputAsString() | 111 String VTTScanner::restOfInputAsString() | 
| 70 { | 112 { | 
| 71     ASSERT(position() <= end()); | 113     Run rest(position(), end(), m_is8Bit); | 
| 72     String s; | 114     return extractString(rest); | 
| 73     if (m_is8Bit) |  | 
| 74         s = String(m_data.characters8, m_end.characters8 - m_data.characters8); |  | 
| 75     else |  | 
| 76         s = String(m_data.characters16, m_end.characters16 - m_data.characters16
     ); |  | 
| 77     seekTo(end()); |  | 
| 78     return s; |  | 
| 79 } | 115 } | 
| 80 | 116 | 
| 81 unsigned VTTScanner::scanDigits(int& number) | 117 unsigned VTTScanner::scanDigits(int& number) | 
| 82 { | 118 { | 
| 83     Run runOfDigits = collectWhile<isASCIIDigit>(); | 119     Run runOfDigits = collectWhile<isASCIIDigit>(); | 
| 84     if (runOfDigits.isEmpty()) { | 120     if (runOfDigits.isEmpty()) { | 
| 85         number = 0; | 121         number = 0; | 
| 86         return 0; | 122         return 0; | 
| 87     } | 123     } | 
| 88     bool validNumber; | 124     bool validNumber; | 
| 89     size_t numDigits = runOfDigits.length(); | 125     size_t numDigits = runOfDigits.length(); | 
| 90     if (m_is8Bit) | 126     if (m_is8Bit) | 
| 91         number = charactersToInt(m_data.characters8, numDigits, &validNumber); | 127         number = charactersToInt(m_data.characters8, numDigits, &validNumber); | 
| 92     else | 128     else | 
| 93         number = charactersToInt(m_data.characters16, numDigits, &validNumber); | 129         number = charactersToInt(m_data.characters16, numDigits, &validNumber); | 
| 94 | 130 | 
| 95     // Since we know that scanDigits only scanned valid (ASCII) digits (and | 131     // Since we know that scanDigits only scanned valid (ASCII) digits (and | 
| 96     // hence that's what got passed to charactersToInt()), the remaining | 132     // hence that's what got passed to charactersToInt()), the remaining | 
| 97     // failure mode for charactersToInt() is overflow, so if |validNumber| is | 133     // failure mode for charactersToInt() is overflow, so if |validNumber| is | 
| 98     // not true, then set |number| to the maximum int value. | 134     // not true, then set |number| to the maximum int value. | 
| 99     if (!validNumber) | 135     if (!validNumber) | 
| 100         number = std::numeric_limits<int>::max(); | 136         number = std::numeric_limits<int>::max(); | 
| 101     // Consume the digits. | 137     // Consume the digits. | 
| 102     seekTo(runOfDigits.end()); | 138     seekTo(runOfDigits.end()); | 
| 103     return numDigits; | 139     return numDigits; | 
| 104 } | 140 } | 
| 105 | 141 | 
| 106 } | 142 } | 
| OLD | NEW | 
|---|