Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- KrapBrowser
- -- scheme://host:port/path?query
- function parseURI(URI)
- -- Scheme
- local schemeS,schemeE = URI:find("://")
- local scheme = URI:sub(1,schemeS-1)
- print("Scheme: " .. scheme)
- -- Port/Host
- local endHostPort = URI:find("/",schemeE+1) or #URI
- local endHost = URI:find(":",shcemeE) or #URI
- if endHost < endHostPort then
- -- Has port specified
- local host = URI:sub(schemeE+1,endHost-1)
- local port = URI:sub(endHost+1,endHostPort-1 or #URI)
- else
- local host = URI:sub(schemeE+1,endHostPort-1)
- local port = 1
- end
- print("Host: " .. host)
- if port then
- print("Port: " .. port)
- end
- -- Path/Query
- local endPathQuery = URI:find("?",endHostPort+1)
- local path = URI:sub(endHostPort+1,endPathQuery-1 or #URI)
- if endPathQuery then
- local query = URI:sub(endPathQuery+1,#URI)
- end
- if path then
- print("Path: " .. path)
- end
- if query then
- print("Query: " .. query)
- end
- return scheme,host,port,path,query
- end
- parseURI("http://www.google.com:80/hi/there?url=thing")
- parseURI("http://www.google.com/hi/there?url=thing")
- parseURI("http://www.google.com:80")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement