Guest User

Untitled

a guest
Jan 9th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. struct URL
  2. {
  3. std::string Schema;
  4. std::string User;
  5. std::string Pass;
  6. std::string Host;
  7. uint32_t Port;
  8. std::string Path;
  9. std::string Query;
  10. };
  11.  
  12. static bool parse_url(std::string url, URL &u)
  13. {
  14. boost::regex re("(\\w+)://(([1-9a-zA-Z_]*):([1-9a-zA-Z_]*)@)?([^:/]+)(:(\\d+))?(/[^?]+)?(\\?(.*))?");
  15. boost::smatch m;
  16. if (!boost::regex_match(url, m, re))
  17. {
  18. return false;
  19. }
  20.  
  21. u.Schema = m[1];
  22. u.Host = m[5];
  23. u.User = m[3];
  24. u.Pass = m[4];
  25. if (m[7].length() > 0)
  26. {
  27. u.Port = boost::lexical_cast<uint32_t>(m[7]);
  28. }
  29. u.Path = m[8];
  30. u.Query = m[10];
  31.  
  32. return true;
  33. }
Add Comment
Please, Sign In to add comment