| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.generated.java_core; | 5 library analyzer.src.generated.java_core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Inserts the given arguments into [pattern]. | 8 * Inserts the given arguments into [pattern]. |
| 9 * | 9 * |
| 10 * format('Hello, {0}!', 'John') = 'Hello, John!' | 10 * format('Hello, {0}!', 'John') = 'Hello, John!' |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { | 33 return pattern.replaceAllMapped(new RegExp(r'\{(\d+)\}'), (match) { |
| 34 String indexStr = match.group(1); | 34 String indexStr = match.group(1); |
| 35 int index = int.parse(indexStr); | 35 int index = int.parse(indexStr); |
| 36 Object arg = arguments[index]; | 36 Object arg = arguments[index]; |
| 37 assert(arg != null); | 37 assert(arg != null); |
| 38 return arg?.toString(); | 38 return arg?.toString(); |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | |
| 43 * Very limited printf implementation, supports only %s and %d. | |
| 44 */ | |
| 45 String _printf(String fmt, List args) { | |
| 46 StringBuffer sb = new StringBuffer(); | |
| 47 bool markFound = false; | |
| 48 int argIndex = 0; | |
| 49 for (int i = 0; i < fmt.length; i++) { | |
| 50 int c = fmt.codeUnitAt(i); | |
| 51 if (c == 0x25) { | |
| 52 if (markFound) { | |
| 53 sb.writeCharCode(c); | |
| 54 markFound = false; | |
| 55 } else { | |
| 56 markFound = true; | |
| 57 } | |
| 58 continue; | |
| 59 } | |
| 60 if (markFound) { | |
| 61 markFound = false; | |
| 62 // %d | |
| 63 if (c == 0x64) { | |
| 64 sb.write(args[argIndex++]); | |
| 65 continue; | |
| 66 } | |
| 67 // %s | |
| 68 if (c == 0x73) { | |
| 69 sb.write(args[argIndex++]); | |
| 70 continue; | |
| 71 } | |
| 72 // unknown | |
| 73 throw new ArgumentError('[$fmt][$i] = 0x${c.toRadixString(16)}'); | |
| 74 } else { | |
| 75 sb.writeCharCode(c); | |
| 76 } | |
| 77 } | |
| 78 return sb.toString(); | |
| 79 } | |
| 80 | |
| 81 class Character { | 42 class Character { |
| 82 static const int MAX_VALUE = 0xffff; | 43 static const int MAX_VALUE = 0xffff; |
| 83 static const int MAX_CODE_POINT = 0x10ffff; | 44 static const int MAX_CODE_POINT = 0x10ffff; |
| 84 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; | 45 static const int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; |
| 85 static const int MIN_LOW_SURROGATE = 0xDC00; | 46 static const int MIN_LOW_SURROGATE = 0xDC00; |
| 86 static const int MIN_HIGH_SURROGATE = 0xD800; | 47 static const int MIN_HIGH_SURROGATE = 0xD800; |
| 87 | 48 |
| 88 static int digit(int codePoint, int radix) { | 49 static int digit(int codePoint, int radix) { |
| 89 if (radix != 16) { | 50 if (radix != 16) { |
| 90 throw new ArgumentError("only radix == 16 is supported"); | 51 throw new ArgumentError("only radix == 16 is supported"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 /// The name of this enum constant, as declared in the enum declaration. | 90 /// The name of this enum constant, as declared in the enum declaration. |
| 130 final String name; | 91 final String name; |
| 131 | 92 |
| 132 /// The position in the enum declaration. | 93 /// The position in the enum declaration. |
| 133 final int ordinal; | 94 final int ordinal; |
| 134 const Enum(this.name, this.ordinal); | 95 const Enum(this.name, this.ordinal); |
| 135 int get hashCode => ordinal; | 96 int get hashCode => ordinal; |
| 136 int compareTo(E other) => ordinal - other.ordinal; | 97 int compareTo(E other) => ordinal - other.ordinal; |
| 137 String toString() => name; | 98 String toString() => name; |
| 138 } | 99 } |
| 139 | |
| 140 class PrintStringWriter extends PrintWriter { | |
| 141 final StringBuffer _sb = new StringBuffer(); | |
| 142 | |
| 143 void print(x) { | |
| 144 _sb.write(x); | |
| 145 } | |
| 146 | |
| 147 String toString() => _sb.toString(); | |
| 148 } | |
| 149 | |
| 150 abstract class PrintWriter { | |
| 151 void newLine() { | |
| 152 this.print('\n'); | |
| 153 } | |
| 154 | |
| 155 void print(x); | |
| 156 | |
| 157 void printf(String fmt, List args) { | |
| 158 this.print(_printf(fmt, args)); | |
| 159 } | |
| 160 | |
| 161 void println(String s) { | |
| 162 this.print(s); | |
| 163 this.newLine(); | |
| 164 } | |
| 165 } | |
| OLD | NEW |