Moving replace function to strutil.hpp

This commit is contained in:
meeh
2018-09-19 16:03:39 +00:00
parent 281c5f579f
commit 9b958e4427
2 changed files with 25 additions and 21 deletions

View File

@@ -53,16 +53,12 @@ inline std::string extractString(CFStringRef value)
} }
} }
using std::experimental::optional; bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
// Use CFStringRef instead of NSString*, otherwise disable ARC if(start_pos == std::string::npos)
inline optional<CFStringRef> optionalString(bool val) { return false;
optional<CFStringRef> myOptString; str.replace(start_pos, from.length(), to);
if(val) { return true;
// Cast to corresponding CoreFoundation object
myOptString = (CFStringRef)@"String";
}
return myOptString;
} }
@@ -102,4 +98,22 @@ static inline std::string trim_copy(std::string s) {
return s; return s;
} }
#ifdef CPP17
using std::experimental::optional;
// Use CFStringRef instead of NSString*, otherwise disable ARC
inline optional<CFStringRef> optionalString(bool val) {
optional<CFStringRef> myOptString;
if(val) {
// Cast to corresponding CoreFoundation object
myOptString = (CFStringRef)@"String";
}
return myOptString;
}
#endif
#endif #endif

View File

@@ -84,17 +84,6 @@ void setGlobalRouterIsRunning(bool running)
@implementation ExtractMetaInfo : NSObject @implementation ExtractMetaInfo : NSObject
@end @end
#ifdef __cplusplus
bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
#endif
@implementation AppDelegate @implementation AppDelegate
@@ -109,6 +98,7 @@ bool replace(std::string& str, const std::string& from, const std::string& to) {
#include <assert.h> #include <assert.h>
#include "include/subprocess.hpp" #include "include/subprocess.hpp"
#include "include/strutil.hpp"
using namespace subprocess; using namespace subprocess;