mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
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.
92 lines
1.9 KiB
92 lines
1.9 KiB
13 years ago
|
#include "StringUtils.h"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
bool StripString(string& src)
|
||
12 years ago
|
{
|
||
13 years ago
|
size_t pos = 0;
|
||
12 years ago
|
|
||
13 years ago
|
if (src.empty())
|
||
|
{
|
||
12 years ago
|
return false;
|
||
13 years ago
|
}
|
||
12 years ago
|
|
||
13 years ago
|
while ((pos < src.length()) && (' ' == src[pos])) pos++;
|
||
|
src.erase(0, pos);
|
||
12 years ago
|
|
||
13 years ago
|
pos = 0;
|
||
|
while ((pos < src.length()) && ('\t' == src[pos])) pos++;
|
||
|
src.erase(0, pos);
|
||
12 years ago
|
|
||
13 years ago
|
pos = src.length() - 1;
|
||
|
while (pos && (' ' == src[pos])) pos--;
|
||
|
src.erase(pos+1);
|
||
12 years ago
|
|
||
13 years ago
|
pos = src.length() - 1;
|
||
|
while (pos && ('\t' == src[pos])) pos--;
|
||
|
src.erase(pos+1);
|
||
12 years ago
|
|
||
13 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
bool ParseString(const string& src, string& key, string& value)
|
||
|
{
|
||
|
if (src.empty())
|
||
12 years ago
|
return false;
|
||
12 years ago
|
|
||
13 years ago
|
// find seporator ":"
|
||
12 years ago
|
size_t seporator_pos = src.find(":");
|
||
|
if (string::npos != seporator_pos)
|
||
|
{
|
||
|
key = src.substr(0, seporator_pos);
|
||
|
StripString(key);
|
||
|
value = src.substr(seporator_pos+1);
|
||
|
StripString(value);
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
|
set<string> SplitString(const string& src, const char seporator)
|
||
|
{
|
||
|
set<string> result;
|
||
12 years ago
|
|
||
13 years ago
|
if (!src.empty())
|
||
|
{
|
||
12 years ago
|
size_t seporator_pos;
|
||
|
size_t prev_pos = 0;
|
||
|
do
|
||
|
{
|
||
|
seporator_pos = src.find(seporator, prev_pos);
|
||
|
result.insert(src.substr(prev_pos, seporator_pos - prev_pos));
|
||
|
prev_pos = seporator_pos + 1;
|
||
|
}
|
||
|
while (string::npos != seporator_pos);
|
||
13 years ago
|
}
|
||
12 years ago
|
|
||
13 years ago
|
return result;
|
||
|
}
|
||
|
|
||
|
vector<string> SplitStringVector(const string& src, const char seporator)
|
||
|
{
|
||
|
vector<string> result;
|
||
12 years ago
|
|
||
13 years ago
|
if (!src.empty())
|
||
|
{
|
||
12 years ago
|
size_t seporator_pos;
|
||
|
size_t prev_pos = 0;
|
||
|
do
|
||
|
{
|
||
|
seporator_pos = src.find(seporator, prev_pos);
|
||
|
string tmp = src.substr(prev_pos, seporator_pos - prev_pos);
|
||
|
result.push_back(tmp);
|
||
|
prev_pos = seporator_pos + 1;
|
||
|
}
|
||
|
while (string::npos != seporator_pos);
|
||
12 years ago
|
}
|
||
|
|
||
13 years ago
|
return result;
|
||
|
}
|