aboutsummaryrefslogtreecommitdiff
path: root/src/StringUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-11 00:42:21 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-11 00:42:21 +0100
commit1f74222bf4cfadead768b095c6b3f8d422ebf84c (patch)
tree39035288edb79852cef6237f0d7ab8ea146cf218 /src/StringUtils.cpp
parent404ac476a213164a041f0f53be30855df815aa6a (diff)
Add local-manga plugin to read local manga
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r--src/StringUtils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 81ea1eb..927c6e1 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -122,15 +122,43 @@ namespace QuickMedia {
}
size_t str_find_case_insensitive(const std::string &str, size_t start_index, const char *substr, size_t substr_len) {
+ if(substr_len == 0)
+ return 0;
+
auto it = std::search(str.begin() + start_index, str.end(), substr, substr + substr_len,
[](char c1, char c2) {
return to_upper(c1) == to_upper(c2);
});
+
if(it == str.end())
return std::string::npos;
+
return it - str.begin();
}
+ // TODO: Support utf-8 case insensitive find
+ bool string_find_fuzzy_case_insensitive(const std::string &str, const std::string &substr) {
+ if(substr.empty()) return true;
+
+ size_t str_index = 0;
+ bool full_match = true;
+
+ string_split(substr, ' ', [&str, &str_index, &full_match](const char *str_part, size_t size) {
+ if(size == 0) return true;
+
+ size_t found_index = str_find_case_insensitive(str, str_index, str_part, size);
+ if(found_index == std::string::npos) {
+ full_match = false;
+ return false;
+ }
+
+ str_index = found_index + size;
+ return true;
+ });
+
+ return full_match;
+ }
+
char to_upper(char c) {
if(c >= 'a' && c <= 'z')
return c - 32;
@@ -173,6 +201,9 @@ namespace QuickMedia {
}
bool to_num(const char *str, size_t size, int &num) {
+ if(size == 0)
+ return false;
+
size_t i = 0;
const bool is_negative = size > 0 && str[0] == '-';
if(is_negative)
@@ -193,6 +224,9 @@ namespace QuickMedia {
}
bool to_num_hex(const char *str, size_t size, int &num) {
+ if(size == 0)
+ return false;
+
size_t i = 0;
const bool is_negative = size > 0 && str[0] == '-';
if(is_negative)