Skip to content

Commit

Permalink
Move string utils to utils namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr authored and fvacek committed Oct 22, 2024
1 parent 5b07ea5 commit ee0753f
Show file tree
Hide file tree
Showing 23 changed files with 348 additions and 393 deletions.
4 changes: 2 additions & 2 deletions libshvbroker/src/brokeraclnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <shv/chainpack/cponwriter.h>
#include <shv/chainpack/metamethod.h>
#include <shv/chainpack/rpc.h>
#include <shv/core/string.h>
#include <shv/core/utils.h>
#include <shv/core/log.h>
#include <shv/core/exception.h>
#include <shv/iotqt/acl/aclroleaccessrules.h>
Expand Down Expand Up @@ -588,7 +588,7 @@ unsigned AccessAclNode::keyToRuleIndex(const std::string &key)
if(std::regex_search(key, color_match, color_regex)) {
if (color_match.size() > 1) {
bool ok;
unsigned ix = static_cast<unsigned>(shv::core::string::toInt(color_match[1], &ok));
unsigned ix = static_cast<unsigned>(shv::core::utils::toInt(color_match[1], &ok));
if(ok)
return ix;
}
Expand Down
1 change: 0 additions & 1 deletion libshvbroker/src/brokerapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <shv/coreqt/log.h>

#include <shv/core/string.h>
#include <shv/core/utils.h>
#include <shv/core/assert.h>
#include <shv/core/stringview.h>
Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/src/rpc/masterbrokerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <shv/broker/brokerapp.h>

#include <shv/chainpack/rpcmessage.h>
#include <shv/core/string.h>
#include <shv/core/utils.h>
#include <shv/coreqt/log.h>
#include <shv/core/utils/shvpath.h>
#include <shv/iotqt/rpc/deviceappclioptions.h>
Expand Down
1 change: 0 additions & 1 deletion libshvcore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_library(libshvcore
src/exception.cpp
src/log.cpp
src/string.cpp
src/stringview.cpp
src/utils.cpp
src/utils/abstractshvjournal.cpp
Expand Down
51 changes: 0 additions & 51 deletions libshvcore/include/shv/core/string.h

This file was deleted.

34 changes: 34 additions & 0 deletions libshvcore/include/shv/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <shv/chainpack/rpcvalue.h>

#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -129,11 +130,44 @@ enum class QuoteBehavior {
KeepQuotes,
RemoveQuotes
};

enum class CaseSensitivity {
CaseSensitive,
CaseInsensitive
};

SHVCORE_DECL_EXPORT StringViewList split(StringView strv, char delim, char quote = '\0', SplitBehavior split_behavior = SplitBehavior::SkipEmptyParts, QuoteBehavior quotes_behavior = QuoteBehavior::KeepQuotes);
StringViewList split(std::string&& strv, char delim, char quote = '\0', SplitBehavior split_behavior = SplitBehavior::SkipEmptyParts, QuoteBehavior quotes_behavior = QuoteBehavior::KeepQuotes) = delete;
SHVCORE_DECL_EXPORT StringView getToken(StringView strv, char delim = ' ', char quote = '\0');
SHVCORE_DECL_EXPORT StringView slice(StringView s, int start, int end);

SHVCORE_DECL_EXPORT bool equal(const std::string &a, const std::string &b, CaseSensitivity case_sensitivity);
SHVCORE_DECL_EXPORT std::string::size_type indexOf(const std::string & str_haystack, const std::string &str_needle, CaseSensitivity case_sensitivity = CaseSensitivity::CaseSensitive);
SHVCORE_DECL_EXPORT std::string::size_type indexOf(const std::string &haystack, char needle);

constexpr auto WhiteSpaceChars = " \t\n\r\f\v";
SHVCORE_DECL_EXPORT std::string& rtrim(std::string& s, const char* t = WhiteSpaceChars);
SHVCORE_DECL_EXPORT std::string& ltrim(std::string& s, const char* t = WhiteSpaceChars);
SHVCORE_DECL_EXPORT std::string& trim(std::string& s, const char* t = WhiteSpaceChars);

SHVCORE_DECL_EXPORT std::string mid(const std::string& str, size_t pos, size_t cnt = std::string::npos);

SHVCORE_DECL_EXPORT std::pair<size_t, size_t> indexOfBrackets(const std::string &haystack, size_t begin_pos, size_t end_pos, const std::string &open_bracket, const std::string &close_bracket);
SHVCORE_DECL_EXPORT std::vector<std::string> split(const std::string &str, char delim, SplitBehavior split_behavior = SplitBehavior::SkipEmptyParts);
SHVCORE_DECL_EXPORT std::string join(const std::vector<std::string> &lst, const std::string &delim);
SHVCORE_DECL_EXPORT std::string join(const std::vector<std::string> &lst, char delim);
SHVCORE_DECL_EXPORT std::string join(const std::vector<shv::core::StringView> &lst, char delim);
SHVCORE_DECL_EXPORT int replace(std::string &str, const std::string &from, const std::string &to);
SHVCORE_DECL_EXPORT int replace(std::string &str, const char from, const char to);

SHVCORE_DECL_EXPORT std::string& upper(std::string& s);
SHVCORE_DECL_EXPORT std::string toUpper(const std::string& s);
SHVCORE_DECL_EXPORT std::string& lower(std::string& s);
SHVCORE_DECL_EXPORT std::string toLower(const std::string& s);

SHVCORE_DECL_EXPORT int toInt(const std::string &str, bool *ok = nullptr);
SHVCORE_DECL_EXPORT double toDouble(const std::string &str, bool *ok);

SHVCORE_DECL_EXPORT std::string joinPath(const StringView &p1, const StringView &p2);

template <typename... Types>
Expand Down
2 changes: 1 addition & 1 deletion libshvcore/include/shv/core/utils/shvpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <shv/core/shvcoreglobal.h>

#include <shv/core/string.h>
#include <shv/core/utils.h>

#include <functional>
#include <map>
Expand Down
Loading

0 comments on commit ee0753f

Please sign in to comment.