Update to v098r10 release.

byuu says:

Changelog:
- synchronized tomoko, loki, icarus with extensive changes to nall
  (118KiB diff)
This commit is contained in:
Tim Allen
2016-05-16 19:51:12 +10:00
parent 6ae0abe3d3
commit 3ebc77c148
105 changed files with 1281 additions and 824 deletions

View File

@@ -3,17 +3,17 @@
namespace nall {
template<bool Insensitive, bool Quoted>
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<Insensitive>(p + n, size - n, from.data(), from.size())) { n++; continue; }
@@ -27,7 +27,7 @@ auto string::_replace(rstring from, rstring to, long limit) -> string& {
if(to.size() == from.size()) {
char* p = get();
for(signed n = 0, remaining = matches, quoted = 0; n <= size - (signed)from.size();) {
for(int n = 0, remaining = matches, quoted = 0; n <= size - (int)from.size();) {
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } }
if(_compare<Insensitive>(p + n, size - n, from.data(), from.size())) { n++; continue; }
@@ -41,10 +41,10 @@ auto string::_replace(rstring from, rstring to, long limit) -> string& {
//left-to-right shrink
else if(to.size() < from.size()) {
char* p = get();
signed offset = 0;
signed base = 0;
int offset = 0;
int base = 0;
for(signed n = 0, remaining = matches, quoted = 0; n <= size - (signed)from.size();) {
for(int n = 0, remaining = matches, quoted = 0; n <= size - (int)from.size();) {
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } }
if(_compare<Insensitive>(p + n, size - n, from.data(), from.size())) { n++; continue; }
@@ -66,10 +66,10 @@ auto string::_replace(rstring from, rstring to, long limit) -> string& {
resize(size + matches * (to.size() - from.size()));
char* p = get();
signed offset = this->size();
signed base = size;
int offset = this->size();
int base = size;
for(signed n = size, remaining = matches; n >= (signed)from.size();) { //quoted reused from parent scope since we are iterating backward
for(int n = size, remaining = matches; n >= (int)from.size();) { //quoted reused from parent scope since we are iterating backward
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n--; continue; } if(quoted) { n--; continue; } }
if(_compare<Insensitive>(p + n - from.size(), size - n + from.size(), from.data(), from.size())) { n--; continue; }
@@ -86,9 +86,9 @@ auto string::_replace(rstring from, rstring to, long limit) -> string& {
return *this;
}
auto string::replace(rstring from, rstring to, long limit) -> string& { return _replace<0, 0>(from, to, limit); }
auto string::ireplace(rstring from, rstring to, long limit) -> string& { return _replace<1, 0>(from, to, limit); }
auto string::qreplace(rstring from, rstring to, long limit) -> string& { return _replace<0, 1>(from, to, limit); }
auto string::iqreplace(rstring from, rstring to, long limit) -> string& { return _replace<1, 1>(from, to, limit); }
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); }
};