ca49303576
This reverts commit00090a0c72. Revert "Add fast-mode Uri class." This reverts commit323ca7e410. Revert "Fix regression for the one case where we deliberately don't follow the RFC." This reverts commitb39e048c4b. Revert "Cache hashCode in Uri implementations to improve performance when used as, e.g., Map key." This reverts commita11ad27723. BUG=https://github.com/dart-lang/sdk/issues/26917 TBR=keertip@google.com Review URL: https://codereview.chromium.org/2167663002 .
74 lines
2.5 KiB
Dart
74 lines
2.5 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "dart:convert" show ASCII;
|
|
|
|
// VM implementation of Uri.
|
|
typedef Uri _UriBaseClosure();
|
|
|
|
Uri _unsupportedUriBase() {
|
|
throw new UnsupportedError("'Uri.base' is not supported");
|
|
}
|
|
|
|
// _uriBaseClosure can be overwritten by the embedder to supply a different
|
|
// value for Uri.base.
|
|
_UriBaseClosure _uriBaseClosure = _unsupportedUriBase;
|
|
|
|
patch class Uri {
|
|
static final bool _isWindowsCached = _isWindowsPlatform;
|
|
|
|
/* patch */ static bool get _isWindows => _isWindowsCached;
|
|
|
|
/* patch */ static Uri get base => _uriBaseClosure();
|
|
|
|
static bool get _isWindowsPlatform native "Uri_isWindowsPlatform";
|
|
|
|
/* patch */ static String _uriEncode(List<int> canonicalTable,
|
|
String text,
|
|
Encoding encoding,
|
|
bool spaceToPlus) {
|
|
// First check if the text will be changed by encoding.
|
|
int i = 0;
|
|
if (identical(encoding, UTF8) ||
|
|
identical(encoding, LATIN1) ||
|
|
identical(encoding, ASCII)) {
|
|
// Encoding is compatible with the original string.
|
|
// Find first character that needs encoding.
|
|
for (; i < text.length; i++) {
|
|
var char = text.codeUnitAt(i);
|
|
if (char >= 128 ||
|
|
canonicalTable[char >> 4] & (1 << (char & 0x0f)) == 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (i == text.length) return text;
|
|
|
|
// Encode the string into bytes then generate an ASCII only string
|
|
// by percent encoding selected bytes.
|
|
StringBuffer result = new StringBuffer();
|
|
for (int j = 0; j < i; j++) {
|
|
result.writeCharCode(text.codeUnitAt(j));
|
|
}
|
|
|
|
// TODO(lrn): Is there a way to only encode from index i and forwards.
|
|
var bytes = encoding.encode(text);
|
|
for (; i < bytes.length; i++) {
|
|
int byte = bytes[i];
|
|
if (byte < 128 &&
|
|
((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) {
|
|
result.writeCharCode(byte);
|
|
} else if (spaceToPlus && byte == _SPACE) {
|
|
result.writeCharCode(_PLUS);
|
|
} else {
|
|
const String hexDigits = '0123456789ABCDEF';
|
|
result..writeCharCode(_PERCENT)
|
|
..writeCharCode(hexDigits.codeUnitAt(byte >> 4))
|
|
..writeCharCode(hexDigits.codeUnitAt(byte & 0x0f));
|
|
}
|
|
}
|
|
return result.toString();
|
|
}
|
|
}
|