mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-30 15:00:02 +02:00
Update to v106r52 release.
byuu says: I stand corrected, I managed to create and even larger diff than ever. This one weighs in at 309KiB `>__>` I'll have to create a changelog later, I'm too tired right now to go through all of that.
This commit is contained in:
@@ -220,18 +220,18 @@ template<> struct stringify<const string&> {
|
||||
const string& _text;
|
||||
};
|
||||
|
||||
template<> struct stringify<string_view> {
|
||||
stringify(const string_view& source) : _view(source) {}
|
||||
template<> struct stringify<view<string>> {
|
||||
stringify(const view<string>& source) : _view(source) {}
|
||||
auto data() const -> const char* { return _view.data(); }
|
||||
auto size() const -> uint { return _view.size(); }
|
||||
const string_view& _view;
|
||||
const view<string>& _view;
|
||||
};
|
||||
|
||||
template<> struct stringify<const string_view&> {
|
||||
stringify(const string_view& source) : _view(source) {}
|
||||
template<> struct stringify<const view<string>&> {
|
||||
stringify(const view<string>& source) : _view(source) {}
|
||||
auto data() const -> const char* { return _view.data(); }
|
||||
auto size() const -> uint { return _view.size(); }
|
||||
const string_view& _view;
|
||||
const view<string>& _view;
|
||||
};
|
||||
|
||||
//pointers
|
||||
|
@@ -9,48 +9,48 @@ auto string::_compare(const char* target, uint capacity, const char* source, uin
|
||||
}
|
||||
|
||||
//size() + 1 includes null-terminator; required to properly compare strings of differing lengths
|
||||
auto string::compare(string_view x, string_view y) -> int {
|
||||
auto string::compare(view<string> x, view<string> y) -> int {
|
||||
return memory::compare(x.data(), x.size() + 1, y.data(), y.size() + 1);
|
||||
}
|
||||
|
||||
auto string::icompare(string_view x, string_view y) -> int {
|
||||
auto string::icompare(view<string> x, view<string> y) -> int {
|
||||
return memory::icompare(x.data(), x.size() + 1, y.data(), y.size() + 1);
|
||||
}
|
||||
|
||||
auto string::compare(string_view source) const -> int {
|
||||
auto string::compare(view<string> source) const -> int {
|
||||
return memory::compare(data(), size() + 1, source.data(), source.size() + 1);
|
||||
}
|
||||
|
||||
auto string::icompare(string_view source) const -> int {
|
||||
auto string::icompare(view<string> source) const -> int {
|
||||
return memory::icompare(data(), size() + 1, source.data(), source.size() + 1);
|
||||
}
|
||||
|
||||
auto string::equals(string_view source) const -> bool {
|
||||
auto string::equals(view<string> source) const -> bool {
|
||||
if(size() != source.size()) return false;
|
||||
return memory::compare(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
auto string::iequals(string_view source) const -> bool {
|
||||
auto string::iequals(view<string> source) const -> bool {
|
||||
if(size() != source.size()) return false;
|
||||
return memory::icompare(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
auto string::beginsWith(string_view source) const -> bool {
|
||||
auto string::beginsWith(view<string> source) const -> bool {
|
||||
if(source.size() > size()) return false;
|
||||
return memory::compare(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
auto string::ibeginsWith(string_view source) const -> bool {
|
||||
auto string::ibeginsWith(view<string> source) const -> bool {
|
||||
if(source.size() > size()) return false;
|
||||
return memory::icompare(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
auto string::endsWith(string_view source) const -> bool {
|
||||
auto string::endsWith(view<string> source) const -> bool {
|
||||
if(source.size() > size()) return false;
|
||||
return memory::compare(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
auto string::iendsWith(string_view source) const -> bool {
|
||||
auto string::iendsWith(view<string> source) const -> bool {
|
||||
if(source.size() > size()) return false;
|
||||
return memory::icompare(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ auto string::qupcase() -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::transform(string_view from, string_view to) -> string& {
|
||||
auto string::transform(view<string> from, view<string> to) -> string& {
|
||||
if(from.size() != to.size() || from.size() == 0) return *this; //patterns must be the same length
|
||||
char* p = get();
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<bool Insensitive, bool Quoted> auto string::_find(int offset, string_view source) const -> maybe<uint> {
|
||||
template<bool Insensitive, bool Quoted> auto string::_find(int offset, view<string> source) const -> maybe<uint> {
|
||||
if(source.size() == 0) return nothing;
|
||||
|
||||
auto p = data();
|
||||
@@ -15,12 +15,12 @@ template<bool Insensitive, bool Quoted> auto string::_find(int offset, string_vi
|
||||
return nothing;
|
||||
}
|
||||
|
||||
auto string::find(string_view source) const -> maybe<uint> { return _find<0, 0>(0, source); }
|
||||
auto string::ifind(string_view source) const -> maybe<uint> { return _find<1, 0>(0, source); }
|
||||
auto string::qfind(string_view source) const -> maybe<uint> { return _find<0, 1>(0, source); }
|
||||
auto string::iqfind(string_view source) const -> maybe<uint> { return _find<1, 1>(0, source); }
|
||||
auto string::find(view<string> source) const -> maybe<uint> { return _find<0, 0>(0, source); }
|
||||
auto string::ifind(view<string> source) const -> maybe<uint> { return _find<1, 0>(0, source); }
|
||||
auto string::qfind(view<string> source) const -> maybe<uint> { return _find<0, 1>(0, source); }
|
||||
auto string::iqfind(view<string> source) const -> maybe<uint> { return _find<1, 1>(0, source); }
|
||||
|
||||
auto string::findFrom(int offset, string_view source) const -> maybe<uint> { return _find<0, 0>(offset, source); }
|
||||
auto string::ifindFrom(int offset, string_view source) const -> maybe<uint> { return _find<1, 0>(offset, source); }
|
||||
auto string::findFrom(int offset, view<string> source) const -> maybe<uint> { return _find<0, 0>(offset, source); }
|
||||
auto string::ifindFrom(int offset, view<string> source) const -> maybe<uint> { return _find<1, 0>(offset, source); }
|
||||
|
||||
}
|
||||
|
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
auto string_vector::operator==(const string_vector& source) const -> bool {
|
||||
if(this == &source) return true;
|
||||
if(size() != source.size()) return false;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n) != source[n]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
auto string_vector::operator!=(const string_vector& source) const -> bool {
|
||||
return !operator==(source);
|
||||
}
|
||||
|
||||
auto string_vector::isort() -> type& {
|
||||
sort([](const string& x, const string& y) {
|
||||
return memory::icompare(x.data(), x.size(), y.data(), y.size()) < 0;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... P> auto string_vector::append(const string& data, P&&... p) -> type& {
|
||||
vector::append(data);
|
||||
append(forward<P>(p)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string_vector::append() -> type& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string_vector::find(string_view source) const -> maybe<uint> {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).equals(source)) return n;
|
||||
}
|
||||
return nothing;
|
||||
}
|
||||
|
||||
auto string_vector::ifind(string_view source) const -> maybe<uint> {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).iequals(source)) return n;
|
||||
}
|
||||
return nothing;
|
||||
}
|
||||
|
||||
auto string_vector::match(string_view pattern) const -> type {
|
||||
string_vector result;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).match(pattern)) result.append(operator[](n));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
auto string_vector::merge(string_view separator) const -> string {
|
||||
string output;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
output.append(operator[](n));
|
||||
if(n < size() - 1) output.append(separator.data());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
auto string_vector::strip() -> type& {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
operator[](n).strip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
@@ -80,7 +80,7 @@ protected:
|
||||
}
|
||||
|
||||
//read a node and all of its child nodes
|
||||
auto parseNode(const string_vector& text, uint& y) -> void {
|
||||
auto parseNode(const vector<string>& text, uint& y) -> void {
|
||||
const char* p = text[y++];
|
||||
_metadata = parseDepth(p);
|
||||
parseName(p);
|
||||
@@ -166,7 +166,7 @@ inline auto serialize(const Markup::Node& node, uint depth = 0) -> string {
|
||||
padding.resize(depth * 2);
|
||||
for(auto& byte : padding) byte = ' ';
|
||||
|
||||
string_vector lines;
|
||||
vector<string> lines;
|
||||
if(auto value = node.value()) lines = value.split("\n");
|
||||
|
||||
string result;
|
||||
|
@@ -20,7 +20,7 @@ auto ManagedNode::_evaluate(string query) const -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
string_vector side;
|
||||
vector<string> side;
|
||||
switch(comparator) {
|
||||
case Comparator::EQ: side = rule.split ("=", 1L); break;
|
||||
case Comparator::NE: side = rule.split("!=", 1L); break;
|
||||
|
@@ -4,7 +4,7 @@ namespace nall {
|
||||
|
||||
//todo: these functions are not binary-safe
|
||||
|
||||
auto string::match(string_view source) const -> bool {
|
||||
auto string::match(view<string> source) const -> bool {
|
||||
const char* s = data();
|
||||
const char* p = source.data();
|
||||
|
||||
@@ -28,7 +28,7 @@ auto string::match(string_view source) const -> bool {
|
||||
return !*p;
|
||||
}
|
||||
|
||||
auto string::imatch(string_view source) const -> bool {
|
||||
auto string::imatch(view<string> source) const -> bool {
|
||||
static auto chrlower = [](char c) -> char {
|
||||
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
|
||||
};
|
||||
@@ -68,7 +68,7 @@ auto tokenize(const char* s, const char* p) -> bool {
|
||||
return !*p;
|
||||
}
|
||||
|
||||
auto tokenize(string_vector& list, const char* s, const char* p) -> bool {
|
||||
auto tokenize(vector<string>& list, const char* s, const char* p) -> bool {
|
||||
while(*s) {
|
||||
if(*p == '*') {
|
||||
const char* b = s;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace nall {
|
||||
|
||||
template<bool Insensitive, bool Quoted>
|
||||
auto string::_replace(string_view from, string_view to, long limit) -> string& {
|
||||
auto string::_replace(view<string> from, view<string> to, long limit) -> string& {
|
||||
if(limit <= 0 || from.size() == 0) return *this;
|
||||
|
||||
int size = this->size();
|
||||
@@ -86,9 +86,9 @@ auto string::_replace(string_view from, string_view to, long limit) -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::replace(string_view from, string_view to, long limit) -> string& { return _replace<0, 0>(from, to, limit); }
|
||||
auto string::ireplace(string_view from, string_view to, long limit) -> string& { return _replace<1, 0>(from, to, limit); }
|
||||
auto string::qreplace(string_view from, string_view to, long limit) -> string& { return _replace<0, 1>(from, to, limit); }
|
||||
auto string::iqreplace(string_view from, string_view to, long limit) -> string& { return _replace<1, 1>(from, to, limit); }
|
||||
auto string::replace(view<string> from, view<string> to, long limit) -> string& { return _replace<0, 0>(from, to, limit); }
|
||||
auto string::ireplace(view<string> from, view<string> to, long limit) -> string& { return _replace<1, 0>(from, to, limit); }
|
||||
auto string::qreplace(view<string> from, view<string> to, long limit) -> string& { return _replace<0, 1>(from, to, limit); }
|
||||
auto string::iqreplace(view<string> from, view<string> to, long limit) -> string& { return _replace<1, 1>(from, to, limit); }
|
||||
|
||||
};
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace nall {
|
||||
|
||||
template<bool Insensitive, bool Quoted>
|
||||
auto string_vector::_split(string_view source, string_view find, long limit) -> string_vector& {
|
||||
auto vector<string>::_split(view<string> source, view<string> find, long limit) -> type& {
|
||||
reset();
|
||||
if(limit <= 0 || find.size() == 0) return *this;
|
||||
|
||||
@@ -33,9 +33,9 @@ auto string_vector::_split(string_view source, string_view find, long limit) ->
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::split(string_view on, long limit) const -> string_vector { return string_vector()._split<0, 0>(*this, on, limit); }
|
||||
auto string::isplit(string_view on, long limit) const -> string_vector { return string_vector()._split<1, 0>(*this, on, limit); }
|
||||
auto string::qsplit(string_view on, long limit) const -> string_vector { return string_vector()._split<0, 1>(*this, on, limit); }
|
||||
auto string::iqsplit(string_view on, long limit) const -> string_vector { return string_vector()._split<1, 1>(*this, on, limit); }
|
||||
auto string::split(view<string> on, long limit) const -> vector<string> { return vector<string>()._split<0, 0>(*this, on, limit); }
|
||||
auto string::isplit(view<string> on, long limit) const -> vector<string> { return vector<string>()._split<1, 0>(*this, on, limit); }
|
||||
auto string::qsplit(view<string> on, long limit) const -> vector<string> { return vector<string>()._split<0, 1>(*this, on, limit); }
|
||||
auto string::iqsplit(view<string> on, long limit) const -> vector<string> { return vector<string>()._split<1, 1>(*this, on, limit); }
|
||||
|
||||
}
|
||||
|
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
auto string::trim(string_view lhs, string_view rhs, long limit) -> string& {
|
||||
auto string::trim(view<string> lhs, view<string> rhs, long limit) -> string& {
|
||||
trimRight(rhs, limit);
|
||||
trimLeft(lhs, limit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::trimLeft(string_view lhs, long limit) -> string& {
|
||||
auto string::trimLeft(view<string> lhs, long limit) -> string& {
|
||||
if(lhs.size() == 0) return *this;
|
||||
long matches = 0;
|
||||
while(matches < limit) {
|
||||
@@ -22,7 +22,7 @@ auto string::trimLeft(string_view lhs, long limit) -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::trimRight(string_view rhs, long limit) -> string& {
|
||||
auto string::trimRight(view<string> rhs, long limit) -> string& {
|
||||
if(rhs.size() == 0) return *this;
|
||||
long matches = 0;
|
||||
while(matches < limit) {
|
||||
@@ -36,13 +36,13 @@ auto string::trimRight(string_view rhs, long limit) -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::itrim(string_view lhs, string_view rhs, long limit) -> string& {
|
||||
auto string::itrim(view<string> lhs, view<string> rhs, long limit) -> string& {
|
||||
itrimRight(rhs, limit);
|
||||
itrimLeft(lhs, limit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::itrimLeft(string_view lhs, long limit) -> string& {
|
||||
auto string::itrimLeft(view<string> lhs, long limit) -> string& {
|
||||
if(lhs.size() == 0) return *this;
|
||||
long matches = 0;
|
||||
while(matches < limit) {
|
||||
@@ -56,7 +56,7 @@ auto string::itrimLeft(string_view lhs, long limit) -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto string::itrimRight(string_view rhs, long limit) -> string& {
|
||||
auto string::itrimRight(view<string> rhs, long limit) -> string& {
|
||||
if(rhs.size() == 0) return *this;
|
||||
long matches = 0;
|
||||
while(matches < limit) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
auto string::read(string_view filename) -> string {
|
||||
auto string::read(view<string> filename) -> string {
|
||||
#if !defined(_WIN32)
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
#else
|
||||
@@ -22,7 +22,7 @@ auto string::read(string_view filename) -> string {
|
||||
return fclose(fp), result;
|
||||
}
|
||||
|
||||
auto string::repeat(string_view pattern, uint times) -> string {
|
||||
auto string::repeat(view<string> pattern, uint times) -> string {
|
||||
string result;
|
||||
while(times--) result.append(pattern.data());
|
||||
return result;
|
||||
@@ -82,7 +82,7 @@ auto string::size(int length, char fill) -> string& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto slice(string_view self, int offset, int length) -> string {
|
||||
auto slice(view<string> self, int offset, int length) -> string {
|
||||
string result;
|
||||
if(offset < 0) offset = self.size() - abs(offset);
|
||||
if(offset >= 0 && offset < self.size()) {
|
||||
|
60
nall/string/vector.hpp
Normal file
60
nall/string/vector.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename... P> auto vector<string>::append(const string& data, P&&... p) -> type& {
|
||||
vector_base::append(data);
|
||||
append(forward<P>(p)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto vector<string>::append() -> type& {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto vector<string>::isort() -> type& {
|
||||
sort([](const string& x, const string& y) {
|
||||
return memory::icompare(x.data(), x.size(), y.data(), y.size()) < 0;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto vector<string>::find(view<string> source) const -> maybe<uint> {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).equals(source)) return n;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto vector<string>::ifind(view<string> source) const -> maybe<uint> {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).iequals(source)) return n;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto vector<string>::match(view<string> pattern) const -> vector<string> {
|
||||
vector<string> result;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
if(operator[](n).match(pattern)) result.append(operator[](n));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
auto vector<string>::merge(view<string> separator) const -> string {
|
||||
string output;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
output.append(operator[](n));
|
||||
if(n < size() - 1) output.append(separator.data());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
auto vector<string>::strip() -> type& {
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
operator[](n).strip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
@@ -2,20 +2,20 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
string_view::string_view() {
|
||||
view<string>::view() {
|
||||
_string = nullptr;
|
||||
_data = "";
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
string_view::string_view(const string_view& source) {
|
||||
view<string>::view(const view& source) {
|
||||
if(this == &source) return;
|
||||
_string = nullptr;
|
||||
_data = source._data;
|
||||
_size = source._size;
|
||||
}
|
||||
|
||||
string_view::string_view(string_view&& source) {
|
||||
view<string>::view(view&& source) {
|
||||
if(this == &source) return;
|
||||
_string = source._string;
|
||||
_data = source._data;
|
||||
@@ -23,36 +23,36 @@ string_view::string_view(string_view&& source) {
|
||||
source._string = nullptr;
|
||||
}
|
||||
|
||||
string_view::string_view(const char* data) {
|
||||
view<string>::view(const char* data) {
|
||||
_string = nullptr;
|
||||
_data = data;
|
||||
_size = -1; //defer length calculation, as it is often unnecessary
|
||||
}
|
||||
|
||||
string_view::string_view(const char* data, uint size) {
|
||||
view<string>::view(const char* data, uint size) {
|
||||
_string = nullptr;
|
||||
_data = data;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
string_view::string_view(const string& source) {
|
||||
view<string>::view(const string& source) {
|
||||
_string = nullptr;
|
||||
_data = source.data();
|
||||
_size = source.size();
|
||||
}
|
||||
|
||||
template<typename... P>
|
||||
string_view::string_view(P&&... p) {
|
||||
view<string>::view(P&&... p) {
|
||||
_string = new string{forward<P>(p)...};
|
||||
_data = _string->data();
|
||||
_size = _string->size();
|
||||
}
|
||||
|
||||
string_view::~string_view() {
|
||||
view<string>::~view() {
|
||||
if(_string) delete _string;
|
||||
}
|
||||
|
||||
auto string_view::operator=(const string_view& source) -> string_view& {
|
||||
auto view<string>::operator=(const view& source) -> view& {
|
||||
if(this == &source) return *this;
|
||||
_string = nullptr;
|
||||
_data = source._data;
|
||||
@@ -60,7 +60,7 @@ auto string_view::operator=(const string_view& source) -> string_view& {
|
||||
return *this;
|
||||
};
|
||||
|
||||
auto string_view::operator=(string_view&& source) -> string_view& {
|
||||
auto view<string>::operator=(view&& source) -> view& {
|
||||
if(this == &source) return *this;
|
||||
_string = source._string;
|
||||
_data = source._data;
|
||||
@@ -69,15 +69,15 @@ auto string_view::operator=(string_view&& source) -> string_view& {
|
||||
return *this;
|
||||
};
|
||||
|
||||
string_view::operator const char*() const {
|
||||
view<string>::operator const char*() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
auto string_view::data() const -> const char* {
|
||||
auto view<string>::data() const -> const char* {
|
||||
return _data;
|
||||
}
|
||||
|
||||
auto string_view::size() const -> uint {
|
||||
auto view<string>::size() const -> uint {
|
||||
if(_size < 0) _size = strlen(_data);
|
||||
return _size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user