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

Unified Diff: sdk/lib/core/uri.dart

Issue 957743002: Cleanup URI and use String.replaceRange. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index c4cb508e2c05eec3cc3e78c35a01de1230c31b55..06bb3ca3b9cfe118e5d31be55e1ad8b6b65fd366 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -753,8 +753,8 @@ class Uri {
}
static _makeFileUri(String path) {
- String sep = "/";
- if (path.startsWith(sep)) {
+ const String sep = "/";
+ if (path.startsWith(sep)) {
// Absolute file:// URI.
return new Uri(scheme: "file", pathSegments: path.split(sep));
} else {
@@ -764,23 +764,23 @@ class Uri {
}
static _makeWindowsFileUrl(String path) {
- if (path.startsWith("\\\\?\\")) {
- if (path.startsWith("\\\\?\\UNC\\")) {
- path = "\\${path.substring(7)}";
+ if (path.startsWith(r"\\?\")) {
+ if (path.startsWith(r"UNC\", 4)) {
+ path = path.replaceRange(0, 7, r'\');
} else {
path = path.substring(4);
if (path.length < 3 ||
path.codeUnitAt(1) != _COLON ||
path.codeUnitAt(2) != _BACKSLASH) {
throw new ArgumentError(
- "Windows paths with \\\\?\\ prefix must be absolute");
+ r"Windows paths with \\?\ prefix must be absolute");
}
}
} else {
- path = path.replaceAll("/", "\\");
+ path = path.replaceAll("/", r'\');
}
- String sep = "\\";
- if (path.length > 1 && path[1] == ":") {
+ const String sep = r'\';
+ if (path.length > 1 && path.codeUnitAt(1) == _COLON) {
_checkWindowsDriveLetter(path.codeUnitAt(0), true);
if (path.length == 2 || path.codeUnitAt(2) != _BACKSLASH) {
throw new ArgumentError(
@@ -792,14 +792,14 @@ class Uri {
return new Uri(scheme: "file", pathSegments: pathSegments);
}
- if (path.length > 0 && path[0] == sep) {
- if (path.length > 1 && path[1] == sep) {
+ if (path.startsWith(sep)) {
+ if (path.startsWith(sep, 1)) {
// Absolute file:// URI with host.
- int pathStart = path.indexOf("\\", 2);
+ int pathStart = path.indexOf(r'\', 2);
String hostPart =
- pathStart == -1 ? path.substring(2) : path.substring(2, pathStart);
+ (pathStart < 0) ? path.substring(2) : path.substring(2, pathStart);
String pathPart =
- pathStart == -1 ? "" : path.substring(pathStart + 1);
+ (pathStart < 0) ? "" : path.substring(pathStart + 1);
var pathSegments = pathPart.split(sep);
_checkWindowsPathReservedCharacters(pathSegments, true);
return new Uri(
@@ -1387,8 +1387,8 @@ class Uri {
baseEnd = newEnd;
backCount--;
}
- return base.substring(0, baseEnd + 1) +
- reference.substring(refStart - 3 * backCount);
+ return base.replaceRange(baseEnd + 1, null,
+ reference.substring(refStart - 3 * backCount));
}
bool _hasDotSegments(String path) {
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698