Skip to content

Commit

Permalink
Fix build on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Dec 7, 2023
1 parent 907a00e commit 586891c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/xtd.core.native.linux/include/xtd/native/linux/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
#include <sstream>
#include <string>

#undef unix
#undef linux

namespace xtd::native::linux {
class strings final {
public:
strings() = delete;

static bool contains(const std::string& str, const std::string& value) noexcept {
return str.find(value) != str.npos;
}

static bool ends_with(const std::string& str, const std::string& value) noexcept {
return str.rfind(value) + value.size() == str.size();
}

template<typename separator_t, typename collection_t>
static std::string join(const separator_t& separator, const collection_t& values) noexcept {return join(separator, values, 0, values.size());}

template<typename separator_t, typename collection_t>
static std::string join(const separator_t& separator, const collection_t& values, size_t index, size_t count) noexcept {
size_t i = 0;
Expand All @@ -42,43 +42,43 @@ namespace xtd::native::linux {
}
return ss.str();
}

static size_t last_index_of(const std::string& str, char value) noexcept {
return last_index_of(str, value, 0, str.size());
}

static size_t last_index_of(const std::string& str, const std::string& value) noexcept {
return last_index_of(str, value, 0, str.size());
}

static size_t last_index_of(const std::string& str, char value, size_t start_index) noexcept {
return last_index_of(str, value, start_index, str.size() - start_index);
}

static size_t last_index_of(const std::string& str, const std::string& value, size_t start_index) noexcept {
return last_index_of(str, value, start_index, str.size() - start_index);
}

static size_t last_index_of(const std::string& str, char value, size_t start_index, size_t count) noexcept {
size_t result = str.rfind(value, start_index + count - 1);
return result < start_index ? str.npos : result;
}

static size_t last_index_of(const std::string& str, const std::string& value, size_t start_index, size_t count) noexcept {
size_t result = str.rfind(value, start_index + count - value.size());
return result < start_index ? str.npos : result;
}

static std::string remove(const std::string& str, size_t start_index) noexcept {
return remove(str, start_index, str.size() - start_index);
}

static std::string remove(const std::string& str, size_t start_index, size_t count) noexcept {
if (start_index > str.size()) return str;
std::string result(str);
return result.erase(start_index, count);
}

static std::string replace(const std::string& str, const std::string& old_string, const std::string& new_string) noexcept {
std::string result(str);
size_t index = 0;
Expand All @@ -91,11 +91,11 @@ namespace xtd::native::linux {
}
return result;
}

static std::vector<std::string> split(const std::string& str, const std::vector<char>& separators, size_t count = std::numeric_limits<size_t>::max(), bool remove_empty_entries = false) noexcept {
if (count == 0) return {};
if (count == 1) return {str};

std::vector<std::string> list;
std::string subString;
std::vector<char> split_char_separators = separators.size() == 0 ? std::vector<char> {9, 10, 11, 12, 13, 32} : separators;
Expand All @@ -111,30 +111,30 @@ namespace xtd::native::linux {
subString.clear();
}
}

return list;
}

static const std::string to_lower(const std::string& str) noexcept {
std::string result = str;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}

static std::string substring(const std::string& str, size_t start_index, size_t length) noexcept {
if (start_index >= str.size()) return "";
return str.substr(start_index, length);
}


static std::string trim_end(const std::string& str, const std::vector<char>& trim_chars) noexcept {
if (!str.size()) return str;
std::string result(str);
while (std::find(trim_chars.begin(), trim_chars.end(), result[result.size() - 1]) != trim_chars.end())
result.erase(result.size() - 1, 1);
return result;
}

static bool try_parse(const std::string& str, int_least32_t& value) noexcept {
try {
value = std::atoi(str.c_str());
Expand All @@ -143,7 +143,7 @@ namespace xtd::native::linux {
return false;
}
}

};
}

0 comments on commit 586891c

Please sign in to comment.