Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 // New spec is at http://dom.spec.whatwg.org/#remove-a-token-from-a-string | 235 // New spec is at http://dom.spec.whatwg.org/#remove-a-token-from-a-string |
| 236 | 236 |
| 237 unsigned inputLength = input.length(); | 237 unsigned inputLength = input.length(); |
| 238 StringBuilder output; // 3 | 238 StringBuilder output; // 3 |
| 239 output.reserveCapacity(inputLength); | 239 output.reserveCapacity(inputLength); |
| 240 unsigned position = 0; // 4 | 240 unsigned position = 0; // 4 |
| 241 | 241 |
| 242 // Step 5 | 242 // Step 5 |
| 243 while (position < inputLength) { | 243 while (position < inputLength) { |
| 244 if (isHTMLSpace<UChar>(input[position])) { // 6 | 244 if (isHTMLSpace<UChar>(input[position])) { // 6 |
| 245 output.append(input[position++]); // 6.1, 6.2 | 245 position++; |
| 246 continue; // 6.3 | 246 continue; // 6.3 |
| 247 } | 247 } |
| 248 | 248 |
| 249 // Step 7 | 249 // Step 7 |
| 250 StringBuilder tokenBuilder; | 250 StringBuilder tokenBuilder; |
| 251 while (position < inputLength && isNotHTMLSpace<UChar>(input[position])) | 251 while (position < inputLength && isNotHTMLSpace<UChar>(input[position])) |
| 252 tokenBuilder.append(input[position++]); | 252 tokenBuilder.append(input[position++]); |
| 253 | 253 |
| 254 // Step 8 | 254 // Step 8 |
| 255 String token = tokenBuilder.toString(); | 255 String token = tokenBuilder.toString(); |
| 256 if (tokens.contains(token)) { | 256 if (tokens.contains(token)) { |
| 257 // Step 8.1 | 257 // Step 8.1 |
| 258 while (position < inputLength && isHTMLSpace<UChar>(input[position]) ) | 258 while (position < inputLength && isHTMLSpace<UChar>(input[position]) ) |
| 259 ++position; | 259 ++position; |
| 260 | 260 |
| 261 // Step 8.2 | 261 // Step 8.2 |
| 262 size_t j = output.length(); | 262 size_t j = output.length(); |
| 263 while (j > 0 && isHTMLSpace<UChar>(output[j - 1])) | 263 while (j > 0 && isHTMLSpace<UChar>(output[j - 1])) |
| 264 --j; | 264 --j; |
| 265 output.resize(j); | 265 output.resize(j); |
| 266 | |
| 267 // Step 8.3 | |
| 268 if (position < inputLength && !output.isEmpty()) | |
| 269 output.append(' '); | |
| 270 } else { | 266 } else { |
| 271 output.append(token); // Step 9 | 267 output.append(token); // Step 9 |
| 272 } | 268 } |
| 269 | |
| 270 if (position < inputLength && !output.isEmpty()) | |
| 271 output.append(' '); | |
| 273 } | 272 } |
| 274 | 273 |
| 274 size_t j = output.length(); | |
| 275 if (isHTMLSpace<UChar>(output[j - 1])) | |
|
tkent
2015/10/26 23:30:38
Buffer underflow. |j| can be 0.
tanay.c
2015/10/27 10:44:39
Done.
| |
| 276 output.resize(j - 1); | |
| 277 | |
| 275 return output.toAtomicString(); | 278 return output.toAtomicString(); |
| 276 } | 279 } |
| 277 | 280 |
| 278 ValueIterable<String>::IterationSource* DOMTokenList::startIteration(ScriptState *, ExceptionState&) | 281 ValueIterable<String>::IterationSource* DOMTokenList::startIteration(ScriptState *, ExceptionState&) |
| 279 { | 282 { |
| 280 return new DOMTokenListIterationSource(this); | 283 return new DOMTokenListIterationSource(this); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace blink | 286 } // namespace blink |
| OLD | NEW |