Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: Source/core/html/parser/HTMLEntityParser.cpp

Issue 1308573006: [reland] SegmentedString::push() should always push a char in front (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix test / accept yosin@ suggestion Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/
4 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 4 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return 0; 88 return 0;
89 } 89 }
90 90
91 typedef Vector<UChar, 64> ConsumedCharacterBuffer; 91 typedef Vector<UChar, 64> ConsumedCharacterBuffer;
92 92
93 static void unconsumeCharacters(SegmentedString& source, ConsumedCharacterBuffer & consumedCharacters) 93 static void unconsumeCharacters(SegmentedString& source, ConsumedCharacterBuffer & consumedCharacters)
94 { 94 {
95 if (consumedCharacters.size() == 1) 95 if (consumedCharacters.size() == 1)
96 source.push(consumedCharacters[0]); 96 source.push(consumedCharacters[0]);
97 else if (consumedCharacters.size() == 2) { 97 else if (consumedCharacters.size() == 2) {
98 source.push(consumedCharacters[1]);
98 source.push(consumedCharacters[0]); 99 source.push(consumedCharacters[0]);
99 source.push(consumedCharacters[1]);
100 } else 100 } else
101 source.prepend(SegmentedString(String(consumedCharacters))); 101 source.prepend(SegmentedString(String(consumedCharacters)));
102 } 102 }
103 103
104 static bool consumeNamedEntity(SegmentedString& source, DecodedHTMLEntity& decod edEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter, UChar& cc ) 104 static bool consumeNamedEntity(SegmentedString& source, DecodedHTMLEntity& decod edEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter, UChar& cc )
105 { 105 {
106 ConsumedCharacterBuffer consumedCharacters; 106 ConsumedCharacterBuffer consumedCharacters;
107 HTMLEntitySearch entitySearch; 107 HTMLEntitySearch entitySearch;
108 while (!source.isEmpty()) { 108 while (!source.isEmpty()) {
109 cc = source.currentChar(); 109 cc = source.currentChar();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 continue; 205 continue;
206 } 206 }
207 source.push('#'); 207 source.push('#');
208 return false; 208 return false;
209 } 209 }
210 case MaybeHexLowerCaseX: { 210 case MaybeHexLowerCaseX: {
211 if (isHexDigit(cc)) { 211 if (isHexDigit(cc)) {
212 entityState = Hex; 212 entityState = Hex;
213 continue; 213 continue;
214 } 214 }
215 source.push('x');
215 source.push('#'); 216 source.push('#');
216 source.push('x');
217 return false; 217 return false;
218 } 218 }
219 case MaybeHexUpperCaseX: { 219 case MaybeHexUpperCaseX: {
220 if (isHexDigit(cc)) { 220 if (isHexDigit(cc)) {
221 entityState = Hex; 221 entityState = Hex;
222 continue; 222 continue;
223 } 223 }
224 source.push('X');
224 source.push('#'); 225 source.push('#');
225 source.push('X');
226 return false; 226 return false;
227 } 227 }
228 case Hex: { 228 case Hex: {
229 if (isHexDigit(cc)) { 229 if (isHexDigit(cc)) {
230 if (result != kInvalidUnicode) 230 if (result != kInvalidUnicode)
231 result = result * 16 + asHexDigit(cc); 231 result = result * 16 + asHexDigit(cc);
232 } else if (cc == ';') { 232 } else if (cc == ';') {
233 source.advanceAndASSERT(cc); 233 source.advanceAndASSERT(cc);
234 appendLegalEntityFor(result, decodedEntity); 234 appendLegalEntityFor(result, decodedEntity);
235 return true; 235 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (!search.isEntityPrefix()) 296 if (!search.isEntityPrefix())
297 return 0; 297 return 0;
298 298
299 size_t numberOfCodePoints = appendUChar32ToUCharArray(search.mostRecentMatch ()->firstValue, result); 299 size_t numberOfCodePoints = appendUChar32ToUCharArray(search.mostRecentMatch ()->firstValue, result);
300 if (!search.mostRecentMatch()->secondValue) 300 if (!search.mostRecentMatch()->secondValue)
301 return numberOfCodePoints; 301 return numberOfCodePoints;
302 return numberOfCodePoints + appendUChar32ToUCharArray(search.mostRecentMatch ()->secondValue, result + numberOfCodePoints); 302 return numberOfCodePoints + appendUChar32ToUCharArray(search.mostRecentMatch ()->secondValue, result + numberOfCodePoints);
303 } 303 }
304 304
305 } // namespace blink 305 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLEntityParser.h ('k') | Source/core/html/parser/HTMLEntityParserTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698