Advertisement
Guest User

overlap in memcpy

a guest
Jul 1st, 2011
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <boost/regex.hpp>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. using namespace boost;
  7.  
  8. int main(int argc, char *argv[]) {
  9.         if (argc < 2)
  10.                 return -1;
  11.  
  12.         string url = argv[1];
  13.  
  14.         cout << "url: " << url << endl;
  15.  
  16.         /* first problem */
  17.         regex rx("((https?)\\://)?([^\\:/]+)(:([0-9]+))?(/[^\\?#]*)?(\\?([^#]*))?(#(.*))?");
  18.         smatch match;
  19.  
  20.         if (regex_match(url, match, rx)) {
  21.                 cout << "scheme: " << match[2] << endl;
  22.                 cout << "domain: " << match[3] << endl;
  23.                 if (!match[5].str().empty())
  24.                         cout << "port: " << match[5] << endl;
  25.                 if (!match[6].str().empty())
  26.                         cout << "path: " << match[6] << endl;
  27.                 if (!match[8].str().empty())
  28.                         cout << "query: " << match[8] << endl;
  29.                 if (!match[10].str().empty())
  30.                         cout << "id: " << match[10] << endl;
  31.         } else {
  32.                 cout << "!regex_match()" << endl;
  33.         }
  34.  
  35.  
  36.         /* second problem */
  37.         string toRemove = "http://";
  38.         size_t found = 0;
  39.         if ((found = url.find(toRemove)) != string::npos) {
  40.                 cout << "found: " << found << endl;
  41.                 url.erase(found, toRemove.size());
  42.         }
  43.  
  44.  
  45.         return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement