
+ class Url {
    + scheme: String // http, https, file, ...
    + host: String
    + path: String
    + query: String
}

+ fn parse(str: String) Url {
    let scheme = ""
    let host = ""
    let path = ""
    let query = ""

    let start : uint = 0
    let index = str.index_of("://") !? 0
    if index > 0 {
        let part = str.part(0, index)
        if part.is_alpha() {
            start = index + 3
            scheme = part
        }
    }

    let query_index : uint = 999999
    if scheme == "http" || scheme == "https" {
        index = str.index_of("/", start) !? start
        if index == start : index = str.index_of("?", start) !? 999999
        host = str.part(start, index - start)
        start = index
        query_index = str.index_of("?", start) !? query_index
    }
    path = str.part(start, query_index - start)
    query = str.part(query_index + 1, 999999)

    return Url {
        scheme: scheme,
        host: host,
        path: path,
        query: query,
    }
}
