]> git.sesse.net Git - cubemap/blobdiff - input.cpp
Use C++11 right angle brackets.
[cubemap] / input.cpp
index 0ee7d1ce918af18a9999a414cc9014a97ae07f7d..7f95b2693a96ea0e56f858eb484c68e8f7a84031 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -37,8 +37,30 @@ bool parse_url(const string &url, string *protocol, string *user, string *host,
        *protocol = string(url.begin(), url.begin() + split);
 
        string rest = string(url.begin() + split + 3, url.end());
-       split = rest.find_first_of(":/");
-       if (split == string::npos) {
+
+       // Split at the first slash, or the first colon that's not within [].
+       bool within_brackets = false;
+       for (split = 0; split < rest.size(); ++split) {
+               if (rest[split] == '[') {
+                       if (within_brackets) {
+                               // Can't nest brackets.
+                               return false;
+                       }
+                       within_brackets = true;
+               } else if (rest[split] == ']') {
+                       if (!within_brackets) {
+                               // ] without matching [.
+                               return false;
+                       }
+                       within_brackets = false;
+               } else if (rest[split] == '/') {
+                       break;
+               } else if (rest[split] == ':' && !within_brackets) {
+                       break;
+               }
+       }
+
+       if (split == rest.size()) {
                // http://foo
                split_user_host(rest, user, host);
                *port = *protocol;
@@ -72,16 +94,17 @@ bool parse_url(const string &url, string *protocol, string *user, string *host,
        return true;
 }
 
-Input *create_input(const std::string &url)
+Input *create_input(const string &url, Input::Encoding encoding)
 {
        string protocol, user, host, port, path;
        if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
                return NULL;
        }
        if (protocol == "http") {
-               return new HTTPInput(url);
+               return new HTTPInput(url, encoding);
        }
        if (protocol == "udp") {
+               // encoding is ignored; it's never Metacube.
                return new UDPInput(url);
        }
        return NULL;