-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "common/string_utils.h" | ||
|
||
namespace kuzu { | ||
namespace common { | ||
|
||
std::vector<std::string> StringUtils::split( | ||
const std::string& input, const std::string& delimiter) { | ||
auto result = std::vector<std::string>(); | ||
auto prevPos = 0u; | ||
auto currentPos = input.find(delimiter, prevPos); | ||
while (currentPos != std::string::npos) { | ||
result.push_back(input.substr(prevPos, currentPos - prevPos)); | ||
prevPos = currentPos + 1; | ||
currentPos = input.find(delimiter, prevPos); | ||
} | ||
result.push_back(input.substr(prevPos)); | ||
return result; | ||
} | ||
|
||
} // namespace common | ||
} // namespace kuzu |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cstring> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include "spdlog/fmt/fmt.h" | ||
|
||
namespace kuzu { | ||
namespace common { | ||
|
||
class StringUtils { | ||
|
||
public: | ||
template<typename... Args> | ||
inline static std::string string_format(const std::string& format, Args... args) { | ||
return fmt::format(fmt::runtime(format), args...); | ||
} | ||
|
||
static std::vector<std::string> split(const std::string& input, const std::string& delimiter); | ||
|
||
static void toUpper(std::string& input) { | ||
std::transform(input.begin(), input.end(), input.begin(), ::toupper); | ||
} | ||
|
||
static void toLower(std::string& input) { | ||
std::transform(input.begin(), input.end(), input.begin(), ::tolower); | ||
} | ||
|
||
static bool CharacterIsSpace(char c) { | ||
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; | ||
} | ||
|
||
static bool CharacterIsDigit(char c) { return c >= '0' && c <= '9'; } | ||
|
||
static std::string getLongStringErrorMessage( | ||
const char* strToInsert, uint64_t maxAllowedStrSize) { | ||
return string_format("Maximum length of strings is {}. Input string's length is {}.", | ||
maxAllowedStrSize, strlen(strToInsert), strToInsert); | ||
} | ||
}; | ||
|
||
} // namespace common | ||
} // namespace kuzu |
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