Advertisement
alex-limonov

Untitled

Mar 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. const string ParseEvent(istream& input_stream) {
  2.     string event;
  3.     string raw_event;
  4.     getline(input_stream, raw_event);
  5.     for (auto it = raw_event.begin(); it != raw_event.end(); it++){
  6.         if (event.size() == 0){
  7.             if (*it == ' ') {
  8.                  continue;
  9.             }
  10.             else if (
  11.                 *it == '"' and *(prev(raw_event.end())) != '"'
  12.             ){
  13.                 continue;
  14.             }
  15.             else {
  16.                 event += *it;
  17.             }
  18.         }
  19.         else if (event.size() == 1 and it != prev(raw_event.end())){
  20.             if (
  21.                  *it == ' ' and event[0] == '"'
  22.             ){
  23.                 continue;
  24.             }
  25.             else if (
  26.                 *it == ' ' and *(next(it)) == ' '
  27.             ){
  28.                 continue;
  29.             }
  30.             else {
  31.                 event += *it;
  32.             }
  33.         }
  34.         else if (event.size() > 1 and next(it) != prev(raw_event.end()) and it != prev(raw_event.end())){
  35.             if (
  36.                 *it == ' ' and *(next(it)) == ' '
  37.             ){
  38.                 continue;
  39.             }
  40.             else {
  41.                 event += *it;
  42.             }
  43.         }
  44.         else if (next(it) == prev(raw_event.end())){
  45.             if (*it == ' ' and *prev(raw_event.end()) == '"') {
  46.                 continue;
  47.             } else if (*it == ' ' and *prev(raw_event.end()) == ' '){
  48.                 continue;
  49.             } else {
  50.                 event += *it;
  51.             }
  52.         }
  53.         else if (it == prev(raw_event.end())){
  54.             if (*it == '"' and event[0] != '"') {
  55.                 continue;
  56.             } else if (*it == ' '){
  57.                 continue;
  58.             } else {
  59.                 event += *it;
  60.             }
  61.         }
  62.     }
  63.     return event;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement