aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-08 19:24:44 +0800
committercrupest <crupest@outlook.com>2022-01-08 19:24:44 +0800
commit0c7153db084060034092c1dc24222cae384722ec (patch)
tree9de1bc4636732e3cc1e1fb7309fdf2ff60683f69 /include/cru
parentc38f1f7c273e85c0a6d197cb27424c9ca69e234d (diff)
downloadcru-0c7153db084060034092c1dc24222cae384722ec.tar.gz
cru-0c7153db084060034092c1dc24222cae384722ec.tar.bz2
cru-0c7153db084060034092c1dc24222cae384722ec.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/String.hpp8
-rw-r--r--include/cru/common/StringUtil.hpp2
-rw-r--r--include/cru/toml/TomlDocument.hpp1
-rw-r--r--include/cru/toml/TomlParser.hpp7
4 files changed, 16 insertions, 2 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp
index 86e0a134..0ae223cf 100644
--- a/include/cru/common/String.hpp
+++ b/include/cru/common/String.hpp
@@ -165,7 +165,10 @@ class CRU_BASE_API String {
}
inline void append(StringView str);
- String substr(size_type start, size_type size) const {
+ String substr(size_type start, size_type size = -1) const {
+ if (size == -1) {
+ size = this->size_ - start;
+ }
return String(this->buffer_ + start, size);
}
@@ -189,6 +192,9 @@ class CRU_BASE_API String {
std::vector<String> SplitToLines(bool remove_space_line = false) const;
+ bool StartWith(StringView str) const;
+ bool EndWith(StringView str) const;
+
public:
void AppendCodePoint(CodePoint code_point);
diff --git a/include/cru/common/StringUtil.hpp b/include/cru/common/StringUtil.hpp
index a35da695..a0cb6b0b 100644
--- a/include/cru/common/StringUtil.hpp
+++ b/include/cru/common/StringUtil.hpp
@@ -222,5 +222,5 @@ Index CRU_BASE_API Utf16NextWord(const char16_t* ptr, Index size,
char16_t CRU_BASE_API ToLower(char16_t c);
char16_t CRU_BASE_API ToUpper(char16_t c);
-char16_t CRU_BASE_API IsWhitespace(char16_t c);
+bool CRU_BASE_API IsWhitespace(char16_t c);
} // namespace cru
diff --git a/include/cru/toml/TomlDocument.hpp b/include/cru/toml/TomlDocument.hpp
index 9b549daa..637690f7 100644
--- a/include/cru/toml/TomlDocument.hpp
+++ b/include/cru/toml/TomlDocument.hpp
@@ -37,6 +37,7 @@ class TomlDocument {
public:
TomlSection* GetSection(const String& name);
+ TomlSection* GetSectionOrCreate(const String& name);
const TomlSection* GetSection(const String& name) const;
void SetSection(const String& name, TomlSection section);
void DeleteSection(const String& name);
diff --git a/include/cru/toml/TomlParser.hpp b/include/cru/toml/TomlParser.hpp
index b5bcaa0b..52332506 100644
--- a/include/cru/toml/TomlParser.hpp
+++ b/include/cru/toml/TomlParser.hpp
@@ -1,10 +1,17 @@
#pragma once
+#include "cru/common/Exception.hpp"
#include "cru/toml/TomlDocument.hpp"
#include <optional>
namespace cru::toml {
+// A very simple and tolerant TOML parser.
+class TomlParsingException : public Exception {
+ public:
+ using Exception::Exception;
+};
+
class TomlParser {
public:
explicit TomlParser(String input);