You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.8 KiB
97 lines
1.8 KiB
/**
|
|
* @file string_helper.cpp
|
|
* @brief string utility functions' implemention
|
|
* @author James
|
|
* @history
|
|
* ===================================================================================
|
|
* Date Name Description of Change
|
|
* 09-July-2008 James
|
|
* 14-Jau-2009 James modify Split functions, add trim blank characters
|
|
*/
|
|
#pragma warning(disable:4996)
|
|
#include "string_helper.h"
|
|
|
|
string TrimString(string strArg)
|
|
{
|
|
size_t index1 = 0;
|
|
index1 = strArg.find_first_not_of(' ');
|
|
if (index1 != string::npos)
|
|
strArg.erase(strArg.begin(), strArg.begin() + index1);
|
|
index1 = strArg.find_last_not_of(' ');
|
|
if (index1 != string::npos)
|
|
strArg.erase(strArg.begin() + index1 + 1);
|
|
return strArg;
|
|
}
|
|
|
|
void Split(string strArg, char spliter, vector<string>& ans)
|
|
{
|
|
ans.clear();
|
|
size_t index0 = 0;
|
|
string one_arg;
|
|
if (strArg.find_first_not_of(' ') == string::npos)
|
|
strArg = "";
|
|
while (strArg.size() > 0)
|
|
{
|
|
index0 = strArg.find_first_of(spliter);
|
|
if (index0 != string::npos)
|
|
{
|
|
one_arg = strArg.substr(0, index0);
|
|
strArg = strArg.substr(index0 + 1);
|
|
ans.push_back(one_arg);
|
|
}
|
|
else
|
|
{
|
|
ans.push_back(strArg);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Split(string strArg, string spliter, vector<string>& ans)
|
|
{
|
|
|
|
ans.clear();
|
|
|
|
size_t index0;
|
|
string one_arg;
|
|
|
|
if (strArg.find_first_not_of(" ") == string::npos)
|
|
strArg = "";
|
|
|
|
|
|
while (strArg.size() > 0)
|
|
{
|
|
|
|
index0 = strArg.find(spliter);
|
|
|
|
if (index0 != string::npos)
|
|
{
|
|
|
|
one_arg = strArg.substr(0, index0);
|
|
strArg = strArg.substr(index0 + spliter.size());
|
|
|
|
ans.push_back(one_arg);
|
|
}
|
|
else
|
|
{
|
|
|
|
ans.push_back(strArg);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void RemoveLiner(string& in, string& out)
|
|
{
|
|
char buf[BUFSIZ] = "";
|
|
for (int i = 0; i < (int)in.size(); i++)
|
|
{
|
|
if (in[i] == '\n')
|
|
continue;
|
|
else
|
|
sprintf(buf, "%s%c", buf, in[i]);
|
|
}
|
|
out.assign(buf);
|
|
}
|
|
|