First render.
This commit is contained in:
9
src/dawn/util/CMakeLists.txt
Normal file
9
src/dawn/util/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
String.cpp
|
||||
)
|
36
src/dawn/util/String.cpp
Normal file
36
src/dawn/util/String.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::string String::toLowercase(const std::string &str) {
|
||||
std::string result = str;
|
||||
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool_t String::includes(const std::string &str, const std::string &needle) {
|
||||
return str.find(needle) != std::string::npos;
|
||||
}
|
||||
|
||||
std::vector<std::string> String::split(
|
||||
const std::string &s,
|
||||
const std::string &delim
|
||||
) {
|
||||
size_t posStart = 0, posEnd, delimLength = delim.length();
|
||||
std::string token;
|
||||
std::vector<std::string> res;
|
||||
|
||||
while((posEnd = s.find(delim, posStart)) != std::string::npos) {
|
||||
token = s.substr(posStart, posEnd - posStart);
|
||||
posStart = posEnd + delimLength;
|
||||
res.push_back (token);
|
||||
}
|
||||
|
||||
res.push_back(s.substr(posStart));
|
||||
return res;
|
||||
}
|
41
src/dawn/util/String.hpp
Normal file
41
src/dawn/util/String.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class String {
|
||||
public:
|
||||
/**
|
||||
* Converts the given string to lowercase.
|
||||
*
|
||||
* @param str String to convert.
|
||||
* @return The lowercase string.
|
||||
*/
|
||||
static std::string toLowercase(const std::string &str);
|
||||
|
||||
/**
|
||||
* Checks if the given string includes the given needle.
|
||||
*
|
||||
* @param str String to check.
|
||||
* @param needle String to check for.
|
||||
* @return True if the string includes the needle.
|
||||
*/
|
||||
static bool_t includes(const std::string &str, const std::string &needle);
|
||||
|
||||
/**
|
||||
* Splits the given string by the given delimiter.
|
||||
*
|
||||
* @param str String to split.
|
||||
* @param delim Delimiter to split by.
|
||||
* @return The split string.
|
||||
*/
|
||||
static std::vector<std::string> split(
|
||||
const std::string &str,
|
||||
const std::string &delim
|
||||
);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user