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

Side by Side Diff: utils/css/tokenkind.dart

Issue 10010009: Calculator App for ChromeOS with fixes for templates/CSS to support this application. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mininimal templates and more text node tests. Created 8 years, 8 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 // 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 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens 5 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens
6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*. 6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
7 class TokenKind { 7 class TokenKind {
8 // Common shared tokens used in TokenizerBase. 8 // Common shared tokens used in TokenizerBase.
9 static final int UNUSED = 0; // Unused place holder... 9 static final int UNUSED = 0; // Unused place holder...
10 static final int END_OF_FILE = 1; // TODO(terry): Must match base 10 static final int END_OF_FILE = 1; // TODO(terry): Must match base
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Completely matched; return the token for this unit. 463 // Completely matched; return the token for this unit.
464 return entry['value']; 464 return entry['value'];
465 } 465 }
466 } 466 }
467 } 467 }
468 468
469 // No match. 469 // No match.
470 throw new NoColorMatchException(text); 470 throw new NoColorMatchException(text);
471 } 471 }
472 472
473 static String decimalToHex(int num) { 473 static String decimalToHex(int num, [int minDigits = 1]) {
474 final String _HEX_DIGITS = '0123456789abcdef'; 474 final String _HEX_DIGITS = '0123456789abcdef';
475 475
476 List<String> result = new List<String>(); 476 List<String> result = new List<String>();
477 477
478 int dividend = num >> 4; 478 int dividend = num >> 4;
479 int remain = num % 16; 479 int remain = num % 16;
480 result.add(_HEX_DIGITS[remain]); 480 result.add(_HEX_DIGITS[remain]);
481 while (dividend != 0) { 481 while (dividend != 0) {
482 remain = dividend % 16; 482 remain = dividend % 16;
483 dividend >>= 4; 483 dividend >>= 4;
484 result.add(_HEX_DIGITS[remain]); 484 result.add(_HEX_DIGITS[remain]);
485 } 485 }
486 486
487 StringBuffer invertResult = new StringBuffer(); 487 StringBuffer invertResult = new StringBuffer();
488 int paddings = minDigits - result.length;
489 while (paddings-- > 0) {
490 invertResult.add('0');
491 }
488 for (int idx = result.length - 1; idx >= 0; idx--) { 492 for (int idx = result.length - 1; idx >= 0; idx--) {
489 invertResult.add(result[idx]); 493 invertResult.add(result[idx]);
490 } 494 }
495
491 return invertResult.toString(); 496 return invertResult.toString();
492 } 497 }
493 498
494 static String kindToString(int kind) { 499 static String kindToString(int kind) {
495 switch(kind) { 500 switch(kind) {
496 case TokenKind.UNUSED: return "ERROR"; 501 case TokenKind.UNUSED: return "ERROR";
497 case TokenKind.END_OF_FILE: return "end of file"; 502 case TokenKind.END_OF_FILE: return "end of file";
498 case TokenKind.LPAREN: return "("; 503 case TokenKind.LPAREN: return "(";
499 case TokenKind.RPAREN: return ")"; 504 case TokenKind.RPAREN: return ")";
500 case TokenKind.LBRACK: return "["; 505 case TokenKind.LBRACK: return "[";
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 587 }
583 588
584 } 589 }
585 590
586 class NoColorMatchException implements Exception { 591 class NoColorMatchException implements Exception {
587 String _colorName; 592 String _colorName;
588 NoColorMatchException(this._colorName); 593 NoColorMatchException(this._colorName);
589 594
590 String get name() => _colorName; 595 String get name() => _colorName;
591 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698