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

Side by Side Diff: runtime/lib/string.dart

Issue 8648003: Fix bug 557: Disallow user side allocation of ImmutableArray. Also added "instantiation-checks" f... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * [StringBase] contains common methods used by concrete String implementations, 6 * [StringBase] contains common methods used by concrete String implementations,
7 * e.g., OneByteString. 7 * e.g., OneByteString.
8 */ 8 */
9 class StringBase { 9 class StringBase {
10 10
11 factory StringBase._uninstantiable() {
12 throw const UnsupportedOperationException(
13 "StringBase can't be instaniated");
14 }
15
11 int hashCode() native "String_hashCode"; 16 int hashCode() native "String_hashCode";
12 17
13 /** 18 /**
14 * Create the most efficient string representation for specified 19 * Create the most efficient string representation for specified
15 * [codePoints]. 20 * [codePoints].
16 */ 21 */
17 static String createFromCharCodes(List<int> charCodes) { 22 static String createFromCharCodes(List<int> charCodes) {
18 ObjectArray objectArray; 23 ObjectArray objectArray;
19 if (charCodes is ObjectArray) { 24 if (charCodes is ObjectArray) {
20 objectArray = charCodes; 25 objectArray = charCodes;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 383 }
379 return _concatAll(stringsArray); 384 return _concatAll(stringsArray);
380 } 385 }
381 386
382 static String _concatAll(ObjectArray<String> strings) 387 static String _concatAll(ObjectArray<String> strings)
383 native "Strings_concatAll"; 388 native "Strings_concatAll";
384 } 389 }
385 390
386 391
387 class OneByteString extends StringBase implements String { 392 class OneByteString extends StringBase implements String {
393 factory OneByteString._uninstantiable() {
394 throw const UnsupportedOperationException(
395 "OneByteString can only be allocated by the VM");
396 }
397
388 // Checks for one-byte whitespaces only. 398 // Checks for one-byte whitespaces only.
389 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 399 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
390 // whitespaces for one byte strings. 400 // whitespaces for one byte strings.
391 bool _isWhitespace(int codePoint) { 401 bool _isWhitespace(int codePoint) {
392 return 402 return
393 (codePoint === 32) || // Space. 403 (codePoint === 32) || // Space.
394 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 404 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
395 } 405 }
396 406
397 } 407 }
398 408
399 409
400 class TwoByteString extends StringBase implements String { 410 class TwoByteString extends StringBase implements String {
411 factory TwoByteString._uninstantiable() {
412 throw const UnsupportedOperationException(
413 "TwoByteString can only be allocated by the VM");
414 }
415
401 // Checks for one-byte whitespaces only. 416 // Checks for one-byte whitespaces only.
402 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 417 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
403 // whitespaces. Add checking for multi-byte whitespace codepoints. 418 // whitespaces. Add checking for multi-byte whitespace codepoints.
404 bool _isWhitespace(int codePoint) { 419 bool _isWhitespace(int codePoint) {
405 return 420 return
406 (codePoint === 32) || // Space. 421 (codePoint === 32) || // Space.
407 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 422 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
408 } 423 }
409 } 424 }
410 425
411 426
412 class FourByteString extends StringBase implements String { 427 class FourByteString extends StringBase implements String {
428 factory FourByteString._uninstantiable() {
429 throw const UnsupportedOperationException(
430 "FourByteString can only be allocated by the VM");
431 }
432
413 // Checks for one-byte whitespaces only. 433 // Checks for one-byte whitespaces only.
414 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 434 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
415 // whitespaces. Add checking for multi-byte whitespace codepoints. 435 // whitespaces. Add checking for multi-byte whitespace codepoints.
416 bool _isWhitespace(int codePoint) { 436 bool _isWhitespace(int codePoint) {
417 return 437 return
418 (codePoint === 32) || // Space. 438 (codePoint === 32) || // Space.
419 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 439 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
420 } 440 }
421 } 441 }
422 442
423 443
424 class ExternalOneByteString extends StringBase implements String { 444 class ExternalOneByteString extends StringBase implements String {
445 factory ExternalOneByteString._uninstantiable() {
446 throw const UnsupportedOperationException(
447 "ExternalOneByteString can only be allocated by the VM");
448 }
449
425 // Checks for one-byte whitespaces only. 450 // Checks for one-byte whitespaces only.
426 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 451 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
427 // whitespaces for one byte strings. 452 // whitespaces for one byte strings.
428 bool _isWhitespace(int codePoint) { 453 bool _isWhitespace(int codePoint) {
429 return 454 return
430 (codePoint === 32) || // Space. 455 (codePoint === 32) || // Space.
431 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 456 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
432 } 457 }
433 } 458 }
434 459
435 460
436 class ExternalTwoByteString extends StringBase implements String { 461 class ExternalTwoByteString extends StringBase implements String {
462 factory ExternalTwoByteString._uninstantiable() {
463 throw const UnsupportedOperationException(
464 "ExternalTwoByteString can only be allocated by the VM");
465 }
466
437 // Checks for one-byte whitespaces only. 467 // Checks for one-byte whitespaces only.
438 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 468 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
439 // whitespaces. Add checking for multi-byte whitespace codepoints. 469 // whitespaces. Add checking for multi-byte whitespace codepoints.
440 bool _isWhitespace(int codePoint) { 470 bool _isWhitespace(int codePoint) {
441 return 471 return
442 (codePoint === 32) || // Space. 472 (codePoint === 32) || // Space.
443 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 473 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
444 } 474 }
445 } 475 }
446 476
447 477
448 class ExternalFourByteString extends StringBase implements String { 478 class ExternalFourByteString extends StringBase implements String {
479 factory ExternalFourByteString._uninstantiable() {
480 throw const UnsupportedOperationException(
481 "ExternalFourByteString can only be allocated by the VM");
482 }
483
449 // Checks for one-byte whitespaces only. 484 // Checks for one-byte whitespaces only.
450 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 485 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
451 // whitespaces. Add checking for multi-byte whitespace codepoints. 486 // whitespaces. Add checking for multi-byte whitespace codepoints.
452 bool _isWhitespace(int codePoint) { 487 bool _isWhitespace(int codePoint) {
453 return 488 return
454 (codePoint === 32) || // Space. 489 (codePoint === 32) || // Space.
455 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 490 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
456 } 491 }
457 } 492 }
458 493
(...skipping 20 matching lines...) Expand all
479 for (int g in groups) { 514 for (int g in groups) {
480 result.add(group(g)); 515 result.add(group(g));
481 } 516 }
482 return result; 517 return result;
483 } 518 }
484 519
485 final int _start; 520 final int _start;
486 final String str; 521 final String str;
487 final String pattern; 522 final String pattern;
488 } 523 }
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698