/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <map>
using namespace std;
int main()
{
// Original string
std::string str1 {"Hello World. #ss4How are #dsyou?"};
// New filtered string
std::string str2 {""};
// Index
std::size_t i{0};
// "frame" counter
std::size_t prtLine{0};
// "Delay"
std::size_t skipLine{0};
// List of commands
map <std::string, std::size_t> StrCmd =
{
{ "#ds", 0 },
{ "#ss", 1 }
};
while(i < (str1.size()))
{
// Print line if == 0
if (prtLine == 0)
{
// Skip blank spaces
if (str1[i] == ' ')
{
str2 += ' ';
++i;
}
// Detects #
if(str1[i] == '#')
{
// Searches for specific code to execute
switch( StrCmd.at(str1.substr(i,3)) )
{
case 0: // #ds
// Stop skipping lines
skipLine = 0;
// Skips to next char in string next to code
i+=3;
break;
case 1: // #ss#
// Skips lines specified in string
skipLine = stoi(str1.substr(i+3,1));
// Skips to next char in string next to code
i+=4;
break;
}
}
// Pass char to new string
str2 += str1[i];
// Debug
std::cout << "Result: " << str2 << '\n';
// Increment for next loop
++i;
}
else
{
// Blank print if prtLine != 0
std::cout << '\n';
//str2 += ' ';
}
// Loops values 0-# depending on value in skipLine
prtLine = ++prtLine%(skipLine+1);
}
return 0;
}