18 #ifndef PIC_UTIL_STRING_HPP 19 #define PIC_UTIL_STRING_HPP 27 #include "../base.hpp" 44 #define MAKE_STRING(input_string) #input_string 58 inline std::string
stdStringRep(std::string str, std::string strSub,
61 std::string ret = str;
63 size_t found = ret.find(strSub);
65 if(found != std::string::npos) {
66 ret.replace(found, strRep.length(), strRep);
82 auto n_sub = strSub.size();
83 auto n_rep = strRep.size();
85 std::string ret = str;
86 std::string::size_type pos = ret.find(strSub);
88 while(pos != std::string::npos) {
89 ret.replace(pos, n_sub, strRep);
91 pos = ret.find(strSub, pos + 1 - n_sub + n_rep);
104 std::ostringstream convert;
106 return convert.str();
116 if(path.find(
"/") != std::string::npos) {
119 if(path.find(
"\\") != std::string::npos) {
134 std::string tmp(name);
135 std::reverse(tmp.begin(), tmp.end());
137 size_t pos = tmp.find(
".");
139 if(pos != std::string::npos) {
140 name.erase(name.end() - pos - 1, name.end());
162 pos = name.find(toFind, pos + 1);
163 }
while(pos != std::string::npos);
165 name.erase(0, oldPos + 1);
188 std::string tmp(name);
189 std::reverse(tmp.begin(), tmp.end());
191 size_t pos = tmp.find(
".");
192 std::string ext =
"";
194 if(pos != std::string::npos) {
195 auto n = name.length() - pos;
196 ext = name.substr(n, n);
208 inline std::string
addSuffix(std::string name, std::string suffix)
212 return tmp + suffix +
"." + tmpExt;
225 size_t found = nameOut.find(fmtIn);
227 if(found != std::string::npos) {
228 nameOut.replace(nameOut.begin() + found, nameOut.end(), fmtOut);
244 std::string::size_type pos = str.find(subStr);
246 while(pos != std::string::npos) {
248 pos = str.find(subStr, pos + 1);
261 std::string ret = path;
269 size_t pos1 = path.rfind(toFind);
271 if(pos1 != std::string::npos) {
272 ret = path.substr(0, pos1);
273 size_t pos2 = ret.rfind(toFind);
275 if(pos2 != std::string::npos) {
276 return ret.substr(pos2 + 1, ret.length());
292 return strOut + sepChar;
304 if(found != std::string::npos) {
305 return path.substr(0, found);
319 std::string ret = path;
321 if(path.find(
"/") != std::string::npos) {
324 if(path.find(
"\\") != std::string::npos) {
331 size_t pos = path.rfind(toFind);
333 if(pos != std::string::npos) {
334 ret = path.substr(pos + 1, path.length());
350 std::stringstream ss(str);
354 std::getline(ss, tmpStr, delim);
355 str_vec->push_back(tmpStr);
369 std::string ret = type +
382 std::ifstream infile;
383 infile.open(nameFile.c_str(), std::ios::in);
387 if((!infile.is_open()) || (!infile.good())) {
391 int c = infile.get();
392 while (infile.good()) {
410 if(path.find(
":\\") != std::string::npos) {
414 if(path.find(
":/") != std::string::npos) {
418 if(path.find(
"\\\\\"") != std::string::npos) {
423 return (path.at(0) ==
'/');
433 char *cstr =
new char [str.size() + 1];
434 strcpy (cstr, str.c_str());
445 if(name.length() < 3) {
449 if((name.at(0) ==
'.') && (name.at(0) ==
'.')) {
451 char *path = _getcwd(NULL, 0);
455 char *path = getcwd(NULL, 0);
462 if(name.at(2) ==
'\\' || name.at(2) ==
'/') {
463 name = name.substr(3);
465 name = name.substr(2);
468 std::string newPath = path + dsepPath + name;
481 std::string
adjustPath(std::string nameFile, std::string pathFolder)
484 std::string fullPath =
checkPath(nameFile);
486 if(fullPath.empty()) {
487 std::string ret = pathFolder +
getSeparator(pathFolder) + nameFile;
505 std::string ret = name;
510 pos = ret.find(
'\n');
std::vector< std::string > StringVec
StringVec is an std::vector of std::string.
Definition: string.hpp:49
std::string getLocaDirectory(std::string path)
getLocaDirectory gets local path.
Definition: string.hpp:259
std::string removeInitialSpaces(char name[])
removeInitialSpaces removes spaces at the beginning of a string.
Definition: string.hpp:502
int countSubString(std::string str, std::string subStr)
countSubString counts how many subStr are in str.
Definition: string.hpp:240
std::string fromNumberToString(T num)
fromNumberToString converts a number into a string.
Definition: string.hpp:102
char getSeparatorChar(std::string path)
getSeparatorChar returns the folder separator in path as a char.
Definition: string.hpp:114
std::string getFolderName(std::string path)
getFolderName gets the folder name from the path.
Definition: string.hpp:300
std::string fromFileToStdString(std::string nameFile)
fromFileToStdString writes a file into a std::string.
Definition: string.hpp:380
std::string addSuffix(std::string name, std::string suffix)
addSuffix adds a suffix to a file name.
Definition: string.hpp:208
void parseStringToStdVector(std::string str, char delim, StringVec *str_vec)
parseStringToStdVector
Definition: string.hpp:347
std::string getSeparator(std::string path)
getSeparator returns the folder separator in path as a string
Definition: string.hpp:288
std::string getFileName(std::string path)
getFileName gets the file name.
Definition: string.hpp:316
std::string checkPath(std::string name)
checkPath
Definition: string.hpp:443
std::string getFileNameOnly(std::string name)
getFileNameOnly
Definition: string.hpp:176
std::string getExtension(std::string name)
getExtension gets the extension of a file name.
Definition: string.hpp:186
std::string adjustPath(std::string nameFile, std::string pathFolder)
adjustPath modifies the path if it is not global.
Definition: string.hpp:481
std::string genBilString(std::string type, float sigma_s, float sigma_r)
genBilString
Definition: string.hpp:366
std::string stdStringRepAll(std::string str, std::string strSub, std::string strRep)
stdStringRepAll replaces all strSub in str with strRep.
Definition: string.hpp:79
bool checkAbsolutePath(std::string path)
checkAbsolutePath checks if the path is absolute or not.
Definition: string.hpp:407
Definition: bilateral_separation.hpp:25
std::string removeExtension(std::string name)
RemoveExtension removes the extension of a string.
Definition: string.hpp:132
std::string removeLocalPath(std::string name)
removeLocalPath removes the local path of a string.
Definition: string.hpp:151
std::string stdStringRep(std::string str, std::string strSub, std::string strRep)
stdStringRep replaces strSub in str with strRep just once.
Definition: string.hpp:58
std::string replaceExtension(std::string nameOut, std::string fmtIn, std::string fmtOut)
replaceExtension changes .format in a file name.
Definition: string.hpp:222
char * fromStdStringToChar(std::string str)
fromStdStringToChar converts from a std::string to a char*.
Definition: string.hpp:431