*added split(s,d) function for strings

*reading unit xml healthbar node
*adjusted hpbars
This commit is contained in:
titison
2014-10-29 00:50:45 +01:00
parent 034b6066be
commit de5135bfaf
6 changed files with 114 additions and 25 deletions

View File

@@ -13,6 +13,7 @@
#define _SHARED_UTIL_UTIL_H_
#include <string>
#include <vector>
#include <fstream>
#include <map>
#include "thread.h"
@@ -226,6 +227,7 @@ string cutLastFile(const string &s);
string cutLastExt(const string &s);
string ext(const string &s);
string replaceBy(const string &s, char c1, char c2);
vector<string> split(string s,string d);
string toLower(const string &s);
void copyStringToBuffer(char *buffer, int bufferSize, const string& s);

View File

@@ -709,6 +709,22 @@ string replaceBy(const string &s, char c1, char c2){
return rs;
}
vector<string> split(string s,string d) {
vector<string> results;
size_t lastOffset = 0;
while(true)
{
size_t offset = s.find_first_of(d, lastOffset);
results.push_back(s.substr(lastOffset, offset - lastOffset));
if (offset == string::npos)
break;
else
lastOffset = offset + d.size(); //skip the delimiter
}
return results;
}
string toLower(const string &s){
string rs= s;