inline auto execute(const string& name, P&&... p) -> execute_result_t {
lstring argl(name, forward(p)...);
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
string arguments = argl.merge(" ");
@@ -91,19 +119,24 @@ template inline auto execute(const string& name, P&&... p) -> str
HANDLE stdoutRead;
HANDLE stdoutWrite;
- if(!CreatePipe(&stdoutRead, &stdoutWrite, &sa, 0)) return "";
- if(!SetHandleInformation(stdoutRead, HANDLE_FLAG_INHERIT, 0)) return "";
+ if(!CreatePipe(&stdoutRead, &stdoutWrite, &sa, 0)) return {};
+ if(!SetHandleInformation(stdoutRead, HANDLE_FLAG_INHERIT, 0)) return {};
+
+ HANDLE stderrRead;
+ HANDLE stderrWrite;
+ if(!CreatePipe(&stderrRead, &stderrWrite, &sa, 0)) return {};
+ if(!SetHandleInformation(stderrRead, HANDLE_FLAG_INHERIT, 0)) return {};
HANDLE stdinRead;
HANDLE stdinWrite;
- if(!CreatePipe(&stdinRead, &stdinWrite, &sa, 0)) return "";
- if(!SetHandleInformation(stdinWrite, HANDLE_FLAG_INHERIT, 0)) return "";
+ if(!CreatePipe(&stdinRead, &stdinWrite, &sa, 0)) return {};
+ if(!SetHandleInformation(stdinWrite, HANDLE_FLAG_INHERIT, 0)) return {};
STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
- si.hStdError = stdoutWrite;
si.hStdOutput = stdoutWrite;
+ si.hStdError = stderrWrite;
si.hStdInput = stdinRead;
si.dwFlags = STARTF_USESTDHANDLES;
@@ -114,15 +147,19 @@ template inline auto execute(const string& name, P&&... p) -> str
nullptr, utf16_t(arguments),
nullptr, nullptr, true, CREATE_NO_WINDOW,
nullptr, nullptr, &si, &pi
- )) return "";
+ )) return {};
- if(WaitForSingleObject(pi.hProcess, INFINITE)) return "";
+ DWORD exitCode = EXIT_FAILURE;
+ if(WaitForSingleObject(pi.hProcess, INFINITE)) return {};
+ if(!GetExitCodeProcess(pi.hProcess, &exitCode)) return {};
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
- string result;
+ char buffer[256];
+ execute_result_t result;
+ result.code = exitCode;
+
while(true) {
- char buffer[256];
DWORD read, available, remaining;
if(!PeekNamedPipe(stdoutRead, nullptr, sizeof(buffer), &read, &available, &remaining)) break;
if(read == 0) break;
@@ -130,9 +167,22 @@ template inline auto execute(const string& name, P&&... p) -> str
if(!ReadFile(stdoutRead, buffer, sizeof(buffer), &read, nullptr)) break;
if(read == 0) break;
- auto offset = result.size();
- result.resize(offset + read);
- memory::copy(result.get() + offset, buffer, read);
+ auto offset = result.output.size();
+ result.output.resize(offset + read);
+ memory::copy(result.output.get() + offset, buffer, read);
+ }
+
+ while(true) {
+ DWORD read, available, remaining;
+ if(!PeekNamedPipe(stderrRead, nullptr, sizeof(buffer), &read, &available, &remaining)) break;
+ if(read == 0) break;
+
+ if(!ReadFile(stderrRead, buffer, sizeof(buffer), &read, nullptr)) break;
+ if(read == 0) break;
+
+ auto offset = result.error.size();
+ result.error.resize(offset + read);
+ memory::copy(result.error.get() + offset, buffer, read);
}
return result;
diff --git a/nall/set.hpp b/nall/set.hpp
index 2c3a405b..507db8db 100644
--- a/nall/set.hpp
+++ b/nall/set.hpp
@@ -49,8 +49,8 @@ template struct set {
return *this;
}
+ explicit operator bool() const { return nodes; }
auto size() const -> unsigned { return nodes; }
- auto empty() const -> bool { return nodes == 0; }
auto reset() -> void {
reset(root);
@@ -100,13 +100,13 @@ template struct set {
auto operator++() -> base_iterator& {
if(++position >= source.size()) { position = source.size(); return *this; }
- if(stack.last()->link[1]) {
- stack.append(stack.last()->link[1]);
- while(stack.last()->link[0]) stack.append(stack.last()->link[0]);
+ if(stack.right()->link[1]) {
+ stack.append(stack.right()->link[1]);
+ while(stack.right()->link[0]) stack.append(stack.right()->link[0]);
} else {
node_t* child;
- do child = stack.take();
- while(child == stack.last()->link[1]);
+ do child = stack.takeRight();
+ while(child == stack.right()->link[1]);
}
return *this;
@@ -128,7 +128,7 @@ template struct set {
struct iterator : base_iterator {
iterator(const set& source, unsigned position) : base_iterator(source, position) {}
- auto operator*() const -> T& { return base_iterator::stack.last()->value; }
+ auto operator*() const -> T& { return base_iterator::stack.right()->value; }
};
auto begin() -> iterator { return iterator(*this, 0); }
@@ -136,7 +136,7 @@ template struct set {
struct const_iterator : base_iterator {
const_iterator(const set& source, unsigned position) : base_iterator(source, position) {}
- auto operator*() const -> const T& { return base_iterator::stack.last()->value; }
+ auto operator*() const -> const T& { return base_iterator::stack.right()->value; }
};
auto begin() const -> const const_iterator { return const_iterator(*this, 0); }
diff --git a/nall/shared-pointer.hpp b/nall/shared-pointer.hpp
index af44bde8..634d02a8 100644
--- a/nall/shared-pointer.hpp
+++ b/nall/shared-pointer.hpp
@@ -170,11 +170,7 @@ struct shared_pointer {
}
explicit operator bool() const {
- return !empty();
- }
-
- auto empty() const -> bool {
- return !manager || !manager->strong;
+ return manager && manager->strong;
}
auto unique() const -> bool {
@@ -242,11 +238,7 @@ struct shared_pointer_weak {
}
explicit operator bool() const {
- return !empty();
- }
-
- auto empty() const -> bool {
- return !manager || !manager->strong;
+ return manager && manager->strong;
}
auto acquire() const -> shared_pointer {
diff --git a/nall/smtp.hpp b/nall/smtp.hpp
index f1f60dea..b3bca32b 100644
--- a/nall/smtp.hpp
+++ b/nall/smtp.hpp
@@ -272,7 +272,7 @@ auto SMTP::contacts(const vector& contacts) -> string {
for(auto& contact : contacts) {
result.append(this->contact(contact), "; ");
}
- result.rtrim("; ", 1L);
+ result.trimRight("; ", 1L);
return result;
}
diff --git a/nall/stream/stream.hpp b/nall/stream/stream.hpp
index a9e1a64a..e2d23d92 100644
--- a/nall/stream/stream.hpp
+++ b/nall/stream/stream.hpp
@@ -29,10 +29,6 @@ struct stream {
return size();
}
- auto empty() const -> bool {
- return size() == 0;
- }
-
auto end() const -> bool {
return offset() >= size();
}
diff --git a/nall/string.hpp b/nall/string.hpp
index b38ba8fe..63e71125 100644
--- a/nall/string.hpp
+++ b/nall/string.hpp
@@ -20,12 +20,305 @@
#include
#include
#include
-#include
-#include
-#include
-#include
-#include
+namespace nall {
+
+struct string;
+struct format;
+struct lstring;
+
+struct string_view {
+ inline string_view();
+ inline string_view(const string_view& source);
+ inline string_view(string_view&& source);
+ inline string_view(const char* data);
+ inline string_view(const char* data, uint size);
+ inline string_view(const string& source);
+ template inline string_view(P&&... p);
+ inline ~string_view();
+
+ inline auto operator=(const string_view& source) -> string_view&;
+ inline auto operator=(string_view&& source) -> string_view&;
+
+ inline operator const char*() const;
+ inline auto data() const -> const char*;
+ inline auto size() const -> uint;
+
+protected:
+ string* _string;
+ const char* _data;
+ mutable int _size;
+};
+
+#define NALL_STRING_ALLOCATOR_ADAPTIVE
+//#define NALL_STRING_ALLOCATOR_COPY_ON_WRITE
+//#define NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION
+//#define NALL_STRING_ALLOCATOR_VECTOR
+
+//cast.hpp
+template struct stringify;
+
+//format.hpp
+template inline auto print(P&&...) -> void;
+template inline auto print(FILE*, P&&...) -> void;
+inline auto integer(intmax value, long precision = 0, char padchar = '0') -> string;
+inline auto natural(uintmax value, long precision = 0, char padchar = '0') -> string;
+inline auto hex(uintmax value, long precision = 0, char padchar = '0') -> string;
+inline auto octal(uintmax value, long precision = 0, char padchar = '0') -> string;
+inline auto binary(uintmax value, long precision = 0, char padchar = '0') -> string;
+template inline auto pointer(const T* value, long precision = 0) -> string;
+inline auto pointer(uintptr value, long precision = 0) -> string;
+inline auto real(long double value) -> string;
+
+//match.hpp
+inline auto tokenize(const char* s, const char* p) -> bool;
+inline auto tokenize(lstring& list, const char* s, const char* p) -> bool;
+
+//path.hpp
+inline auto pathname(string_view self) -> string;
+inline auto filename(string_view self) -> string;
+
+inline auto dirname(string_view self) -> string;
+inline auto basename(string_view self) -> string;
+inline auto prefixname(string_view self) -> string;
+inline auto suffixname(string_view self) -> string;
+
+//utility.hpp
+inline auto slice(string_view self, int offset = 0, int length = -1) -> string;
+
+inline auto integer(char* result, intmax value) -> char*;
+inline auto natural(char* result, uintmax value) -> char*;
+inline auto real(char* str, long double value) -> uint;
+
+struct string {
+ using type = string;
+
+protected:
+ #if defined(NALL_STRING_ALLOCATOR_ADAPTIVE)
+ enum : uint { SSO = 24 };
+ union {
+ struct { //copy-on-write
+ char* _data;
+ uint* _refs;
+ };
+ struct { //small-string-optimization
+ char _text[SSO];
+ };
+ };
+ inline auto _allocate() -> void;
+ inline auto _copy() -> void;
+ inline auto _resize() -> void;
+ #endif
+
+ #if defined(NALL_STRING_ALLOCATOR_COPY_ON_WRITE)
+ char* _data;
+ mutable uint* _refs;
+ inline auto _allocate() -> char*;
+ inline auto _copy() -> char*;
+ #endif
+
+ #if defined(NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION)
+ enum : uint { SSO = 24 };
+ union {
+ char* _data;
+ char _text[SSO];
+ };
+ #endif
+
+ #if defined(NALL_STRING_ALLOCATOR_VECTOR)
+ char* _data;
+ #endif
+
+ uint _capacity;
+ uint _size;
+
+public:
+ inline string();
+ template inline auto get() -> T*;
+ template inline auto data() const -> const T*;
+ inline auto reset() -> type&;
+ inline auto reserve(uint) -> type&;
+ inline auto resize(uint) -> type&;
+ inline auto operator=(const string&) -> type&;
+ inline auto operator=(string&&) -> type&;
+
+ template string(T&& s, P&&... p) : string() {
+ append(forward(s), forward(p)...);
+ }
+ ~string() { reset(); }
+
+ explicit operator bool() const { return _size; }
+ operator const char*() const { return (const char*)data(); }
+
+ auto size() const -> uint { return _size; }
+ auto capacity() const -> uint { return _capacity; }
+
+ auto operator==(const string& source) const -> bool {
+ return size() == source.size() && memory::compare(data(), source.data(), size()) == 0;
+ }
+ auto operator!=(const string& source) const -> bool {
+ return size() != source.size() || memory::compare(data(), source.data(), size()) != 0;
+ }
+
+ auto operator==(const char* source) const -> bool { return strcmp(data(), source) == 0; }
+ auto operator!=(const char* source) const -> bool { return strcmp(data(), source) != 0; }
+
+ auto operator==(string_view source) const -> bool { return compare(source) == 0; }
+ auto operator!=(string_view source) const -> bool { return compare(source) != 0; }
+ auto operator< (string_view source) const -> bool { return compare(source) < 0; }
+ auto operator<=(string_view source) const -> bool { return compare(source) <= 0; }
+ auto operator> (string_view source) const -> bool { return compare(source) > 0; }
+ auto operator>=(string_view source) const -> bool { return compare(source) >= 0; }
+
+ string(const string& source) : string() { operator=(source); }
+ string(string&& source) : string() { operator=(move(source)); }
+
+ auto begin() -> char* { return &get()[0]; }
+ auto end() -> char* { return &get()[size()]; }
+ auto begin() const -> const char* { return &data()[0]; }
+ auto end() const -> const char* { return &data()[size()]; }
+
+ //atoi.hpp
+ inline auto integer() const -> intmax;
+ inline auto natural() const -> uintmax;
+ inline auto real() const -> double;
+
+ //core.hpp
+ inline auto operator[](int) const -> const char&;
+ template inline auto assign(P&&...) -> type&;
+ template inline auto append(const T&, P&&...) -> type&;
+ template inline auto append(const nall::format&, P&&...) -> type&;
+ inline auto append() -> type&;
+ template inline auto _append(const stringify&) -> string&;
+ inline auto length() const -> uint;
+
+ //datetime.hpp
+ inline static auto date(time_t = 0) -> string;
+ inline static auto time(time_t = 0) -> string;
+ inline static auto datetime(time_t = 0) -> string;
+
+ //find.hpp
+ template inline auto _find(int, string_view) const -> maybe;
+
+ inline auto find(string_view source) const -> maybe;
+ inline auto ifind(string_view source) const -> maybe;
+ inline auto qfind(string_view source) const -> maybe;
+ inline auto iqfind(string_view source) const -> maybe;
+
+ inline auto findFrom(int offset, string_view source) const -> maybe;
+ inline auto ifindFrom(int offset, string_view source) const -> maybe;
+
+ //format.hpp
+ inline auto format(const nall::format& params) -> type&;
+
+ //compare.hpp
+ template inline static auto _compare(const char*, uint, const char*, uint) -> int;
+
+ inline static auto compare(string_view, string_view) -> int;
+ inline static auto icompare(string_view, string_view) -> int;
+
+ inline auto compare(string_view source) const -> int;
+ inline auto icompare(string_view source) const -> int;
+
+ inline auto equals(string_view source) const -> bool;
+ inline auto iequals(string_view source) const -> bool;
+
+ inline auto beginsWith(string_view source) const -> bool;
+ inline auto ibeginsWith(string_view source) const -> bool;
+
+ inline auto endsWith(string_view source) const -> bool;
+ inline auto iendsWith(string_view source) const -> bool;
+
+ //convert.hpp
+ inline auto downcase() -> type&;
+ inline auto upcase() -> type&;
+
+ inline auto qdowncase() -> type&;
+ inline auto qupcase() -> type&;
+
+ inline auto transform(string_view from, string_view to) -> type&;
+
+ //match.hpp
+ inline auto match(string_view source) const -> bool;
+ inline auto imatch(string_view source) const -> bool;
+
+ //replace.hpp
+ template inline auto _replace(string_view, string_view, long) -> type&;
+ inline auto replace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
+ inline auto ireplace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
+ inline auto qreplace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
+ inline auto iqreplace(string_view from, string_view to, long limit = LONG_MAX) -> type&;
+
+ //split.hpp
+ inline auto split(string_view key, long limit = LONG_MAX) const -> lstring;
+ inline auto isplit(string_view key, long limit = LONG_MAX) const -> lstring;
+ inline auto qsplit(string_view key, long limit = LONG_MAX) const -> lstring;
+ inline auto iqsplit(string_view key, long limit = LONG_MAX) const -> lstring;
+
+ //trim.hpp
+ inline auto trim(string_view lhs, string_view rhs, long limit = LONG_MAX) -> type&;
+ inline auto trimLeft(string_view lhs, long limit = LONG_MAX) -> type&;
+ inline auto trimRight(string_view rhs, long limit = LONG_MAX) -> type&;
+
+ inline auto itrim(string_view lhs, string_view rhs, long limit = LONG_MAX) -> type&;
+ inline auto itrimLeft(string_view lhs, long limit = LONG_MAX) -> type&;
+ inline auto itrimRight(string_view rhs, long limit = LONG_MAX) -> type&;
+
+ inline auto strip() -> type&;
+ inline auto stripLeft() -> type&;
+ inline auto stripRight() -> type&;
+
+ //utility.hpp
+ inline static auto read(string_view filename) -> string;
+ inline static auto repeat(string_view pattern, uint times) -> string;
+ inline auto fill(char fill = ' ') -> type&;
+ inline auto hash() const -> uint;
+ inline auto remove(uint offset, uint length) -> type&;
+ inline auto reverse() -> type&;
+ inline auto size(int length, char fill = ' ') -> type&;
+};
+
+struct lstring : vector {
+ using type = lstring;
+
+ lstring(const lstring& source) { vector::operator=(source); }
+ lstring(lstring& source) { vector::operator=(source); }
+ lstring(lstring&& source) { vector::operator=(move(source)); }
+ template lstring(P&&... p) { append(forward(p)...); }
+
+ //list.hpp
+ inline auto operator==(const lstring&) const -> bool;
+ inline auto operator!=(const lstring&) const -> bool;
+
+ inline auto operator=(const lstring& source) -> type& { return vector::operator=(source), *this; }
+ inline auto operator=(lstring& source) -> type& { return vector::operator=(source), *this; }
+ inline auto operator=(lstring&& source) -> type& { return vector::operator=(move(source)), *this; }
+
+ inline auto isort() -> type&;
+
+ template inline auto append(const string&, P&&...) -> type&;
+ inline auto append() -> type&;
+
+ inline auto find(string_view source) const -> maybe;
+ inline auto ifind(string_view source) const -> maybe;
+ inline auto match(string_view pattern) const -> lstring;
+ inline auto merge(string_view separator) const -> string;
+ inline auto strip() -> type&;
+
+ //split.hpp
+ template inline auto _split(string_view, string_view, long) -> lstring&;
+};
+
+struct format : vector {
+ using type = format;
+
+ template format(P&&... p) { reserve(sizeof...(p)); append(forward(p)...); }
+ template inline auto append(const T&, P&&... p) -> type&;
+ inline auto append() -> type&;
+};
+
+}
+
#include
#include
#include
@@ -35,11 +328,9 @@
#include
#include
#include
-#include
#include
#include
#include
-#include
#include
#include
#include
diff --git a/nall/string/allocator/adaptive.hpp b/nall/string/allocator/adaptive.hpp
index 224cc154..f919c0bb 100644
--- a/nall/string/allocator/adaptive.hpp
+++ b/nall/string/allocator/adaptive.hpp
@@ -22,15 +22,17 @@ namespace nall {
string::string() : _data(nullptr), _capacity(SSO - 1), _size(0) {
}
-auto string::get() -> char* {
- if(_capacity < SSO) return _text;
+template
+auto string::get() -> T* {
+ if(_capacity < SSO) return (T*)_text;
if(*_refs > 1) _copy();
- return _data;
+ return (T*)_data;
}
-auto string::data() const -> const char* {
- if(_capacity < SSO) return _text;
- return _data;
+template
+auto string::data() const -> const T* {
+ if(_capacity < SSO) return (const T*)_text;
+ return (const T*)_data;
}
auto string::reset() -> type& {
diff --git a/nall/string/base.hpp b/nall/string/base.hpp
deleted file mode 100644
index d638f035..00000000
--- a/nall/string/base.hpp
+++ /dev/null
@@ -1,294 +0,0 @@
-#pragma once
-
-namespace nall {
-
-struct string_view;
-struct string;
-struct format;
-struct lstring;
-
-using rstring = const string_view&;
-using cstring = const string&;
-
-#define NALL_STRING_ALLOCATOR_ADAPTIVE
-//#define NALL_STRING_ALLOCATOR_COPY_ON_WRITE
-//#define NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION
-//#define NALL_STRING_ALLOCATOR_VECTOR
-
-//cast.hpp
-template struct stringify;
-
-//format.hpp
-template inline auto print(P&&...) -> void;
-inline auto integer(intmax value, long precision = 0, char padchar = '0') -> string;
-inline auto natural(uintmax value, long precision = 0, char padchar = '0') -> string;
-inline auto hex(uintmax value, long precision = 0, char padchar = '0') -> string;
-inline auto octal(uintmax value, long precision = 0, char padchar = '0') -> string;
-inline auto binary(uintmax value, long precision = 0, char padchar = '0') -> string;
-template inline auto pointer(const T* value, long precision = 0) -> string;
-inline auto pointer(uintptr value, long precision = 0) -> string;
-inline auto real(long double value) -> string;
-
-//hash.hpp
-inline auto crc16(rstring self) -> string;
-inline auto crc32(rstring self) -> string;
-inline auto crc64(rstring self) -> string;
-inline auto sha256(rstring self) -> string;
-
-//match.hpp
-inline auto tokenize(const char* s, const char* p) -> bool;
-inline auto tokenize(lstring& list, const char* s, const char* p) -> bool;
-
-//path.hpp
-inline auto pathname(rstring self) -> string;
-inline auto filename(rstring self) -> string;
-
-inline auto dirname(rstring self) -> string;
-inline auto basename(rstring self) -> string;
-inline auto prefixname(rstring self) -> string;
-inline auto suffixname(rstring self) -> string;
-
-//platform.hpp
-inline auto activepath() -> string;
-inline auto realpath(rstring name) -> string;
-inline auto programpath() -> string;
-inline auto rootpath() -> string;
-inline auto userpath() -> string;
-inline auto configpath() -> string;
-inline auto localpath() -> string;
-inline auto sharedpath() -> string;
-inline auto temppath() -> string;
-
-//utility.hpp
-inline auto slice(rstring self, int offset = 0, int length = -1) -> string;
-
-inline auto integer(char* result, intmax value) -> char*;
-inline auto natural(char* result, uintmax value) -> char*;
-inline auto real(char* str, long double value) -> uint;
-
-struct string {
- using type = string;
- struct exception_out_of_bounds{};
-
-protected:
- #if defined(NALL_STRING_ALLOCATOR_ADAPTIVE)
- enum : uint { SSO = 24 };
- union {
- struct { //copy-on-write
- char* _data;
- uint* _refs;
- };
- struct { //small-string-optimization
- char _text[SSO];
- };
- };
- inline auto _allocate() -> void;
- inline auto _copy() -> void;
- inline auto _resize() -> void;
- #endif
-
- #if defined(NALL_STRING_ALLOCATOR_COPY_ON_WRITE)
- char* _data;
- mutable uint* _refs;
- inline auto _allocate() -> char*;
- inline auto _copy() -> char*;
- #endif
-
- #if defined(NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION)
- enum : uint { SSO = 24 };
- union {
- char* _data;
- char _text[SSO];
- };
- #endif
-
- #if defined(NALL_STRING_ALLOCATOR_VECTOR)
- char* _data;
- #endif
-
- uint _capacity;
- uint _size;
-
-public:
- inline string();
- inline auto get() -> char*;
- inline auto data() const -> const char*;
- inline auto reset() -> type&;
- inline auto reserve(uint) -> type&;
- inline auto resize(uint) -> type&;
- inline auto operator=(const string&) -> type&;
- inline auto operator=(string&&) -> type&;
-
- template string(T&& s, P&&... p) : string() { append(forward(s), forward(p)...); }
- ~string() { reset(); }
-
- explicit operator bool() const { return _size; }
- operator const uint8_t*() const { return (const uint8_t*)data(); }
- operator const char*() const { return (const char*)data(); }
-
- auto binary() const -> const uint8_t* { return (const uint8_t*)data(); }
- auto size() const -> uint { return _size; }
- auto capacity() const -> uint { return _capacity; }
-
- auto operator==(const string& source) const -> bool { return size() == source.size() && memory::compare(data(), source.data(), size()) == 0; }
- auto operator!=(const string& source) const -> bool { return size() != source.size() || memory::compare(data(), source.data(), size()) != 0; }
-
- auto operator==(const char* source) const -> bool { return strcmp(data(), source) == 0; }
- auto operator!=(const char* source) const -> bool { return strcmp(data(), source) != 0; }
-
- auto operator==(rstring source) const -> bool { return compare(source) == 0; }
- auto operator!=(rstring source) const -> bool { return compare(source) != 0; }
- auto operator< (rstring source) const -> bool { return compare(source) < 0; }
- auto operator<=(rstring source) const -> bool { return compare(source) <= 0; }
- auto operator> (rstring source) const -> bool { return compare(source) > 0; }
- auto operator>=(rstring source) const -> bool { return compare(source) >= 0; }
-
- string(const string& source) : string() { operator=(source); }
- string(string&& source) : string() { operator=(move(source)); }
-
- auto begin() -> char* { return &get()[0]; }
- auto end() -> char* { return &get()[size()]; }
- auto begin() const -> const char* { return &data()[0]; }
- auto end() const -> const char* { return &data()[size()]; }
-
- //atoi.hpp
- inline auto integer() const -> intmax;
- inline auto natural() const -> uintmax;
- inline auto real() const -> double;
-
- //core.hpp
- inline auto operator[](int) const -> const char&;
- template inline auto assign(P&&...) -> type&;
- template inline auto append(const T&, P&&...) -> type&;
- template inline auto append(const nall::format&, P&&...) -> type&;
- inline auto append() -> type&;
- template inline auto _append(const stringify&) -> string&;
- inline auto empty() const -> bool;
- inline auto length() const -> uint;
-
- //datetime.hpp
- inline static auto date(time_t = 0) -> string;
- inline static auto time(time_t = 0) -> string;
- inline static auto datetime(time_t = 0) -> string;
-
- //find.hpp
- template inline auto _find(int, rstring) const -> maybe;
-
- inline auto find(rstring source) const -> maybe;
- inline auto ifind(rstring source) const -> maybe;
- inline auto qfind(rstring source) const -> maybe;
- inline auto iqfind(rstring source) const -> maybe;
-
- inline auto findFrom(int offset, rstring source) const -> maybe;
- inline auto ifindFrom(int offset, rstring source) const -> maybe;
-
- //format.hpp
- inline auto format(const nall::format& params) -> type&;
-
- //compare.hpp
- template inline static auto _compare(const char*, uint, const char*, uint) -> signed;
-
- inline static auto compare(rstring, rstring) -> signed;
- inline static auto icompare(rstring, rstring) -> signed;
-
- inline auto compare(rstring source) const -> signed;
- inline auto icompare(rstring source) const -> signed;
-
- inline auto equals(rstring source) const -> bool;
- inline auto iequals(rstring source) const -> bool;
-
- inline auto beginsWith(rstring source) const -> bool;
- inline auto ibeginsWith(rstring source) const -> bool;
-
- inline auto endsWith(rstring source) const -> bool;
- inline auto iendsWith(rstring source) const -> bool;
-
- //convert.hpp
- inline auto downcase() -> type&;
- inline auto upcase() -> type&;
-
- inline auto qdowncase() -> type&;
- inline auto qupcase() -> type&;
-
- inline auto transform(rstring from, rstring to) -> type&;
-
- //match.hpp
- inline auto match(rstring source) const -> bool;
- inline auto imatch(rstring source) const -> bool;
-
- //replace.hpp
- template inline auto _replace(rstring, rstring, long) -> type&;
- inline auto replace(rstring from, rstring to, long limit = LONG_MAX) -> type&;
- inline auto ireplace(rstring from, rstring to, long limit = LONG_MAX) -> type&;
- inline auto qreplace(rstring from, rstring to, long limit = LONG_MAX) -> type&;
- inline auto iqreplace(rstring from, rstring to, long limit = LONG_MAX) -> type&;
-
- //split.hpp
- inline auto split(rstring key, long limit = LONG_MAX) const -> lstring;
- inline auto isplit(rstring key, long limit = LONG_MAX) const -> lstring;
- inline auto qsplit(rstring key, long limit = LONG_MAX) const -> lstring;
- inline auto iqsplit(rstring key, long limit = LONG_MAX) const -> lstring;
-
- //trim.hpp
- inline auto trim(rstring lhs, rstring rhs, long limit = LONG_MAX) -> type&;
- inline auto ltrim(rstring lhs, long limit = LONG_MAX) -> type&;
- inline auto rtrim(rstring rhs, long limit = LONG_MAX) -> type&;
-
- inline auto itrim(rstring lhs, rstring rhs, long limit = LONG_MAX) -> type&;
- inline auto iltrim(rstring lhs, long limit = LONG_MAX) -> type&;
- inline auto irtrim(rstring rhs, long limit = LONG_MAX) -> type&;
-
- inline auto strip() -> type&;
- inline auto lstrip() -> type&;
- inline auto rstrip() -> type&;
-
- //utility.hpp
- inline static auto read(rstring filename) -> string;
- inline static auto repeat(rstring pattern, uint times) -> string;
- inline auto fill(char fill = ' ') -> type&;
- inline auto hash() const -> uint;
- inline auto remove(uint offset, uint length) -> type&;
- inline auto reverse() -> type&;
- inline auto size(int length, char fill = ' ') -> type&;
-};
-
-struct lstring : vector {
- using type = lstring;
-
- lstring(const lstring& source) { vector::operator=(source); }
- lstring(lstring& source) { vector::operator=(source); }
- lstring(lstring&& source) { vector::operator=(move(source)); }
- template lstring(P&&... p) { append(forward(p)...); }
-
- //list.hpp
- inline auto operator==(const lstring&) const -> bool;
- inline auto operator!=(const lstring&) const -> bool;
-
- inline auto operator=(const lstring& source) -> type& { return vector::operator=(source), *this; }
- inline auto operator=(lstring& source) -> type& { return vector::operator=(source), *this; }
- inline auto operator=(lstring&& source) -> type& { return vector::operator=(move(source)), *this; }
-
- inline auto isort() -> type&;
-
- template inline auto append(const string&, P&&...) -> type&;
- inline auto append() -> type&;
-
- inline auto find(rstring source) const -> maybe;
- inline auto ifind(rstring source) const -> maybe;
- inline auto match(rstring pattern) const -> lstring;
- inline auto merge(rstring separator) const -> string;
- inline auto strip() -> type&;
-
- //split.hpp
- template inline auto _split(rstring, rstring, long) -> lstring&;
-};
-
-struct format : vector {
- using type = format;
-
- template format(P&&... p) { reserve(sizeof...(p)); append(forward(p)...); }
- template inline auto append(const T&, P&&... p) -> type&;
- inline auto append() -> type&;
-};
-
-}
diff --git a/nall/string/cast.hpp b/nall/string/cast.hpp
index 2574eca4..2c68071e 100644
--- a/nall/string/cast.hpp
+++ b/nall/string/cast.hpp
@@ -10,7 +10,7 @@ namespace nall {
template<> struct stringify {
stringify(bool value) : _value(value) {}
auto data() const -> const char* { return _value ? "true" : "false"; }
- auto size() const -> unsigned { return _value ? 4 : 5; }
+ auto size() const -> uint { return _value ? 4 : 5; }
bool _value;
};
@@ -26,7 +26,7 @@ template<> struct stringify {
template<> struct stringify {
stringify(char source) { _data[0] = source; _data[1] = 0; }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return 1; }
+ auto size() const -> uint { return 1; }
char _data[2];
};
@@ -35,35 +35,35 @@ template<> struct stringify {
template<> struct stringify {
stringify(signed char source) { integer(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[2 + sizeof(signed char) * 3];
};
template<> struct stringify {
stringify(signed short source) { integer(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[2 + sizeof(signed short) * 3];
};
template<> struct stringify {
stringify(signed int source) { integer(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[2 + sizeof(signed int) * 3];
};
template<> struct stringify {
stringify(signed long source) { integer(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[2 + sizeof(signed long) * 3];
};
template<> struct stringify {
stringify(signed long long source) { integer(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[2 + sizeof(signed long long) * 3];
};
@@ -79,35 +79,35 @@ template struct stringify> {
template<> struct stringify {
stringify(unsigned char source) { natural(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[1 + sizeof(unsigned char) * 3];
};
template<> struct stringify {
stringify(unsigned short source) { natural(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[1 + sizeof(unsigned short) * 3];
};
template<> struct stringify {
stringify(unsigned int source) { natural(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[1 + sizeof(unsigned int) * 3];
};
template<> struct stringify {
stringify(unsigned long source) { natural(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[1 + sizeof(unsigned long) * 3];
};
template<> struct stringify {
stringify(unsigned long long source) { natural(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[1 + sizeof(unsigned long long) * 3];
};
@@ -123,21 +123,21 @@ template struct stringify> {
template<> struct stringify {
stringify(float source) { real(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[256];
};
template<> struct stringify {
stringify(double source) { real(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[256];
};
template<> struct stringify {
stringify(long double source) { real(_data, source); }
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
char _data[256];
};
@@ -156,7 +156,7 @@ template<> struct stringify> {
memory::copy(_text.data(), source.data(), source.size());
}
auto data() const -> const char* { return _text.data(); }
- auto size() const -> unsigned { return _text.size(); }
+ auto size() const -> uint { return _text.size(); }
vector _text;
};
@@ -166,7 +166,7 @@ template<> struct stringify&> {
memory::copy(_text.data(), source.data(), source.size());
}
auto data() const -> const char* { return _text.data(); }
- auto size() const -> unsigned { return _text.size(); }
+ auto size() const -> uint { return _text.size(); }
vector _text;
};
@@ -175,14 +175,14 @@ template<> struct stringify&> {
template<> struct stringify {
stringify(char* source) : _data(source ? source : "") {}
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
const char* _data;
};
template<> struct stringify {
stringify(const char* source) : _data(source ? source : "") {}
auto data() const -> const char* { return _data; }
- auto size() const -> unsigned { return strlen(_data); }
+ auto size() const -> uint { return strlen(_data); }
const char* _data;
};
@@ -191,28 +191,28 @@ template<> struct stringify {
template<> struct stringify {
stringify(const string& source) : _text(source) {}
auto data() const -> const char* { return _text.data(); }
- auto size() const -> unsigned { return _text.size(); }
+ auto size() const -> uint { return _text.size(); }
const string& _text;
};
template<> struct stringify {
stringify(const string& source) : _text(source) {}
auto data() const -> const char* { return _text.data(); }
- auto size() const -> unsigned { return _text.size(); }
+ auto size() const -> uint { return _text.size(); }
const string& _text;
};
template<> struct stringify {
stringify(const string_view& source) : _view(source) {}
auto data() const -> const char* { return _view.data(); }
- auto size() const -> unsigned { return _view.size(); }
+ auto size() const -> uint { return _view.size(); }
const string_view& _view;
};
template<> struct stringify {
stringify(const string_view& source) : _view(source) {}
auto data() const -> const char* { return _view.data(); }
- auto size() const -> unsigned { return _view.size(); }
+ auto size() const -> uint { return _view.size(); }
const string_view& _view;
};
diff --git a/nall/string/compare.hpp b/nall/string/compare.hpp
index 0fb933dc..08479ba2 100644
--- a/nall/string/compare.hpp
+++ b/nall/string/compare.hpp
@@ -3,54 +3,54 @@
namespace nall {
template
-auto string::_compare(const char* target, uint capacity, const char* source, uint size) -> signed {
+auto string::_compare(const char* target, uint capacity, const char* source, uint size) -> int {
if(Insensitive) return memory::icompare(target, capacity, source, size);
return memory::compare(target, capacity, source, size);
}
//size() + 1 includes null-terminator; required to properly compare strings of differing lengths
-auto string::compare(rstring x, rstring y) -> int {
+auto string::compare(string_view x, string_view y) -> int {
return memory::compare(x.data(), x.size() + 1, y.data(), y.size() + 1);
}
-auto string::icompare(rstring x, rstring y) -> int {
+auto string::icompare(string_view x, string_view y) -> int {
return memory::icompare(x.data(), x.size() + 1, y.data(), y.size() + 1);
}
-auto string::compare(rstring source) const -> int {
+auto string::compare(string_view source) const -> int {
return memory::compare(data(), size() + 1, source.data(), source.size() + 1);
}
-auto string::icompare(rstring source) const -> int {
+auto string::icompare(string_view source) const -> int {
return memory::icompare(data(), size() + 1, source.data(), source.size() + 1);
}
-auto string::equals(rstring source) const -> bool {
+auto string::equals(string_view source) const -> bool {
if(size() != source.size()) return false;
return memory::compare(data(), source.data(), source.size()) == 0;
}
-auto string::iequals(rstring source) const -> bool {
+auto string::iequals(string_view source) const -> bool {
if(size() != source.size()) return false;
return memory::icompare(data(), source.data(), source.size()) == 0;
}
-auto string::beginsWith(rstring source) const -> bool {
+auto string::beginsWith(string_view source) const -> bool {
if(source.size() > size()) return false;
return memory::compare(data(), source.data(), source.size()) == 0;
}
-auto string::ibeginsWith(rstring source) const -> bool {
+auto string::ibeginsWith(string_view source) const -> bool {
if(source.size() > size()) return false;
return memory::icompare(data(), source.data(), source.size()) == 0;
}
-auto string::endsWith(rstring source) const -> bool {
+auto string::endsWith(string_view source) const -> bool {
if(source.size() > size()) return false;
return memory::compare(data() + size() - source.size(), source.data(), source.size()) == 0;
}
-auto string::iendsWith(rstring source) const -> bool {
+auto string::iendsWith(string_view source) const -> bool {
if(source.size() > size()) return false;
return memory::icompare(data() + size() - source.size(), source.data(), source.size()) == 0;
}
diff --git a/nall/string/convert.hpp b/nall/string/convert.hpp
index 2b177f44..4c7d4abf 100644
--- a/nall/string/convert.hpp
+++ b/nall/string/convert.hpp
@@ -4,7 +4,7 @@ namespace nall {
auto string::downcase() -> string& {
char* p = get();
- for(unsigned n = 0; n < size(); n++) {
+ for(uint n = 0; n < size(); n++) {
if(p[n] >= 'A' && p[n] <= 'Z') p[n] += 0x20;
}
return *this;
@@ -12,7 +12,7 @@ auto string::downcase() -> string& {
auto string::qdowncase() -> string& {
char* p = get();
- for(unsigned n = 0, quoted = 0; n < size(); n++) {
+ for(uint n = 0, quoted = 0; n < size(); n++) {
if(p[n] == '\"') quoted ^= 1;
if(!quoted && p[n] >= 'A' && p[n] <= 'Z') p[n] += 0x20;
}
@@ -21,7 +21,7 @@ auto string::qdowncase() -> string& {
auto string::upcase() -> string& {
char* p = get();
- for(unsigned n = 0; n < size(); n++) {
+ for(uint n = 0; n < size(); n++) {
if(p[n] >= 'a' && p[n] <= 'z') p[n] -= 0x20;
}
return *this;
@@ -29,18 +29,18 @@ auto string::upcase() -> string& {
auto string::qupcase() -> string& {
char* p = get();
- for(unsigned n = 0, quoted = 0; n < size(); n++) {
+ for(uint n = 0, quoted = 0; n < size(); n++) {
if(p[n] == '\"') quoted ^= 1;
if(!quoted && p[n] >= 'a' && p[n] <= 'z') p[n] -= 0x20;
}
return *this;
}
-auto string::transform(rstring from, rstring to) -> string& {
+auto string::transform(string_view from, string_view to) -> string& {
if(from.size() != to.size() || from.size() == 0) return *this; //patterns must be the same length
char* p = get();
- for(unsigned n = 0; n < size(); n++) {
- for(unsigned s = 0; s < from.size(); s++) {
+ for(uint n = 0; n < size(); n++) {
+ for(uint s = 0; s < from.size(); s++) {
if(p[n] == from[s]) {
p[n] = to[s];
break;
diff --git a/nall/string/core.hpp b/nall/string/core.hpp
index da8c166e..7122c5f6 100644
--- a/nall/string/core.hpp
+++ b/nall/string/core.hpp
@@ -16,7 +16,7 @@
namespace nall {
auto string::operator[](int position) const -> const char& {
- if(position > size() + 1) throw exception_out_of_bounds{};
+//if(position > size() + 1) throw;
return data()[position];
}
@@ -45,10 +45,6 @@ template auto string::_append(const stringify& source) -> string&
return *this;
}
-auto string::empty() const -> bool {
- return size() == 0;
-}
-
auto string::length() const -> uint {
return strlen(data());
}
diff --git a/nall/string/eval/evaluator.hpp b/nall/string/eval/evaluator.hpp
index 60fc2d1b..184f8eb4 100644
--- a/nall/string/eval/evaluator.hpp
+++ b/nall/string/eval/evaluator.hpp
@@ -28,7 +28,7 @@ inline auto evaluateExpression(Node* node) -> string {
for(auto& link : node->link) {
result.append(evaluateExpression(link), ", ");
}
- return result.rtrim(", ", 1L).append(")");
+ return result.trimRight(", ", 1L).append(")");
}
}
#undef p
diff --git a/nall/string/eval/literal.hpp b/nall/string/eval/literal.hpp
index f56078ad..4efd94aa 100644
--- a/nall/string/eval/literal.hpp
+++ b/nall/string/eval/literal.hpp
@@ -16,7 +16,7 @@ inline auto literalNumber(const char*& s) -> string {
//binary
if(p[0] == '%' || (p[0] == '0' && p[1] == 'b')) {
- unsigned prefix = 1 + (p[0] == '0');
+ uint prefix = 1 + (p[0] == '0');
p += prefix;
while(p[0] == '\'' || p[0] == '0' || p[0] == '1') p++;
if(p - s <= prefix) throw "invalid binary literal";
@@ -27,7 +27,7 @@ inline auto literalNumber(const char*& s) -> string {
//octal
if(p[0] == '0' && p[1] == 'o') {
- unsigned prefix = 1 + (p[0] == '0');
+ uint prefix = 1 + (p[0] == '0');
p += prefix;
while(p[0] == '\'' || (p[0] >= '0' && p[0] <= '7')) p++;
if(p - s <= prefix) throw "invalid octal literal";
@@ -38,7 +38,7 @@ inline auto literalNumber(const char*& s) -> string {
//hex
if(p[0] == '$' || (p[0] == '0' && p[1] == 'x')) {
- unsigned prefix = 1 + (p[0] == '0');
+ uint prefix = 1 + (p[0] == '0');
p += prefix;
while(p[0] == '\'' || (p[0] >= '0' && p[0] <= '9') || (p[0] >= 'A' && p[0] <= 'F') || (p[0] >= 'a' && p[0] <= 'f')) p++;
if(p - s <= prefix) throw "invalid hex literal";
diff --git a/nall/string/find.hpp b/nall/string/find.hpp
index 872fece5..d8d9a48c 100644
--- a/nall/string/find.hpp
+++ b/nall/string/find.hpp
@@ -2,7 +2,7 @@
namespace nall {
-template auto string::_find(int offset, rstring source) const -> maybe {
+template auto string::_find(int offset, string_view source) const -> maybe {
if(source.size() == 0) return nothing;
auto p = data();
@@ -15,12 +15,12 @@ template auto string::_find(int offset, rstring s
return nothing;
}
-auto string::find(rstring source) const -> maybe { return _find<0, 0>(0, source); }
-auto string::ifind(rstring source) const -> maybe { return _find<1, 0>(0, source); }
-auto string::qfind(rstring source) const -> maybe { return _find<0, 1>(0, source); }
-auto string::iqfind(rstring source) const -> maybe { return _find<1, 1>(0, source); }
+auto string::find(string_view source) const -> maybe { return _find<0, 0>(0, source); }
+auto string::ifind(string_view source) const -> maybe { return _find<1, 0>(0, source); }
+auto string::qfind(string_view source) const -> maybe { return _find<0, 1>(0, source); }
+auto string::iqfind(string_view source) const -> maybe { return _find<1, 1>(0, source); }
-auto string::findFrom(int offset, rstring source) const -> maybe { return _find<0, 0>(offset, source); }
-auto string::ifindFrom(int offset, rstring source) const -> maybe { return _find<1, 0>(offset, source); }
+auto string::findFrom(int offset, string_view source) const -> maybe { return _find<0, 0>(offset, source); }
+auto string::ifindFrom(int offset, string_view source) const -> maybe { return _find<1, 0>(offset, source); }
}
diff --git a/nall/string/format.hpp b/nall/string/format.hpp
index 8f8c463e..71c8a1a4 100644
--- a/nall/string/format.hpp
+++ b/nall/string/format.hpp
@@ -10,11 +10,11 @@ auto string::format(const nall::format& params) -> type& {
auto data = (char*)memory::allocate(size);
memory::copy(data, this->data(), size);
- signed x = 0;
+ int x = 0;
while(x < size - 2) { //2 = minimum tag length
if(data[x] != '{') { x++; continue; }
- signed y = x + 1;
+ int y = x + 1;
while(y < size - 1) { //-1 avoids going out of bounds on test after this loop
if(data[y] != '}') { y++; continue; }
break;
@@ -70,7 +70,12 @@ auto format::append() -> format& {
template auto print(P&&... p) -> void {
string s{forward(p)...};
- fputs(s.data(), stdout);
+ fwrite(s.data(), 1, s.size(), stdout);
+}
+
+template auto print(FILE* fp, P&&... p) -> void {
+ string s{forward(p)...};
+ fwrite(s.data(), 1, s.size(), fp);
}
auto integer(intmax value, long precision, char padchar) -> string {
diff --git a/nall/string/hash.hpp b/nall/string/hash.hpp
deleted file mode 100644
index 04be44ff..00000000
--- a/nall/string/hash.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-
-namespace nall {
-
-namespace Hash {
- auto CRC16::digest() const -> string {
- return hex(value(), 4L);
- }
-
- auto CRC32::digest() const -> string {
- return hex(value(), 8L);
- }
-
- auto CRC64::digest() const -> string {
- return hex(value(), 16L);
- }
-
- auto SHA256::digest() const -> string {
- string result;
- for(auto n : value()) result.append(hex(n, 2L));
- return result;
- }
-}
-
-auto crc16(rstring self) -> string {
- return Hash::CRC16(self.data(), self.size()).digest();
-}
-
-auto crc32(rstring self) -> string {
- return Hash::CRC32(self.data(), self.size()).digest();
-}
-
-auto crc64(rstring self) -> string {
- return Hash::CRC64(self.data(), self.size()).digest();
-}
-
-auto sha256(rstring self) -> string {
- return Hash::SHA256(self.data(), self.size()).digest();
-}
-
-}
diff --git a/nall/string/list.hpp b/nall/string/list.hpp
index e448acb7..ae741722 100644
--- a/nall/string/list.hpp
+++ b/nall/string/list.hpp
@@ -32,21 +32,21 @@ auto lstring::append() -> lstring& {
return *this;
}
-auto lstring::find(rstring source) const -> maybe {
+auto lstring::find(string_view source) const -> maybe {
for(uint n = 0; n < size(); n++) {
if(operator[](n).equals(source)) return n;
}
return nothing;
}
-auto lstring::ifind(rstring source) const -> maybe {
+auto lstring::ifind(string_view source) const -> maybe {
for(uint n = 0; n < size(); n++) {
if(operator[](n).iequals(source)) return n;
}
return nothing;
}
-auto lstring::match(rstring pattern) const -> lstring {
+auto lstring::match(string_view pattern) const -> lstring {
lstring result;
for(uint n = 0; n < size(); n++) {
if(operator[](n).match(pattern)) result.append(operator[](n));
@@ -54,7 +54,7 @@ auto lstring::match(rstring pattern) const -> lstring {
return result;
}
-auto lstring::merge(rstring separator) const -> string {
+auto lstring::merge(string_view separator) const -> string {
string output;
for(uint n = 0; n < size(); n++) {
output.append(operator[](n));
diff --git a/nall/string/markup/bml.hpp b/nall/string/markup/bml.hpp
index d170d194..550f3e09 100644
--- a/nall/string/markup/bml.hpp
+++ b/nall/string/markup/bml.hpp
@@ -74,7 +74,7 @@ protected:
if(length == 0) throw "Invalid attribute name";
node->_name = slice(p, 0, length);
node->parseData(p += length);
- node->_value.rtrim("\n", 1L);
+ node->_value.trimRight("\n", 1L);
_children.append(node);
}
}
@@ -101,7 +101,7 @@ protected:
_children.append(node);
}
- _value.rtrim("\n", 1L);
+ _value.trimRight("\n", 1L);
}
//read top-level nodes
@@ -127,7 +127,7 @@ protected:
memory::move(output, origin, p - origin);
output += p - origin;
}
- document.resize(document.size() - (p - output)).rtrim("\n");
+ document.resize(document.size() - (p - output)).trimRight("\n");
if(document.size() == 0) return; //empty document
auto text = document.split("\n");
diff --git a/nall/string/markup/find.hpp b/nall/string/markup/find.hpp
index 91dedc17..f4016bab 100644
--- a/nall/string/markup/find.hpp
+++ b/nall/string/markup/find.hpp
@@ -31,7 +31,7 @@ auto ManagedNode::_evaluate(string query) const -> bool {
}
string data = string{_value}.strip();
- if(side(0).empty() == false) {
+ if(side(0)) {
auto result = _find(side(0));
if(result.size() == 0) return false;
data = result[0].value();
@@ -60,19 +60,19 @@ auto ManagedNode::_find(const string& query) const -> vector {
uint lo = 0u, hi = ~0u;
if(name.match("*[*]")) {
- auto p = name.rtrim("]", 1L).split("[", 1L);
+ auto p = name.trimRight("]", 1L).split("[", 1L);
name = p(0);
if(p(1).find("-")) {
p = p(1).split("-", 1L);
- lo = p(0).empty() ? 0u : p(0).natural();
- hi = p(1).empty() ? ~0u : p(1).natural();
+ lo = !p(0) ? 0u : p(0).natural();
+ hi = !p(1) ? ~0u : p(1).natural();
} else {
lo = hi = p(1).natural();
}
}
if(name.match("*(*)")) {
- auto p = name.rtrim(")", 1L).split("(", 1L);
+ auto p = name.trimRight(")", 1L).split("(", 1L);
name = p(0);
rule = p(1);
}
diff --git a/nall/string/markup/xml.hpp b/nall/string/markup/xml.hpp
index f53090e0..b0d946af 100644
--- a/nall/string/markup/xml.hpp
+++ b/nall/string/markup/xml.hpp
@@ -125,7 +125,7 @@ protected:
while(isName(*p)) p++;
const char* nameEnd = p;
copy(_name, nameStart, nameEnd - nameStart);
- if(_name.empty()) throw "missing element name";
+ if(!_name) throw "missing element name";
//parse attributes
while(*p) {
@@ -141,7 +141,7 @@ protected:
while(isName(*p)) p++;
const char* nameEnd = p;
copy(attribute->_name, nameStart, nameEnd - nameStart);
- if(attribute->_name.empty()) throw "missing attribute name";
+ if(!attribute->_name) throw "missing attribute name";
//parse attribute data
if(*p++ != '=') throw "missing attribute value";
diff --git a/nall/string/match.hpp b/nall/string/match.hpp
index 80ff7c1c..3d1bebb1 100644
--- a/nall/string/match.hpp
+++ b/nall/string/match.hpp
@@ -4,7 +4,7 @@ namespace nall {
//todo: these functions are not binary-safe
-auto string::match(rstring source) const -> bool {
+auto string::match(string_view source) const -> bool {
const char* s = data();
const char* p = source.data();
@@ -28,7 +28,7 @@ auto string::match(rstring source) const -> bool {
return !*p;
}
-auto string::imatch(rstring source) const -> bool {
+auto string::imatch(string_view source) const -> bool {
static auto chrlower = [](char c) -> char {
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
};
diff --git a/nall/string/path.hpp b/nall/string/path.hpp
index b5903d56..eac881bf 100644
--- a/nall/string/path.hpp
+++ b/nall/string/path.hpp
@@ -4,7 +4,7 @@ namespace nall {
// (/parent/child.type/)
// (/parent/child.type/)name.type
-auto pathname(rstring self) -> string {
+auto pathname(string_view self) -> string {
const char* p = self.data() + self.size() - 1;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, 0, offset + 1);
@@ -14,7 +14,7 @@ auto pathname(rstring self) -> string {
// /parent/child.type/()
// /parent/child.type/(name.type)
-auto filename(rstring self) -> string {
+auto filename(string_view self) -> string {
const char* p = self.data() + self.size() - 1;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, offset + 1);
@@ -24,18 +24,18 @@ auto filename(rstring self) -> string {
// (/parent/)child.type/
// (/parent/child.type/)name.type
-auto dirname(rstring self) -> string {
+auto dirname(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, 0, offset + 1);
}
- return rootpath(); //technically, directory is unknown; must return something
+ return ""; //no path found
}
// /parent/(child.type/)
// /parent/child.type/(name.type)
-auto basename(rstring self) -> string {
+auto basename(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
@@ -46,25 +46,25 @@ auto basename(rstring self) -> string {
// /parent/(child).type/
// /parent/child.type/(name).type
-auto prefixname(rstring self) -> string {
+auto prefixname(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
- if(*p == '/') return slice(self, offset + 1, suffix >= 0 ? suffix - offset - 1 : 0).rtrim("/");
+ if(*p == '/') return slice(self, offset + 1, suffix >= 0 ? suffix - offset - 1 : 0).trimRight("/");
if(*p == '.' && suffix == -1) { suffix = offset; continue; }
- if(offset == 0) return slice(self, offset, suffix).rtrim("/");
+ if(offset == 0) return slice(self, offset, suffix).trimRight("/");
}
return ""; //no prefix found
}
// /parent/child(.type)/
// /parent/child.type/name(.type)
-auto suffixname(rstring self) -> string {
+auto suffixname(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') break;
- if(*p == '.') return slice(self, offset).rtrim("/");
+ if(*p == '.') return slice(self, offset).trimRight("/");
}
return ""; //no suffix found
}
diff --git a/nall/string/replace.hpp b/nall/string/replace.hpp
index 0744caf3..d8143a15 100644
--- a/nall/string/replace.hpp
+++ b/nall/string/replace.hpp
@@ -3,17 +3,17 @@
namespace nall {
template
-auto string::_replace(rstring from, rstring to, long limit) -> string& {
+auto string::_replace(string_view from, string_view to, long limit) -> string& {
if(limit <= 0 || from.size() == 0) return *this;
- signed size = this->size();
- signed matches = 0;
- signed quoted = 0;
+ int size = this->size();
+ int matches = 0;
+ int quoted = 0;
//count matches first, so that we only need to reallocate memory once
//(recording matches would also require memory allocation, so this is not done)
{ const char* p = data();
- for(signed n = 0; n <= size - (signed)from.size();) {
+ for(int n = 0; n <= size - (int)from.size();) {
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } }
if(_compare