Esempio n. 1
0
// removes punctuation and redundant
// spaces from the user's input
void cleanString( std::string &str ) {
	int len = str.length();
	std::string temp = "";

	char prevChar = 0;

	for(int i = 0; i < len; ++i) {
		if( (str[i] == ' ' && prevChar != ' ') || !isPunc(str[i]) ) {
			temp += str[i];
			prevChar = str[i];
		}	
		else if(prevChar != ' ' && isPunc(str[i])) {
			temp += ' ';
		}
	}
	str = temp;
}
Esempio n. 2
0
//splits a line into words
void SplitToWords(const std::string str, Vstr &v) {
    std::string buffer;
    for(int i = 0; i < str.length(); ++i) {
        if(!isPunc(str[i]) && !isspace(str[i]) && str[i] != '.') {
            buffer += str[i];
        } else if(!buffer.empty()) {
            v.push_back(buffer);
            buffer.erase();
        }
    }
    if((v.empty() && !buffer.empty()) || !buffer.empty()) {
        v.push_back(buffer);
    }
}