#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace nall { struct string; struct string_format; template<> struct view { using type = view; //view.hpp inline view(); inline view(const view& source); inline view(view&& source); inline view(const char* data); inline view(const char* data, uint size); inline view(const string& source); template inline view(P&&... p); inline ~view(); inline auto operator=(const view& source) -> view&; inline auto operator=(view&& source) -> view&; inline operator const char*() const; inline auto data() const -> const char*; inline auto size() const -> uint; inline auto begin() const { return &_data[0]; } inline auto end() const { return &_data[size()]; } 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; template inline auto pad(const T& value, long precision = 0, char padchar = ' ') -> 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; //match.hpp inline auto tokenize(const char* s, const char* p) -> bool; inline auto tokenize(vector& list, const char* s, const char* p) -> bool; //utility.hpp inline auto slice(view self, int offset = 0, int length = -1) -> string; template inline auto fromInteger(char* result, T value) -> char*; template inline auto fromNatural(char* result, T value) -> char*; template inline auto fromReal(char* str, T 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==(view source) const -> bool { return compare(source) == 0; } auto operator!=(view source) const -> bool { return compare(source) != 0; } auto operator< (view source) const -> bool { return compare(source) < 0; } auto operator<=(view source) const -> bool { return compare(source) <= 0; } auto operator> (view source) const -> bool { return compare(source) > 0; } auto operator>=(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 hex() const -> uintmax; inline auto real() const -> double; //core.hpp inline auto operator[](uint) const -> const char&; inline auto operator()(uint, char = 0) const -> char; template inline auto assign(P&&...) -> type&; template inline auto prepend(const T&, P&&...) -> type&; template inline auto prepend(const nall::string_format&, P&&...) -> type&; inline auto prepend() -> type&; template inline auto _prepend(const stringify&) -> string&; template inline auto append(const T&, P&&...) -> type&; template inline auto append(const nall::string_format&, P&&...) -> type&; inline auto append() -> type&; template inline auto _append(const stringify&) -> string&; inline auto length() const -> uint; //find.hpp inline auto contains(view characters) const -> maybe; template inline auto _find(int, view) const -> maybe; inline auto find(view source) const -> maybe; inline auto ifind(view source) const -> maybe; inline auto qfind(view source) const -> maybe; inline auto iqfind(view source) const -> maybe; inline auto findFrom(int offset, view source) const -> maybe; inline auto ifindFrom(int offset, view source) const -> maybe; //format.hpp inline auto format(const nall::string_format& params) -> type&; //compare.hpp template inline static auto _compare(const char*, uint, const char*, uint) -> int; inline static auto compare(view, view) -> int; inline static auto icompare(view, view) -> int; inline auto compare(view source) const -> int; inline auto icompare(view source) const -> int; inline auto equals(view source) const -> bool; inline auto iequals(view source) const -> bool; inline auto beginsWith(view source) const -> bool; inline auto ibeginsWith(view source) const -> bool; inline auto endsWith(view source) const -> bool; inline auto iendsWith(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(view from, viewto) -> type&; //match.hpp inline auto match(view source) const -> bool; inline auto imatch(view source) const -> bool; //replace.hpp template inline auto _replace(view, view, long) -> type&; inline auto replace(view from, view to, long limit = LONG_MAX) -> type&; inline auto ireplace(view from, view to, long limit = LONG_MAX) -> type&; inline auto qreplace(view from, view to, long limit = LONG_MAX) -> type&; inline auto iqreplace(view from, view to, long limit = LONG_MAX) -> type&; //split.hpp inline auto split(view key, long limit = LONG_MAX) const -> vector; inline auto isplit(view key, long limit = LONG_MAX) const -> vector; inline auto qsplit(view key, long limit = LONG_MAX) const -> vector; inline auto iqsplit(view key, long limit = LONG_MAX) const -> vector; //trim.hpp inline auto trim(view lhs, view rhs, long limit = LONG_MAX) -> type&; inline auto trimLeft(view lhs, long limit = LONG_MAX) -> type&; inline auto trimRight(view rhs, long limit = LONG_MAX) -> type&; inline auto itrim(view lhs, view rhs, long limit = LONG_MAX) -> type&; inline auto itrimLeft(view lhs, long limit = LONG_MAX) -> type&; inline auto itrimRight(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(view filename) -> string; inline static auto repeat(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&; }; template<> struct vector : vector_base { using type = vector; using vector_base::vector_base; vector(const vector& source) { vector_base::operator=(source); } vector(vector& source) { vector_base::operator=(source); } vector(vector&& source) { vector_base::operator=(move(source)); } template vector(P&&... p) { append(forward

(p)...); } inline auto operator=(const vector& source) -> type& { return vector_base::operator=(source), *this; } inline auto operator=(vector& source) -> type& { return vector_base::operator=(source), *this; } inline auto operator=(vector&& source) -> type& { return vector_base::operator=(move(source)), *this; } //list.hpp template inline auto append(const string&, P&&...) -> type&; inline auto append() -> type&; inline auto isort() -> type&; inline auto find(view source) const -> maybe; inline auto ifind(view source) const -> maybe; inline auto match(view pattern) const -> vector; inline auto merge(view separator) const -> string; inline auto strip() -> type&; //split.hpp template inline auto _split(view, view, long) -> type&; }; struct string_format : vector { using type = string_format; template string_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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include