diff --git a/exporters/translation_exporter.cpp b/exporters/translation_exporter.cpp index 6bca858d..caedf232 100644 --- a/exporters/translation_exporter.cpp +++ b/exporters/translation_exporter.cpp @@ -1,6 +1,5 @@ #include "translation_exporter.h" -#include "../../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config" #include "compat/optimized_translation_extractor.h" #include "compat/resource_loader_compat.h" #include "exporters/export_report.h" diff --git a/utility/common.cpp b/utility/common.cpp index 263d5210..777a41a6 100644 --- a/utility/common.cpp +++ b/utility/common.cpp @@ -93,6 +93,7 @@ class GodotFileInterface : public tga::FileInterface { GodotFileInterface(const String &p_path, FileAccess::ModeFlags p_mode) { m_file = FileAccess::open(p_path, p_mode); } + // Returns true if we can read/write bytes from/into the file virtual bool ok() const override { return m_file.is_valid(); @@ -486,4 +487,106 @@ bool gdre::dir_is_empty(const String &dir) { f = da->get_next(); } return true; -} \ No newline at end of file +} + +//void get_chars_in_set(const String &s, const HashSet &chars, HashSet &ret); + +void gdre::get_chars_in_set(const String &s, const HashSet &chars, HashSet &ret) { + for (int i = 0; i < s.length(); i++) { + if (chars.has(s[i])) { + ret.insert(s[i]); + } + } +} + +bool gdre::has_chars_in_set(const String &s, const HashSet &chars) { + for (int i = 0; i < s.length(); i++) { + if (chars.has(s[i])) { + return true; + } + } + return false; +} + +String gdre::remove_chars(const String &s, const HashSet &chars) { + String ret; + for (int i = 0; i < s.length(); i++) { + if (!chars.has(s[i])) { + ret += s[i]; + } + } + return ret; +} + +Vector gdre::split_multichar(const String &s, const HashSet &splitters, bool allow_empty, int maxsplit) { + Vector ret; + String current; + int i; + for (i = 0; i < s.length(); i++) { + if (splitters.has(s[i])) { + if (current.length() > 0 || allow_empty) { + ret.push_back(current); + current = ""; + if (maxsplit > 0 && ret.size() >= maxsplit - 1) { + i++; + break; + } + } + } else { + current += s[i]; + } + } + if (i < s.length()) { + current += s.substr(i, s.length()); + } + if (current.length() > 0 || allow_empty) { + ret.push_back(current); + } + return ret; +} + +Vector gdre::rsplit_multichar(const String &s, const HashSet &splitters, bool allow_empty, int maxsplit) { + Vector ret; + String current; + int i; + for (i = s.length() - 1; i >= 0; i--) { + if (splitters.has(s[i])) { + if (current.length() > 0 || allow_empty) { + ret.push_back(current); + current = ""; + if (maxsplit > 0 && ret.size() >= maxsplit - 1) { + i--; + break; + } + } + } else { + current = s[i] + current; + } + } + if (i >= 0) { + current = s.substr(0, i + 1) + current; + } + if (current.length() > 0 || allow_empty) { + ret.push_back(current); + } + ret.reverse(); + return ret; +} + +bool gdre::string_has_whitespace(const String &s) { + for (int i = 0; i < s.length(); i++) { + if (s[i] == ' ' || s[i] == '\t' || s[i] == '\n') { + return true; + } + } + return false; +}; + +bool gdre::string_is_ascii(const String &s) { + for (int i = 0; i < s.length(); i++) { + if (s[i] > 127) { + return false; + } + } + return true; +}; \ No newline at end of file diff --git a/utility/common.h b/utility/common.h index a0881e30..3b179887 100644 --- a/utility/common.h +++ b/utility/common.h @@ -59,6 +59,24 @@ bool hashset_intersects_vector(const HashSet &a, const Vector &b) { return false; } +template +Vector get_keys(const HashMap &map) { + Vector ret; + for (const auto &E : map) { + ret.push_back(E.key); + } + return ret; +} + +template +HashSet get_set_of_keys(const HashMap &map) { + HashSet ret; + for (const auto &E : map) { + ret.insert(E.key); + } + return ret; +} + template Vector get_vector_intersection(const Vector &a, const Vector &b) { Vector ret; @@ -87,6 +105,15 @@ void shuffle_vector(Vector &vec) { } } +bool string_is_ascii(const String &s); +bool string_has_whitespace(const String &s); +void get_chars_in_set(const String &s, const HashSet &chars, HashSet &ret); +bool has_chars_in_set(const String &s, const HashSet &chars); +String remove_chars(const String &s, const HashSet &chars); +Vector split_multichar(const String &s, const HashSet &splitters, bool allow_empty = true, + int maxsplit = 0); +Vector rsplit_multichar(const String &s, const HashSet &splitters, bool allow_empty = true, + int maxsplit = 0); } // namespace gdre #define GDRE_ERR_DECOMPRESS_OR_FAIL(img) \