Remove deprecated string features.
Make String.codeUnits return a List.
Review URL: https://codereview.chromium.org//12282038
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/yaml@18960 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/yaml/lib/composer.dart b/pkgs/yaml/lib/composer.dart
index e9c1879..e22159f 100644
--- a/pkgs/yaml/lib/composer.dart
+++ b/pkgs/yaml/lib/composer.dart
@@ -120,12 +120,7 @@
match = new RegExp("^0o([0-7]+)\$").firstMatch(content);
if (match != null) {
- // TODO(nweiz): clean this up when Dart can parse an octal string
- var n = 0;
- for (var c in match.group(1).charCodes) {
- n *= 8;
- n += c - 48;
- }
+ int n = int.parse(match.group(1), radix: 8);
return new _ScalarNode(_Tag.yaml("int"), value: n);
}
@@ -153,15 +148,13 @@
match = new RegExp("^([+-]?)\.(inf|Inf|INF)\$").firstMatch(content);
if (match != null) {
- var infinityStr = match.group(1) == "-" ? "-Infinity" : "Infinity";
- return new _ScalarNode(_Tag.yaml("float"),
- value: double.parse(infinityStr));
+ var value = match.group(1) == "-" ? -double.INFINITY : double.INFINITY;
+ return new _ScalarNode(_Tag.yaml("float"), value: value);
}
match = new RegExp("^\.(nan|NaN|NAN)\$").firstMatch(content);
if (match != null) {
- return new _ScalarNode(_Tag.yaml("float"),
- value: double.parse("NaN"));
+ return new _ScalarNode(_Tag.yaml("float"), value: double.NAN);
}
return null;
diff --git a/pkgs/yaml/lib/model.dart b/pkgs/yaml/lib/model.dart
index 9f1474e..5c09aa5 100644
--- a/pkgs/yaml/lib/model.dart
+++ b/pkgs/yaml/lib/model.dart
@@ -149,7 +149,7 @@
// TODO(nweiz): This could be faster if we used a RegExp to check for
// special characters and short-circuited if they didn't exist.
- var escapedValue = value.charCodes.map((c) {
+ var escapedValue = value.codeUnits.map((c) {
switch (c) {
case _Parser.TAB: return "\\t";
case _Parser.LF: return "\\n";
diff --git a/pkgs/yaml/lib/parser.dart b/pkgs/yaml/lib/parser.dart
index f2f255e..386bb59 100644
--- a/pkgs/yaml/lib/parser.dart
+++ b/pkgs/yaml/lib/parser.dart
@@ -172,7 +172,7 @@
/// forward one character. Also updates the current line and column numbers.
int next() {
if (pos == len) return -1;
- var char = s.charCodeAt(pos++);
+ var char = s.codeUnitAt(pos++);
if (isBreak(char)) {
line++;
column = 0;
@@ -193,14 +193,14 @@
return char;
}
- /// Returns the character at the current position, or the character [i]
+ /// Returns the code unit at the current position, or the character [i]
/// characters after the current position.
///
/// Returns -1 if this would return a character after the end or before the
/// beginning of the input string.
int peek([int i = 0]) {
var peekPos = pos + i;
- return (peekPos >= len || peekPos < 0) ? -1 : s.charCodeAt(peekPos);
+ return (peekPos >= len || peekPos < 0) ? -1 : s.codeUnitAt(peekPos);
}
/// The truthiness operator. Returns `false` if [obj] is `null` or `false`,
@@ -304,7 +304,7 @@
///
/// Returns whether or not the string was consumed.
bool rawString(String str) =>
- nAtOnce(str.length, (c, i) => str.charCodeAt(i) == c);
+ nAtOnce(str.length, (c, i) => str.codeUnitAt(i) == c);
/// Consumes and returns a string of characters matching [matcher], or null if
/// there are no such characters.