A string parser over std::string

I have created a string parser over st::string and its working fine. Some feedback would be good.
I have also provided a constructor to input the delimiter as a character. There its not working as expected.


#include <iostream>
#include <cstring>
#include <vector>

typedef unsigned int ULI;

class StringParser {
protected:
std::string str;
std::string delimiter;
std::vector<std::string> parsed_string;

void splitter() {
ULI len = strlen(str.c_str());
register int ct = 0, sct = 0, inc = 0;
char s[len+1];

while (str[ct] != '\0') {
//std::cout<<ct<<"\n";
if (str[ct] == delimiter[0]) {
while (delimiter[inc] != '\0' && str[ct] != '\0' && str[ct] == delimiter[inc]) {
s[sct+inc] = str[ct++];
inc++;
}
if (delimiter[inc] == '\0') {
s[sct] = '\0';
parsed_string.push_back(s);
sct = 0;
} else {
sct = sct+inc;
}
inc = 0;
} else {
s[sct++] = str[ct++];
}
//std::cout<<ct<<"a\n";
}
s[sct] = '\0';
parsed_string.push_back(s);
}
public:
StringParser(std::string str, std::string delim) {
this->str = str;
delimiter = delim;
parsed_string.clear();

splitter();
}
StringParser(std::string str, char delim) {
std::string t;
t[0] = delim; t[1] = '\0';
StringParser(str, t);
}
std::vector<std::string> GetSplitVector() {
return parsed_string;
}
void SplitString() {
for (register int i = 0; i < parsed_string.size(); i++)
std::cout<<parsed_string[i]<<std::endl;
}
};

#include <iostream>
#include <cstring>
#include "StringParser.h"

using namespace std;

int main() {
string s = "Hello/ World!";
StringParser parser(s,'/');

parser.SplitString();

return 0;
}




Topic archived. No new replies allowed.