mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 13:18:57 +08:00
Add listdir to fileop
This commit is contained in:
16
str_util.cpp
16
str_util.cpp
@@ -2,6 +2,10 @@
|
||||
#include "cstr_util.h"
|
||||
#include <malloc.h>
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
bool str_util::tolowercase(std::string ori, std::string& result) {
|
||||
char* tmp = nullptr;
|
||||
auto re = cstr_tolowercase(ori.c_str(), ori.length(), &tmp);
|
||||
@@ -13,3 +17,15 @@ bool str_util::tolowercase(std::string ori, std::string& result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string str_util::str_replace(std::string input, std::string pattern, std::string new_content) {
|
||||
auto loc = input.find(pattern, 0);
|
||||
auto len = pattern.length();
|
||||
auto len2 = new_content.length();
|
||||
while (loc != -1) {
|
||||
input.replace(loc, len, new_content);
|
||||
if (loc + len2 < input.length()) loc = input.find(pattern, max(0, loc + len2));
|
||||
else break;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
Reference in New Issue
Block a user