Skip to content

Commit

Permalink
X
Browse files Browse the repository at this point in the history
  • Loading branch information
mewim committed Apr 6, 2023
1 parent a2f042f commit a099ceb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_library(kuzu_common
null_mask.cpp
profiler.cpp
type_utils.cpp
utils.cpp)
utils.cpp string_utils.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_common>
Expand Down
21 changes: 21 additions & 0 deletions src/common/string_utils.cpp
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
15 changes: 0 additions & 15 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,5 @@ std::string LoggerUtils::getLoggerName(LoggerConstants::LoggerEnum loggerEnum) {
}
}
}

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
45 changes: 45 additions & 0 deletions src/include/common/string_utils.h
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
32 changes: 0 additions & 32 deletions src/include/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "common/constants.h"
#include "exception.h"
#include "spdlog/fmt/fmt.h"

namespace spdlog {
class logger;
Expand All @@ -31,37 +30,6 @@ class LoggerUtils {
static std::string getLoggerName(LoggerConstants::LoggerEnum loggerEnum);
};

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);
}
};

template<typename FROM, typename TO>
std::unique_ptr<TO> ku_static_unique_pointer_cast(std::unique_ptr<FROM>&& old) {
return std::unique_ptr<TO>{static_cast<TO*>(old.release())};
Expand Down

0 comments on commit a099ceb

Please sign in to comment.