bsnes/nall/string/core.hpp

90 lines
2.5 KiB
C++
Raw Normal View History

#ifdef NALL_STRING_INTERNAL_HPP
//only allocators may access _data or modify _size and _capacity
//all other functions must use data(), size(), capacity()
#if defined(NALL_STRING_ALLOCATOR_COPY_ON_WRITE)
#include <nall/string/allocator/copy-on-write.hpp>
#elif defined(NALL_STRING_ALLOCATOR_SMALL_STRING_OPTIMIZATION)
#include <nall/string/allocator/small-string-optimization.hpp>
#elif defined(NALL_STRING_ALLOCATOR_VECTOR)
#include <nall/string/allocator/vector.hpp>
#endif
namespace nall {
unsigned string::length() const { return strlen(data()); }
unsigned string::size() const { return _size; }
unsigned string::capacity() const { return _capacity; }
bool string::empty() const { return _size == 0; }
void string::clear(char c) {
for(unsigned n = 0; n < size(); n++) data()[n] = c;
}
unsigned string::hash() const {
const char* p = data();
unsigned result = 5381;
while(*p) result = (result << 5) + result + *p++;
return result;
}
template<typename... Args> string& string::assign(Args&&... args) {
resize(0);
sprint(*this, std::forward<Args>(args)...);
return *this;
}
template<typename... Args> string& string::append(Args&&... args) {
sprint(*this, std::forward<Args>(args)...);
return *this;
}
string& string::_append(const char* s) {
if(s == nullptr) return *this;
unsigned basesize = size(), length = strlen(s);
reserve(basesize + length);
memcpy(data() + basesize, s, length);
resize(basesize + length);
return *this;
}
string::operator bool() const {
return !empty();
}
string::operator const char*() const {
return data();
}
char& string::operator[](signed position) {
if(position > size() + 1) throw exception_out_of_bounds{};
return data()[position];
}
const char& string::operator[](signed position) const {
if(position > size() + 1) throw exception_out_of_bounds{};
return data()[position];
}
bool string::operator==(const char* str) const { return strcmp(data(), str) == 0; }
bool string::operator!=(const char* str) const { return strcmp(data(), str) != 0; }
bool string::operator< (const char* str) const { return strcmp(data(), str) < 0; }
bool string::operator<=(const char* str) const { return strcmp(data(), str) <= 0; }
bool string::operator> (const char* str) const { return strcmp(data(), str) > 0; }
bool string::operator>=(const char* str) const { return strcmp(data(), str) >= 0; }
string::string(const string& source) {
construct();
operator=(source);
}
string::string(string&& source) {
construct();
operator=(std::move(source));
Update to higan v091r14 and ananke v00r03 releases. byuu says: higan changelog: - generates title displayed in emulator window by asking the core - core builds title solely from "information/title" ... if it's not there, you don't get a title at all - sub-system load menu is gone ... since there are multiple revisions of the SGB, this never really worked well anyway - to load an SGB, BS-X or ST cartridge, load the base cartridge first - "File->Load Game" moved to "Load->Import Game" ... may cause a bit of confusion to new users, but I don't like having a single-item menu, we'll just have to explain it to new users - browser window redone to look like ananke - home button here goes to ~/Emulation rather than just ~ like ananke, since this is the home of game folders - game folder icon is now the executable icon for the Tango theme (orange diamond), meant to represent a complete game rather than a game file or archive ananke changelog: - outputs GBC games to "Game Boy Color/" instead of "Game Boy/" - adds the file basename to "information/title" Known issues: - using ananke to load a GB game trips the Super Famicom SGB mode and fails (need to make the full-path auto-detection ignore non-bootable systems) - need to dump and test some BS-X media before releasing - ananke lacks BS-X Satellaview cartridge support - v092 isn't going to let you retarget the ananke/higan game folder path of ~/Emulation, you will have to wait for a future version if that bothers you so greatly [Later, after the v092 release, byuu posted this additional changelog: - kill laevateinn - add title() - add bootable, remove load - combine file, library - combine [][][] paths - fix SFC subtype handling XML->BML - update file browser to use buttons - update file browser keyboard handling - update system XML->BML - fix sufami turbo hashing - remove Cartridge::manifest ]
2012-12-25 05:31:55 +00:00
}
}
#endif