Skip to content

Instantly share code, notes, and snippets.

@ArpegiusWhooves
Created December 20, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArpegiusWhooves/cccd20fa00053a66836f0aae59a09655 to your computer and use it in GitHub Desktop.
Save ArpegiusWhooves/cccd20fa00053a66836f0aae59a09655 to your computer and use it in GitHub Desktop.
// Example program
#include <iostream>
#include <string>
#include <map>
#include <regex>
#include <algorithm>
using std::cin;
using std::cout;
using std::string;
using std::stod;
using std::smatch;
using std::regex_search;
using std::regex;
std::regex operator "" _rx (const char *str, std::size_t len) { return {str,len}; }
int main()
{
string line;
while (getline(cin,line) && line != "|") { //ok wczytalismy linie
smatch match;
if (!regex_search (line, match, "^\\s*([^:;]*[^:;\\s])?\\s*"_rx )) {
cout << "Bad input '" << line <<"'\n";
continue;
}
if( match[1].matched ) {
cout << "Name: '" << match[1] <<"'\n";
}
if( match[0].second == line.end() )
{
continue;
}
string::const_iterator it = match[0].second;
if( *(it++) == ':' ) {
while( regex_search (it,line.cend(), match, "^\\s*([^,;]*[^,;\\s])?\\s*"_rx ) ) {
if( match[1].matched ) {
cout << "Var: '" << match[1] <<"'\n";
}
it = match[0].second;
if( it == line.end() || *(it++) == ';' ) break;
}
}
if(it != line.end()) {
cout << "Comment: '" << string(it,line.cend()) <<"'\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment