Advertisement
TheRockettek

Untitled

May 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. -- KrapBrowser
  2.  
  3. -- scheme://host:port/path?query
  4.  
  5. function parseURI(URI)
  6. -- Scheme
  7. local schemeS,schemeE = URI:find("://")
  8. local scheme = URI:sub(1,schemeS-1)
  9. print("Scheme: " .. scheme)
  10.  
  11. -- Port/Host
  12. local endHostPort = URI:find("/",schemeE+1) or #URI
  13. local endHost = URI:find(":",shcemeE) or #URI
  14. if endHost < endHostPort then
  15. -- Has port specified
  16. local host = URI:sub(schemeE+1,endHost-1)
  17. local port = URI:sub(endHost+1,endHostPort-1 or #URI)
  18. else
  19. local host = URI:sub(schemeE+1,endHostPort-1)
  20. local port = 1
  21. end
  22. print("Host: " .. host)
  23. if port then
  24. print("Port: " .. port)
  25. end
  26.  
  27. -- Path/Query
  28. local endPathQuery = URI:find("?",endHostPort+1)
  29. local path = URI:sub(endHostPort+1,endPathQuery-1 or #URI)
  30. if endPathQuery then
  31. local query = URI:sub(endPathQuery+1,#URI)
  32. end
  33. if path then
  34. print("Path: " .. path)
  35. end
  36. if query then
  37. print("Query: " .. query)
  38. end
  39. return scheme,host,port,path,query
  40. end
  41.  
  42. parseURI("http://www.google.com:80/hi/there?url=thing")
  43. parseURI("http://www.google.com/hi/there?url=thing")
  44. parseURI("http://www.google.com:80")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement