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

Unified Diff: lib/uri/uri.dart

Issue 10832092: Added origin property to Uri class Added unit test coverage for origin property (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Error out on non-http/https schemes Created 8 years, 4 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 | « no previous file | tests/utils/uri_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/uri/uri.dart
diff --git a/lib/uri/uri.dart b/lib/uri/uri.dart
index ad396eb74d601a970d140a396e406de93ba636b7..3a4f0d6fc6b1aab34a7b5f4f35fcddf72026cacd 100644
--- a/lib/uri/uri.dart
+++ b/lib/uri/uri.dart
@@ -167,6 +167,29 @@ class Uri {
return (userInfo != "") || (domain != "") || (port != 0);
}
+ /**
+ * Returns URI's origin: scheme://domain:port for http/https schemes
+ * Throws IllegalArgumentException for all other schemes
+ * See (http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin)
+ */
+ String get origin() {
ahe 2012/08/07 06:32:36 Please add something like: if (scheme == "") {
+ if (scheme != "http" && scheme != "https") {
+ throw new IllegalArgumentException(
ahe 2012/08/07 06:32:36 This should be a StateException which is coming so
+ "origin is applicable to http/https schemes only. Not \'$scheme\'");
+ }
+ StringBuffer sb = new StringBuffer();
+ _addIfNonEmpty(sb, scheme, scheme, ':');
ahe 2012/08/07 06:32:36 scheme is never empty now.
+ if (domain != null || port != 0) {
ahe 2012/08/07 06:32:36 Right now, the invariant is that domain is never n
+ sb.add("//");
+ sb.add(_emptyIfNull(domain));
+ if (port != 0) {
+ sb.add(":");
+ sb.add(port.toString());
+ }
+ }
+ return sb.toString();
+ }
+
String toString() {
StringBuffer sb = new StringBuffer();
_addIfNonEmpty(sb, scheme, scheme, ':');
@@ -193,3 +216,4 @@ class Uri {
}
}
}
+
ahe 2012/08/07 06:32:36 Extra line at end of file.
« no previous file with comments | « no previous file | tests/utils/uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698