-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Agent/Worker comm using files in Python and Cpp (#421)
- Loading branch information
Showing
10 changed files
with
236 additions
and
368 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/cpp/ArmoniK.Api.Common/header/utils/string_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cctype> | ||
#include <locale> | ||
#include <string> | ||
|
||
namespace armonik { | ||
namespace api { | ||
namespace common { | ||
namespace utils { | ||
// trim from start (in place) | ||
static inline void ltrim(std::string &s) { | ||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); | ||
} | ||
|
||
// trim from end (in place) | ||
static inline void rtrim(std::string &s) { | ||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); | ||
} | ||
|
||
// trim from both ends (in place) | ||
static inline void trim(std::string &s) { | ||
rtrim(s); | ||
ltrim(s); | ||
} | ||
|
||
// trim from start (copying) | ||
static inline std::string ltrim_copy(std::string s) { | ||
ltrim(s); | ||
return s; | ||
} | ||
|
||
// trim from end (copying) | ||
static inline std::string rtrim_copy(std::string s) { | ||
rtrim(s); | ||
return s; | ||
} | ||
|
||
// trim from both ends (copying) | ||
static inline std::string trim_copy(std::string s) { | ||
trim(s); | ||
return s; | ||
} | ||
|
||
inline std::string pathJoin(const std::string &p1, const std::string &p2) { | ||
#ifdef _WIN32 | ||
constexpr char sep = '\\'; | ||
#else | ||
constexpr char sep = '/'; | ||
#endif | ||
std::string tmp = trim_copy(p1); | ||
|
||
if (tmp[tmp.length() - 1] != sep) { | ||
tmp += sep; | ||
} | ||
return tmp + trim_copy(p2); | ||
} | ||
} // namespace utils | ||
} // namespace common | ||
} // namespace api | ||
} // namespace armonik |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.