Update to v095r07 release.

byuu says:

Changelog:
- entire GBA core ported to auto function() -> return; syntax
- fixed GBA BLDY bug that was causing flickering in a few games
- replaced nall/config usage with nall/string/markup/node
  - this merges all configuration files to a unified settings.bml file
- added "Ignore Manifests" option to the advanced setting tab
  - this lets you keep a manifest.bml for an older version of higan; if
    you want to do regression testing

Be sure to remap your controller/hotkey inputs, and for SNES, choose
"Gamepad" from "Controller Port 1" in the system menu. Otherwise you
won't get any input. No need to blow away your old config files, unless
you want to.
This commit is contained in:
Tim Allen
2015-11-16 19:38:05 +11:00
parent 40f4b91000
commit 41c478ac4a
96 changed files with 1055 additions and 1156 deletions

View File

@@ -41,7 +41,7 @@ auto string::reset() -> type& {
return *this;
}
auto string::reserve(unsigned capacity) -> type& {
auto string::reserve(uint capacity) -> type& {
if(capacity <= _capacity) return *this;
capacity = bit::round(capacity + 1) - 1;
if(_capacity < SSO) {
@@ -57,7 +57,7 @@ auto string::reserve(unsigned capacity) -> type& {
return *this;
}
auto string::resize(unsigned size) -> type& {
auto string::resize(uint size) -> type& {
reserve(size);
get()[_size = size] = 0;
return *this;
@@ -94,27 +94,27 @@ auto string::operator=(string&& source) -> type& {
auto string::_allocate() -> void {
char _temp[SSO];
memory::copy(_temp, _text, SSO);
_data = (char*)memory::allocate(_capacity + 1 + sizeof(unsigned));
_data = (char*)memory::allocate(_capacity + 1 + sizeof(uint));
memory::copy(_data, _temp, SSO);
_refs = (unsigned*)(_data + _capacity + 1); //always aligned by 32 via reserve()
_refs = (uint*)(_data + _capacity + 1); //always aligned by 32 via reserve()
*_refs = 1;
}
//COW -> Unique
auto string::_copy() -> void {
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(unsigned));
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(uint));
memory::copy(_temp, _data, _size = min(_capacity, _size));
_temp[_size] = 0;
--*_refs;
_data = _temp;
_refs = (unsigned*)(_data + _capacity + 1);
_refs = (uint*)(_data + _capacity + 1);
*_refs = 1;
}
//COW -> Resize
auto string::_resize() -> void {
_data = (char*)memory::resize(_data, _capacity + 1 + sizeof(unsigned));
_refs = (unsigned*)(_data + _capacity + 1);
_data = (char*)memory::resize(_data, _capacity + 1 + sizeof(uint));
_refs = (uint*)(_data + _capacity + 1);
*_refs = 1;
}

View File

@@ -28,7 +28,7 @@ auto string::reset() -> type& {
return *this;
}
auto string::reserve(unsigned capacity) -> type& {
auto string::reserve(uint capacity) -> type& {
if(capacity > _capacity) {
_capacity = bit::round(max(31u, capacity) + 1) - 1;
_data = _data ? _copy() : _allocate();
@@ -36,7 +36,7 @@ auto string::reserve(unsigned capacity) -> type& {
return *this;
}
auto string::resize(unsigned size) -> type& {
auto string::resize(uint size) -> type& {
reserve(size);
get()[_size = size] = 0;
return *this;
@@ -70,19 +70,19 @@ auto string::operator=(string&& source) -> string& {
}
auto string::_allocate() -> char* {
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(unsigned));
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(uint));
*_temp = 0;
_refs = (unsigned*)(_temp + _capacity + 1); //this will always be aligned by 32 via reserve()
_refs = (uint*)(_temp + _capacity + 1); //this will always be aligned by 32 via reserve()
*_refs = 1;
return _temp;
}
auto string::_copy() -> char* {
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(unsigned));
auto _temp = (char*)memory::allocate(_capacity + 1 + sizeof(uint));
memory::copy(_temp, _data, _size = min(_capacity, _size));
_temp[_size] = 0;
--*_refs;
_refs = (unsigned*)(_temp + _capacity + 1);
_refs = (uint*)(_temp + _capacity + 1);
*_refs = 1;
return _temp;
}

View File

@@ -44,7 +44,7 @@ auto string::reset() -> type& {
return *this;
}
auto string::reserve(unsigned capacity) -> type& {
auto string::reserve(uint capacity) -> type& {
if(capacity <= _capacity) return *this;
capacity = bit::round(capacity + 1) - 1;
if(_capacity < SSO) {
@@ -58,7 +58,7 @@ auto string::reserve(unsigned capacity) -> type& {
return *this;
}
auto string::resize(unsigned size) -> type& {
auto string::resize(uint size) -> type& {
reserve(size);
get()[_size = size] = 0;
return *this;

View File

@@ -36,7 +36,7 @@ auto string::reset() -> type& {
return *this;
}
auto string::reserve(unsigned capacity) -> type& {
auto string::reserve(uint capacity) -> type& {
if(capacity > _capacity) {
_capacity = bit::round(capacity + 1) - 1;
_data = (char*)memory::resize(_data, _capacity + 1);
@@ -45,7 +45,7 @@ auto string::reserve(unsigned capacity) -> type& {
return *this;
}
auto string::resize(unsigned size) -> type& {
auto string::resize(uint size) -> type& {
reserve(size);
get()[_size = size] = 0;
return *this;

View File

@@ -3,16 +3,10 @@
namespace nall {
auto string::integer() const -> intmax {
if(beginsWith("0b") || beginsWith("0B")) return nall::binary(data());
if(beginsWith("0o") || beginsWith("0O")) return nall::octal(data());
if(beginsWith("0x") || beginsWith("0X")) return nall::hex(data());
return nall::integer(data());
}
auto string::natural() const -> uintmax {
if(beginsWith("0b") || beginsWith("0B")) return nall::binary(data());
if(beginsWith("0o") || beginsWith("0O")) return nall::octal(data());
if(beginsWith("0x") || beginsWith("0X")) return nall::hex(data());
return nall::natural(data());
}

View File

@@ -20,13 +20,13 @@ template<typename T> struct stringify;
//format.hpp
template<typename... P> inline auto print(P&&...) -> void;
inline auto integer(intmax_t value, long precision = 0, char padchar = '0') -> string;
inline auto decimal(uintmax_t value, long precision = 0, char padchar = '0') -> string;
inline auto hex(uintmax_t value, long precision = 0, char padchar = '0') -> string;
inline auto octal(uintmax_t value, long precision = 0, char padchar = '0') -> string;
inline auto binary(uintmax_t value, long precision = 0, char padchar = '0') -> string;
inline auto integer(intmax value, long precision = 0, char padchar = '0') -> string;
inline auto decimal(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<typename T> inline auto pointer(const T* value, long precision = 0) -> string;
inline auto pointer(uintptr_t value, long precision = 0) -> string;
inline auto pointer(uintptr value, long precision = 0) -> string;
inline auto real(long double value) -> string;
//hash.hpp
@@ -58,11 +58,11 @@ inline auto sharedpath() -> string;
inline auto temppath() -> string;
//utility.hpp
inline auto slice(rstring self, signed offset = 0, signed length = -1) -> string;
inline auto slice(rstring self, int offset = 0, int length = -1) -> string;
inline auto integer(char* result, intmax_t value) -> char*;
inline auto decimal(char* result, uintmax_t value) -> char*;
inline auto real(char* str, long double value) -> unsigned;
inline auto integer(char* result, intmax value) -> char*;
inline auto decimal(char* result, uintmax value) -> char*;
inline auto real(char* str, long double value) -> uint;
struct string {
using type = string;
@@ -70,11 +70,11 @@ struct string {
protected:
#if defined(NALL_STRING_ALLOCATOR_ADAPTIVE)
enum : unsigned { SSO = 24 };
enum : uint { SSO = 24 };
union {
struct { //copy-on-write
char* _data;
unsigned* _refs;
uint* _refs;
};
struct { //small-string-optimization
char _text[SSO];
@@ -87,13 +87,13 @@ protected:
#if defined(NALL_STRING_ALLOCATOR_COPY_ON_WRITE)
char* _data;
mutable unsigned* _refs;
mutable uint* _refs;
inline auto _allocate() -> char*;
inline auto _copy() -> char*;
#endif
#if defined(NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION)
enum : unsigned { SSO = 24 };
enum : uint { SSO = 24 };
union {
char* _data;
char _text[SSO];
@@ -104,16 +104,16 @@ protected:
char* _data;
#endif
unsigned _capacity;
unsigned _size;
uint _capacity;
uint _size;
public:
inline string();
inline auto get() -> char*;
inline auto data() const -> const char*;
inline auto reset() -> type&;
inline auto reserve(unsigned) -> type&;
inline auto resize(unsigned) -> type&;
inline auto reserve(uint) -> type&;
inline auto resize(uint) -> type&;
inline auto operator=(const string&) -> type&;
inline auto operator=(string&&) -> type&;
@@ -125,8 +125,8 @@ public:
operator const char*() const { return (const char*)data(); }
auto binary() const -> const uint8_t* { return (const uint8_t*)data(); }
auto size() const -> unsigned { return _size; }
auto capacity() const -> unsigned { return _capacity; }
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; }
@@ -155,14 +155,14 @@ public:
inline auto real() const -> double;
//core.hpp
inline auto operator[](signed) const -> const char&;
inline auto operator[](int) const -> const char&;
template<typename... P> inline auto assign(P&&...) -> type&;
template<typename T, typename... P> inline auto append(const T&, P&&...) -> type&;
template<typename... P> inline auto append(const nall::format&, P&&...) -> type&;
inline auto append() -> type&;
template<typename T> inline auto _append(const stringify<T>&) -> string&;
inline auto empty() const -> bool;
inline auto length() const -> unsigned;
inline auto length() const -> uint;
//datetime.hpp
inline static auto date(time_t = 0) -> string;
@@ -170,21 +170,21 @@ public:
inline static auto datetime(time_t = 0) -> string;
//find.hpp
template<bool, bool> inline auto _find(signed, rstring) const -> maybe<unsigned>;
template<bool, bool> inline auto _find(int, rstring) const -> maybe<uint>;
inline auto find(rstring source) const -> maybe<unsigned>;
inline auto ifind(rstring source) const -> maybe<unsigned>;
inline auto qfind(rstring source) const -> maybe<unsigned>;
inline auto iqfind(rstring source) const -> maybe<unsigned>;
inline auto findFrom(signed offset, rstring source) const -> maybe<unsigned>;
inline auto ifindFrom(signed offset, rstring source) const -> maybe<unsigned>;
inline auto findFrom(int offset, rstring source) const -> maybe<uint>;
inline auto ifindFrom(int offset, rstring source) const -> maybe<uint>;
//format.hpp
inline auto format(const nall::format& params) -> type&;
//compare.hpp
template<bool> inline static auto _compare(const char*, unsigned, const char*, unsigned) -> signed;
template<bool> 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;
@@ -242,12 +242,12 @@ public:
//utility.hpp
inline static auto read(rstring filename) -> string;
inline static auto repeat(rstring pattern, unsigned times) -> string;
inline static auto repeat(rstring pattern, uint times) -> string;
inline auto fill(char fill = ' ') -> type&;
inline auto hash() const -> unsigned;
inline auto remove(unsigned offset, unsigned length) -> type&;
inline auto hash() const -> uint;
inline auto remove(uint offset, uint length) -> type&;
inline auto reverse() -> type&;
inline auto size(signed length, char fill = ' ') -> type&;
inline auto size(int length, char fill = ' ') -> type&;
};
struct lstring : vector<string> {
@@ -255,7 +255,7 @@ struct lstring : vector<string> {
lstring(const lstring& source) { vector::operator=(source); }
lstring(lstring& source) { vector::operator=(source); }
lstring(lstring&& source) { vector::operator=(std::move(source)); }
lstring(lstring&& source) { vector::operator=(move(source)); }
template<typename... P> lstring(P&&... p) { append(forward<P>(p)...); }
//list.hpp
@@ -264,15 +264,15 @@ struct lstring : vector<string> {
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=(std::move(source)), *this; }
inline auto operator=(lstring&& source) -> type& { return vector::operator=(move(source)), *this; }
inline auto isort() -> type&;
template<typename... P> inline auto append(const string&, P&&...) -> type&;
inline auto append() -> type&;
inline auto find(rstring source) const -> maybe<unsigned>;
inline auto ifind(rstring source) const -> maybe<unsigned>;
inline auto find(rstring source) const -> maybe<uint>;
inline auto ifind(rstring source) const -> maybe<uint>;
inline auto match(rstring pattern) const -> lstring;
inline auto merge(rstring separator) const -> string;
inline auto strip() -> type&;

View File

@@ -3,25 +3,25 @@
namespace nall {
template<bool Insensitive>
auto string::_compare(const char* target, unsigned capacity, const char* source, unsigned size) -> signed {
auto string::_compare(const char* target, uint capacity, const char* source, uint size) -> signed {
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) -> signed {
auto string::compare(rstring x, rstring y) -> int {
return memory::compare(x.data(), x.size() + 1, y.data(), y.size() + 1);
}
auto string::icompare(rstring x, rstring y) -> signed {
auto string::icompare(rstring x, rstring y) -> int {
return memory::icompare(x.data(), x.size() + 1, y.data(), y.size() + 1);
}
auto string::compare(rstring source) const -> signed {
auto string::compare(rstring source) const -> int {
return memory::compare(data(), size() + 1, source.data(), source.size() + 1);
}
auto string::icompare(rstring source) const -> signed {
auto string::icompare(rstring source) const -> int {
return memory::icompare(data(), size() + 1, source.data(), source.size() + 1);
}

View File

@@ -15,7 +15,7 @@
namespace nall {
auto string::operator[](signed position) const -> const char& {
auto string::operator[](int position) const -> const char& {
if(position > size() + 1) throw exception_out_of_bounds{};
return data()[position];
}
@@ -49,7 +49,7 @@ auto string::empty() const -> bool {
return size() == 0;
}
auto string::length() const -> unsigned {
auto string::length() const -> uint {
return strlen(data());
}

View File

@@ -3,7 +3,7 @@
namespace nall {
namespace Eval {
inline string evaluateExpression(Node* node) {
inline auto evaluateExpression(Node* node) -> string {
#define p(n) evaluateExpression(node->link[n])
switch(node->type) {
case Node::Type::Null: return "Null";
@@ -37,15 +37,8 @@ inline string evaluateExpression(Node* node) {
throw "invalid operator";
}
inline int64_t evaluateInteger(Node* node) {
if(node->type == Node::Type::Literal) {
if(node->literal.beginsWith("0b")) return nall::binary(node->literal);
if(node->literal.beginsWith("0o")) return nall::octal(node->literal);
if(node->literal.beginsWith("0x")) return nall::hex(node->literal);
if(node->literal.beginsWith("%")) return nall::binary(node->literal);
if(node->literal.beginsWith("$")) return nall::hex(node->literal);
return nall::integer(node->literal);
}
inline auto evaluateInteger(Node* node) -> int64 {
if(node->type == Node::Type::Literal) return nall::integer(node->literal);
#define p(n) evaluateInteger(node->link[n])
switch(node->type) {
@@ -93,7 +86,7 @@ inline int64_t evaluateInteger(Node* node) {
throw "invalid operator";
}
inline maybe<int64_t> integer(const string& expression) {
inline auto integer(const string& expression) -> maybe<int64> {
try {
auto tree = new Node;
const char* p = expression;
@@ -106,7 +99,7 @@ inline maybe<int64_t> integer(const string& expression) {
}
}
inline long double evaluateReal(Node* node) {
inline auto evaluateReal(Node* node) -> long double {
if(node->type == Node::Type::Literal) return nall::real(node->literal);
#define p(n) evaluateReal(node->link[n])
@@ -138,7 +131,7 @@ inline long double evaluateReal(Node* node) {
throw "invalid operator";
}
inline maybe<long double> real(const string& expression) {
inline auto real(const string& expression) -> maybe<long double> {
try {
auto tree = new Node;
const char* p = expression;

View File

@@ -3,7 +3,7 @@
namespace nall {
namespace Eval {
inline bool isLiteral(const char*& s) {
inline auto isLiteral(const char*& s) -> bool {
char n = s[0];
return (n >= 'A' && n <= 'Z')
|| (n >= 'a' && n <= 'z')
@@ -12,7 +12,7 @@ inline bool isLiteral(const char*& s) {
|| (n == '\'' || n == '\"');
}
inline string literalNumber(const char*& s) {
inline auto literalNumber(const char*& s) -> string {
const char* p = s;
//binary
@@ -64,7 +64,7 @@ inline string literalNumber(const char*& s) {
return result;
}
inline string literalString(const char*& s) {
inline auto literalString(const char*& s) -> string {
const char* p = s;
char escape = *p++;
@@ -76,7 +76,7 @@ inline string literalString(const char*& s) {
return result;
}
inline string literalVariable(const char*& s) {
inline auto literalVariable(const char*& s) -> string {
const char* p = s;
while(p[0] == '_' || p[0] == '.' || (p[0] >= 'A' && p[0] <= 'Z') || (p[0] >= 'a' && p[0] <= 'z') || (p[0] >= '0' && p[0] <= '9')) p++;
@@ -86,7 +86,7 @@ inline string literalVariable(const char*& s) {
return result;
}
inline string literal(const char*& s) {
inline auto literal(const char*& s) -> string {
const char* p = s;
if(p[0] >= '0' && p[0] <= '9') return literalNumber(s);

View File

@@ -4,7 +4,7 @@ namespace nall {
namespace Eval {
struct Node {
enum class Type : unsigned {
enum class Type : uint {
Null,
Literal,
Function, Subscript, Member, SuffixIncrement, SuffixDecrement,

View File

@@ -3,32 +3,32 @@
namespace nall {
namespace Eval {
inline bool whitespace(char n) {
inline auto whitespace(char n) -> bool {
return n == ' ' || n == '\t' || n == '\r' || n == '\n';
}
inline void parse(Node*& node, const char*& s, unsigned depth) {
auto unaryPrefix = [&](Node::Type type, unsigned seek, unsigned depth) {
inline auto parse(Node*& node, const char*& s, uint depth) -> void {
auto unaryPrefix = [&](Node::Type type, uint seek, uint depth) {
auto parent = new Node(type);
parse(parent->link(0) = new Node, s += seek, depth);
node = parent;
};
auto unarySuffix = [&](Node::Type type, unsigned seek, unsigned depth) {
auto unarySuffix = [&](Node::Type type, uint seek, uint depth) {
auto parent = new Node(type);
parent->link(0) = node;
parse(parent, s += seek, depth);
node = parent;
};
auto binary = [&](Node::Type type, unsigned seek, unsigned depth) {
auto binary = [&](Node::Type type, uint seek, uint depth) {
auto parent = new Node(type);
parent->link(0) = node;
parse(parent->link(1) = new Node, s += seek, depth);
node = parent;
};
auto ternary = [&](Node::Type type, unsigned seek, unsigned depth) {
auto ternary = [&](Node::Type type, uint seek, uint depth) {
auto parent = new Node(type);
parent->link(0) = node;
parse(parent->link(1) = new Node, s += seek, depth);
@@ -37,9 +37,9 @@ inline void parse(Node*& node, const char*& s, unsigned depth) {
node = parent;
};
auto separator = [&](Node::Type type, unsigned seek, unsigned depth) {
auto separator = [&](Node::Type type, uint seek, uint depth) {
if(node->type != Node::Type::Separator) return binary(type, seek, depth);
unsigned n = node->link.size();
uint n = node->link.size();
parse(node->link(n) = new Node, s += seek, depth);
};
@@ -155,7 +155,7 @@ inline void parse(Node*& node, const char*& s, unsigned depth) {
#undef p
}
inline Node* parse(const string& expression) {
inline auto parse(const string& expression) -> Node* {
auto result = new Node;
const char* p = expression;
parse(result, p, 0);

View File

@@ -2,11 +2,11 @@
namespace nall {
template<bool Insensitive, bool Quoted> auto string::_find(signed offset, rstring source) const -> maybe<unsigned> {
template<bool Insensitive, bool Quoted> auto string::_find(int offset, rstring source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
auto p = data();
for(unsigned n = offset, quoted = 0; n < size();) {
for(uint n = offset, quoted = 0; n < size();) {
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } }
if(_compare<Insensitive>(p + n, size() - n, source.data(), source.size())) { n++; continue; }
return n - offset;
@@ -15,13 +15,13 @@ template<bool Insensitive, bool Quoted> auto string::_find(signed offset, rstrin
return nothing;
}
auto string::find(rstring source) const -> maybe<unsigned> { return _find<0, 0>(0, source); }
auto string::ifind(rstring source) const -> maybe<unsigned> { return _find<1, 0>(0, source); }
auto string::qfind(rstring source) const -> maybe<unsigned> { return _find<0, 1>(0, source); }
auto string::iqfind(rstring source) const -> maybe<unsigned> { return _find<1, 1>(0, source); }
auto string::find(rstring source) const -> maybe<uint> { return _find<0, 0>(0, source); }
auto string::ifind(rstring source) const -> maybe<uint> { return _find<1, 0>(0, source); }
auto string::qfind(rstring source) const -> maybe<uint> { return _find<0, 1>(0, source); }
auto string::iqfind(rstring source) const -> maybe<uint> { return _find<1, 1>(0, source); }
auto string::findFrom(signed offset, rstring source) const -> maybe<unsigned> { return _find<0, 0>(offset, source); }
auto string::ifindFrom(signed offset, rstring source) const -> maybe<unsigned> { return _find<1, 0>(offset, source); }
auto string::findFrom(int offset, rstring source) const -> maybe<uint> { return _find<0, 0>(offset, source); }
auto string::ifindFrom(int offset, rstring source) const -> maybe<uint> { return _find<1, 0>(offset, source); }
}

View File

@@ -6,8 +6,8 @@ namespace nall {
//each {#} token will be replaced with its appropriate format parameter
auto string::format(const nall::format& params) -> type& {
signed size = this->size();
char* data = (char*)memory::allocate(size);
auto size = (int)this->size();
auto data = (char*)memory::allocate(size);
memory::copy(data, this->data(), size);
signed x = 0;
@@ -32,19 +32,19 @@ auto string::format(const nall::format& params) -> type& {
};
if(!isNumeric(&data[x + 1], &data[y - 1])) { x++; continue; }
unsigned index = nall::natural(&data[x + 1]);
uint index = nall::natural(&data[x + 1]);
if(index >= params.size()) { x++; continue; }
unsigned sourceSize = y - x;
unsigned targetSize = params[index].size();
unsigned remaining = size - x;
uint sourceSize = y - x;
uint targetSize = params[index].size();
uint remaining = size - x;
if(sourceSize > targetSize) {
unsigned difference = sourceSize - targetSize;
uint difference = sourceSize - targetSize;
memory::move(&data[x], &data[x + difference], remaining);
size -= difference;
} else if(targetSize > sourceSize) {
unsigned difference = targetSize - sourceSize;
uint difference = targetSize - sourceSize;
data = (char*)realloc(data, size + difference);
size += difference;
memory::move(&data[x + difference], &data[x], remaining);
@@ -73,14 +73,14 @@ template<typename... P> auto print(P&&... p) -> void {
fputs(s.data(), stdout);
}
auto integer(intmax_t value, long precision, char padchar) -> string {
auto integer(intmax value, long precision, char padchar) -> string {
string buffer;
buffer.resize(1 + sizeof(intmax_t) * 3);
buffer.resize(1 + sizeof(intmax) * 3);
char* p = buffer.get();
bool negative = value < 0;
value = abs(value);
unsigned size = 0;
uint size = 0;
do {
p[size++] = '0' + (value % 10);
value /= 10;
@@ -92,12 +92,12 @@ auto integer(intmax_t value, long precision, char padchar) -> string {
return buffer;
}
auto decimal(uintmax_t value, long precision, char padchar) -> string {
auto decimal(uintmax value, long precision, char padchar) -> string {
string buffer;
buffer.resize(sizeof(uintmax_t) * 3);
buffer.resize(sizeof(uintmax) * 3);
char* p = buffer.get();
unsigned size = 0;
uint size = 0;
do {
p[size++] = '0' + (value % 10);
value /= 10;
@@ -108,14 +108,14 @@ auto decimal(uintmax_t value, long precision, char padchar) -> string {
return buffer;
}
auto hex(uintmax_t value, long precision, char padchar) -> string {
auto hex(uintmax value, long precision, char padchar) -> string {
string buffer;
buffer.resize(sizeof(uintmax_t) * 2);
buffer.resize(sizeof(uintmax) * 2);
char* p = buffer.get();
unsigned size = 0;
uint size = 0;
do {
unsigned n = value & 15;
uint n = value & 15;
p[size++] = n < 10 ? '0' + n : 'a' + n - 10;
value >>= 4;
} while(value);
@@ -125,12 +125,12 @@ auto hex(uintmax_t value, long precision, char padchar) -> string {
return buffer;
}
auto octal(uintmax_t value, long precision, char padchar) -> string {
auto octal(uintmax value, long precision, char padchar) -> string {
string buffer;
buffer.resize(sizeof(uintmax_t) * 3);
buffer.resize(sizeof(uintmax) * 3);
char* p = buffer.get();
unsigned size = 0;
uint size = 0;
do {
p[size++] = '0' + (value & 7);
value >>= 3;
@@ -141,12 +141,12 @@ auto octal(uintmax_t value, long precision, char padchar) -> string {
return buffer;
}
auto binary(uintmax_t value, long precision, char padchar) -> string {
auto binary(uintmax value, long precision, char padchar) -> string {
string buffer;
buffer.resize(sizeof(uintmax_t) * 8);
buffer.resize(sizeof(uintmax) * 8);
char* p = buffer.get();
unsigned size = 0;
uint size = 0;
do {
p[size++] = '0' + (value & 1);
value >>= 1;
@@ -158,12 +158,12 @@ auto binary(uintmax_t value, long precision, char padchar) -> string {
}
template<typename T> auto pointer(const T* value, long precision) -> string {
if(value == nullptr) return "(null)";
return {"0x", hex((uintptr_t)value, precision)};
if(value == nullptr) return "(nullptr)";
return {"0x", hex((uintptr)value, precision)};
}
auto pointer(uintptr_t value, long precision) -> string {
if(value == 0) return "(null)";
auto pointer(uintptr value, long precision) -> string {
if(value == 0) return "(nullptr)";
return {"0x", hex(value, precision)};
}

View File

@@ -5,7 +5,7 @@ namespace nall {
auto lstring::operator==(const lstring& source) const -> bool {
if(this == &source) return true;
if(size() != source.size()) return false;
for(unsigned n = 0; n < size(); n++) {
for(uint n = 0; n < size(); n++) {
if(operator[](n) != source[n]) return false;
}
return true;
@@ -32,15 +32,15 @@ auto lstring::append() -> lstring& {
return *this;
}
auto lstring::find(rstring source) const -> maybe<unsigned> {
for(unsigned n = 0; n < size(); n++) {
auto lstring::find(rstring source) const -> maybe<uint> {
for(uint n = 0; n < size(); n++) {
if(operator[](n).equals(source)) return n;
}
return nothing;
}
auto lstring::ifind(rstring source) const -> maybe<unsigned> {
for(unsigned n = 0; n < size(); n++) {
auto lstring::ifind(rstring source) const -> maybe<uint> {
for(uint n = 0; n < size(); n++) {
if(operator[](n).iequals(source)) return n;
}
return nothing;
@@ -48,7 +48,7 @@ auto lstring::ifind(rstring source) const -> maybe<unsigned> {
auto lstring::match(rstring pattern) const -> lstring {
lstring result;
for(unsigned n = 0; n < size(); n++) {
for(uint n = 0; n < size(); n++) {
if(operator[](n).match(pattern)) result.append(operator[](n));
}
return result;
@@ -56,7 +56,7 @@ auto lstring::match(rstring pattern) const -> lstring {
auto lstring::merge(rstring separator) const -> string {
string output;
for(unsigned n = 0; n < size(); n++) {
for(uint n = 0; n < size(); n++) {
output.append(operator[](n));
if(n < size() - 1) output.append(separator.data());
}
@@ -64,7 +64,7 @@ auto lstring::merge(rstring separator) const -> string {
}
auto lstring::strip() -> lstring& {
for(unsigned n = 0; n < size(); n++) {
for(uint n = 0; n < size(); n++) {
operator[](n).strip();
}
return *this;

View File

@@ -19,22 +19,22 @@ protected:
}
//determine indentation level, without incrementing pointer
auto readDepth(const char* p) -> unsigned {
unsigned depth = 0;
auto readDepth(const char* p) -> uint {
uint depth = 0;
while(p[depth] == '\t' || p[depth] == ' ') depth++;
return depth;
}
//determine indentation level
auto parseDepth(const char*& p) -> unsigned {
unsigned depth = readDepth(p);
auto parseDepth(const char*& p) -> uint {
uint depth = readDepth(p);
p += depth;
return depth;
}
//read name
auto parseName(const char*& p) -> void {
unsigned length = 0;
uint length = 0;
while(valid(p[length])) length++;
if(length == 0) throw "Invalid node name";
_name = slice(p, 0, length);
@@ -43,19 +43,19 @@ protected:
auto parseData(const char*& p) -> void {
if(*p == '=' && *(p + 1) == '\"') {
unsigned length = 2;
uint length = 2;
while(p[length] && p[length] != '\n' && p[length] != '\"') length++;
if(p[length] != '\"') throw "Unescaped value";
_value = {slice(p, 2, length - 2), "\n"};
p += length + 1;
} else if(*p == '=') {
unsigned length = 1;
uint length = 1;
while(p[length] && p[length] != '\n' && p[length] != '\"' && p[length] != ' ') length++;
if(p[length] == '\"') throw "Illegal character in value";
_value = {slice(p, 1, length - 1), "\n"};
p += length;
} else if(*p == ':') {
unsigned length = 1;
uint length = 1;
while(p[length] && p[length] != '\n') length++;
_value = {slice(p, 1, length - 1), "\n"};
p += length;
@@ -70,7 +70,7 @@ protected:
if(*(p + 0) == '/' && *(p + 1) == '/') break; //skip comments
SharedNode node(new ManagedNode);
unsigned length = 0;
uint length = 0;
while(valid(p[length])) length++;
if(length == 0) throw "Invalid attribute name";
node->_name = slice(p, 0, length);
@@ -81,7 +81,7 @@ protected:
}
//read a node and all of its child nodes
auto parseNode(const lstring& text, unsigned& y) -> void {
auto parseNode(const lstring& text, uint& y) -> void {
const char* p = text[y++];
_metadata = parseDepth(p);
parseName(p);
@@ -89,7 +89,7 @@ protected:
parseAttributes(p);
while(y < text.size()) {
unsigned depth = readDepth(text[y]);
uint depth = readDepth(text[y]);
if(depth <= _metadata) break;
if(text[y][depth] == ':') {
@@ -132,7 +132,7 @@ protected:
if(document.size() == 0) return; //empty document
auto text = document.split("\n");
unsigned y = 0;
uint y = 0;
while(y < text.size()) {
SharedNode node(new ManagedNode);
node->parseNode(text, y);
@@ -154,7 +154,7 @@ inline auto unserialize(const string& markup) -> Markup::Node {
return (Markup::SharedNode&)node;
}
inline auto serialize(const Markup::Node& node, unsigned depth = 0) -> string {
inline auto serialize(const Markup::Node& node, uint depth = 0) -> string {
if(!node.name()) {
string result;
for(auto leaf : node) {

View File

@@ -7,7 +7,7 @@ auto ManagedNode::_evaluate(string query) const -> bool {
if(!query) return true;
for(auto& rule : query.replace(" ", "").split(",")) {
enum class Comparator : unsigned { ID, EQ, NE, LT, LE, GT, GE };
enum class Comparator : uint { ID, EQ, NE, LT, LE, GT, GE };
auto comparator = Comparator::ID;
if(rule.match("*!=*")) comparator = Comparator::NE;
else if(rule.match("*<=*")) comparator = Comparator::LE;
@@ -58,7 +58,7 @@ auto ManagedNode::_find(const string& query) const -> vector<Node> {
lstring path = query.split("/");
string name = path.take(0), rule;
unsigned lo = 0u, hi = ~0u;
uint lo = 0u, hi = ~0u;
if(name.match("*[*]")) {
auto p = name.rtrim("]", 1L).split("[", 1L);
@@ -78,7 +78,7 @@ auto ManagedNode::_find(const string& query) const -> vector<Node> {
rule = p(1);
}
unsigned position = 0;
uint position = 0;
for(auto& node : _children) {
if(!node->_name.match(name)) continue;
if(!node->_evaluate(rule)) continue;

View File

@@ -62,12 +62,13 @@ struct Node {
auto boolean() const -> bool { return text() == "true"; }
auto integer() const -> intmax { return text().integer(); }
auto natural() const -> uintmax { return text().natural(); }
auto real() const -> double { return text().real(); }
auto setName(const string& name = "") -> Node& { shared->_name = name; return *this; }
auto setValue(const string& value = "") -> Node& { shared->_value = value; return *this; }
auto reset() -> void { shared->_children.reset(); }
auto size() const -> unsigned { return shared->_children.size(); }
auto size() const -> uint { return shared->_children.size(); }
auto prepend(const Node& node) -> void { shared->_children.prepend(node.shared); }
auto append(const Node& node) -> void { shared->_children.append(node.shared); }
@@ -80,17 +81,17 @@ struct Node {
return false;
}
auto insert(unsigned position, const Node& node) -> bool {
auto insert(uint position, const Node& node) -> bool {
if(position > size()) return false; //used > instead of >= to allow indexed-equivalent of append()
return shared->_children.insert(position, node.shared), true;
}
auto remove(unsigned position) -> bool {
auto remove(uint position) -> bool {
if(position >= size()) return false;
return shared->_children.remove(position), true;
}
auto swap(unsigned x, unsigned y) -> bool {
auto swap(uint x, uint y) -> bool {
if(x >= size() || y >= size()) return false;
return std::swap(shared->_children[x], shared->_children[y]), true;
}
@@ -103,7 +104,7 @@ struct Node {
});
}
auto operator[](signed position) -> Node {
auto operator[](int position) -> Node {
if(position >= size()) return {};
return shared->_children[position];
}
@@ -116,11 +117,11 @@ struct Node {
auto operator*() -> Node { return {source.shared->_children[position]}; }
auto operator!=(const iterator& source) const -> bool { return position != source.position; }
auto operator++() -> iterator& { return position++, *this; }
iterator(const Node& source, unsigned position) : source(source), position(position) {}
iterator(const Node& source, uint position) : source(source), position(position) {}
private:
const Node& source;
unsigned position;
uint position;
};
auto begin() const -> iterator { return iterator(*this, 0); }
@@ -136,7 +137,7 @@ protected:
namespace nall {
inline range_t range(const Markup::Node& node) {
return range_t{0, (signed)node.size(), 1};
return range_t{0, (int)node.size(), 1};
}
}

View File

@@ -43,7 +43,7 @@ protected:
}
//copy part of string from source document into target string; decode markup while copying
inline void copy(string& target, const char* source, unsigned length) {
inline void copy(string& target, const char* source, uint length) {
target.reserve(length + 1);
#if defined(NALL_XML_LITERAL)
@@ -106,7 +106,7 @@ protected:
//DOCTYPE
if(!memory::compare(p, "<!DOCTYPE", 9)) {
unsigned counter = 0;
uint counter = 0;
do {
char n = *p++;
if(!n) throw "unclosed DOCTYPE";

View File

@@ -29,7 +29,7 @@ private:
};
vector<Variable> variables;
auto parseDocument(const string& filedata, const string& pathname, unsigned depth) -> bool;
auto parseDocument(const string& filedata, const string& pathname, uint depth) -> bool;
};
auto CML::parse(const string& filename) -> string {
@@ -45,7 +45,7 @@ auto CML::parse(const string& filedata, const string& pathname) -> string {
return state.output;
}
auto CML::parseDocument(const string& filedata, const string& pathname, unsigned depth) -> bool {
auto CML::parseDocument(const string& filedata, const string& pathname, uint depth) -> bool {
if(depth >= 100) return false; //prevent infinite recursion
auto vendorAppend = [&](const string& name, const string& value) {

View File

@@ -27,12 +27,12 @@ private:
struct State {
string output;
unsigned sections = 0;
uint sections = 0;
} state;
auto parseDocument(const string& filedata, const string& pathname, unsigned depth) -> bool;
auto parseBlock(string& block, const string& pathname, unsigned depth) -> bool;
auto count(const string& text, char value) -> unsigned;
auto parseDocument(const string& filedata, const string& pathname, uint depth) -> bool;
auto parseBlock(string& block, const string& pathname, uint depth) -> bool;
auto count(const string& text, char value) -> uint;
auto escape(const string& text) -> string;
auto markup(const string& text) -> string;
@@ -51,7 +51,7 @@ auto DML::parse(const string& filename) -> string {
return state.output;
}
auto DML::parseDocument(const string& filedata, const string& pathname, unsigned depth) -> bool {
auto DML::parseDocument(const string& filedata, const string& pathname, uint depth) -> bool {
if(depth >= 100) return false; //attempt to prevent infinite recursion with reasonable limit
auto blocks = filedata.split("\n\n");
@@ -60,7 +60,7 @@ auto DML::parseDocument(const string& filedata, const string& pathname, unsigned
return true;
}
auto DML::parseBlock(string& block, const string& pathname, unsigned depth) -> bool {
auto DML::parseBlock(string& block, const string& pathname, uint depth) -> bool {
if(block.rstrip().empty()) return true;
auto lines = block.split("\n");
@@ -114,7 +114,7 @@ auto DML::parseBlock(string& block, const string& pathname, unsigned depth) -> b
//navigation
else if(count(block, '-')) {
state.output.append("<nav>\n");
unsigned level = 0;
uint level = 0;
for(auto& line : lines) {
if(auto depth = count(line, '-')) {
while(level < depth) level++, state.output.append("<ul>\n");
@@ -131,7 +131,7 @@ auto DML::parseBlock(string& block, const string& pathname, unsigned depth) -> b
//list
else if(count(block, '*')) {
unsigned level = 0;
uint level = 0;
for(auto& line : lines) {
if(auto depth = count(line, '*')) {
while(level < depth) level++, state.output.append("<ul>\n");
@@ -145,7 +145,7 @@ auto DML::parseBlock(string& block, const string& pathname, unsigned depth) -> b
//quote
else if(count(block, '>')) {
unsigned level = 0;
uint level = 0;
for(auto& line : lines) {
if(auto depth = count(line, '>')) {
while(level < depth) level++, state.output.append("<blockquote>\n");
@@ -180,8 +180,8 @@ auto DML::parseBlock(string& block, const string& pathname, unsigned depth) -> b
return true;
}
auto DML::count(const string& text, char value) -> unsigned {
for(unsigned n = 0; n < text.size(); n++) {
auto DML::count(const string& text, char value) -> uint {
for(uint n = 0; n < text.size(); n++) {
if(text[n] != value) {
if(text[n] == ' ') return n;
break;
@@ -206,8 +206,8 @@ auto DML::markup(const string& text) -> string {
string output;
char match = 0;
unsigned offset = 0;
for(unsigned n = 0; n < text.size();) {
uint offset = 0;
for(uint n = 0; n < text.size();) {
char a = n ? text[n - 1] : 0;
char b = text[n];
char c = text[n++ + 1];

View File

@@ -13,7 +13,7 @@ auto string::read(rstring filename) -> string {
if(!fp) return result;
fseek(fp, 0, SEEK_END);
signed filesize = ftell(fp);
int filesize = ftell(fp);
if(filesize < 0) return fclose(fp), result;
rewind(fp);
@@ -22,7 +22,7 @@ auto string::read(rstring filename) -> string {
return fclose(fp), result;
}
auto string::repeat(rstring pattern, unsigned times) -> string {
auto string::repeat(rstring pattern, uint times) -> string {
string result;
while(times--) result.append(pattern.data());
return result;
@@ -35,13 +35,13 @@ auto string::fill(char fill) -> string& {
auto string::hash() const -> unsigned {
const char* p = data();
unsigned length = size();
unsigned result = 5381;
uint length = size();
uint result = 5381;
while(length--) result = (result << 5) + result + *p++;
return result;
}
auto string::remove(unsigned offset, unsigned length) -> string& {
auto string::remove(uint offset, uint length) -> string& {
char* p = get();
length = min(length, size());
memory::move(p + offset, p + offset + length, size() - length);
@@ -50,16 +50,16 @@ auto string::remove(unsigned offset, unsigned length) -> string& {
auto string::reverse() -> string& {
char* p = get();
unsigned length = size();
unsigned pivot = length >> 1;
for(signed x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(p[x], p[y]);
uint length = size();
uint pivot = length >> 1;
for(int x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(p[x], p[y]);
return *this;
}
//+length => insert/delete from start (right justify)
//-length => insert/delete from end (left justify)
auto string::size(signed length, char fill) -> string& {
unsigned size = this->size();
auto string::size(int length, char fill) -> string& {
uint size = this->size();
if(size == length) return *this;
bool right = length >= 0;
@@ -68,13 +68,13 @@ auto string::size(signed length, char fill) -> string& {
if(size < length) { //expand
resize(length);
char* p = get();
unsigned displacement = length - size;
uint displacement = length - size;
if(right) memory::move(p + displacement, p, size);
else p += size;
while(displacement--) *p++ = fill;
} else { //shrink
char* p = get();
unsigned displacement = size - length;
uint displacement = size - length;
if(right) memory::move(p, p + displacement, length);
resize(length);
}
@@ -82,7 +82,7 @@ auto string::size(signed length, char fill) -> string& {
return *this;
}
auto slice(rstring self, signed offset, signed length) -> string {
auto slice(rstring self, int offset, int length) -> string {
string result;
if(offset < self.size()) {
if(length < 0) length = self.size() - offset;
@@ -92,36 +92,36 @@ auto slice(rstring self, signed offset, signed length) -> string {
return result;
}
auto integer(char* result, intmax_t value) -> char* {
auto integer(char* result, intmax value) -> char* {
bool negative = value < 0;
if(negative) value = -value;
char buffer[64];
unsigned size = 0;
uint size = 0;
do {
unsigned n = value % 10;
uint n = value % 10;
buffer[size++] = '0' + n;
value /= 10;
} while(value);
if(negative) buffer[size++] = '-';
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
for(int x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
result[size] = 0;
return result;
}
auto decimal(char* result, uintmax_t value) -> char* {
auto decimal(char* result, uintmax value) -> char* {
char buffer[64];
unsigned size = 0;
uint size = 0;
do {
unsigned n = value % 10;
uint n = value % 10;
buffer[size++] = '0' + n;
value /= 10;
} while(value);
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
for(int x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
result[size] = 0;
return result;
}
@@ -129,7 +129,7 @@ auto decimal(char* result, uintmax_t value) -> char* {
//using sprintf is certainly not the most ideal method to convert
//a double to a string ... but attempting to parse a double by
//hand, digit-by-digit, results in subtle rounding errors.
auto real(char* result, long double value) -> unsigned {
auto real(char* result, long double value) -> uint {
char buffer[256];
#ifdef _WIN32
//Windows C-runtime does not support long double via sprintf()
@@ -150,7 +150,7 @@ auto real(char* result, long double value) -> unsigned {
}
}
unsigned length = strlen(buffer);
uint length = strlen(buffer);
if(result) strcpy(result, buffer);
return length + 1;
}