mirror of https://github.com/bsnes-emu/bsnes.git
Update to v092r09 release.
byuu says: This will be another massive diff from the previous version. All of higan was updated to use the new foo& bar syntax, and I also updated switch statements to be consistent as well (but not in the disassemblers, was starting to get an RSI just from what I already did.) phoenix/{windows, cocoa, qt} need to be updated to use "string foo" instead of "const string& foo", and after that, the major diffs should be finished. This archive is the first time I'm posting my copy-on-write, size+capacity nall::string class, so any feedback on that is welcome as well.
This commit is contained in:
parent
75dab443b4
commit
29ea5bd599
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Emulator {
|
||||
static const char Name[] = "higan";
|
||||
static const char Version[] = "092.08";
|
||||
static const char Version[] = "092.09";
|
||||
static const char Author[] = "byuu";
|
||||
static const char License[] = "GPLv3";
|
||||
static const char Website[] = "http://byuu.org/";
|
||||
|
|
|
@ -47,9 +47,9 @@ struct Interface {
|
|||
vector<Port> port;
|
||||
|
||||
struct Bind {
|
||||
virtual void loadRequest(unsigned, const string&, const string&) {}
|
||||
virtual void loadRequest(unsigned, const string&) {}
|
||||
virtual void saveRequest(unsigned, const string&) {}
|
||||
virtual void loadRequest(unsigned, string, string) {}
|
||||
virtual void loadRequest(unsigned, string) {}
|
||||
virtual void saveRequest(unsigned, string) {}
|
||||
virtual uint32_t videoColor(unsigned, uint16_t, uint16_t, uint16_t) { return 0u; }
|
||||
virtual void videoRefresh(const uint32_t*, unsigned, unsigned, unsigned) {}
|
||||
virtual void audioSample(int16_t, int16_t) {}
|
||||
|
@ -57,14 +57,14 @@ struct Interface {
|
|||
virtual unsigned dipSettings(const Markup::Node&) { return 0; }
|
||||
virtual string path(unsigned) { return ""; }
|
||||
virtual string server() { return ""; }
|
||||
virtual void notify(const string& text) { print(text, "\n"); }
|
||||
virtual void notify(string text) { print(text, "\n"); }
|
||||
};
|
||||
Bind* bind = nullptr;
|
||||
|
||||
//callback bindings (provided by user interface)
|
||||
void loadRequest(unsigned id, const string& name, const string& type) { return bind->loadRequest(id, name, type); }
|
||||
void loadRequest(unsigned id, const string& path) { return bind->loadRequest(id, path); }
|
||||
void saveRequest(unsigned id, const string& path) { return bind->saveRequest(id, path); }
|
||||
void loadRequest(unsigned id, string name, string type) { return bind->loadRequest(id, name, type); }
|
||||
void loadRequest(unsigned id, string path) { return bind->loadRequest(id, path); }
|
||||
void saveRequest(unsigned id, string path) { return bind->saveRequest(id, path); }
|
||||
uint32_t videoColor(unsigned source, uint16_t red, uint16_t green, uint16_t blue) { return bind->videoColor(source, red, green, blue); }
|
||||
void videoRefresh(const uint32_t* data, unsigned pitch, unsigned width, unsigned height) { return bind->videoRefresh(data, pitch, width, height); }
|
||||
void audioSample(int16_t lsample, int16_t rsample) { return bind->audioSample(lsample, rsample); }
|
||||
|
|
|
@ -9,7 +9,7 @@ void APU::DMC::stop() {
|
|||
length_counter = 0;
|
||||
dma_delay_counter = 0;
|
||||
cpu.set_rdy_line(1);
|
||||
cpu.set_rdy_addr({ false, 0u });
|
||||
cpu.set_rdy_addr(false);
|
||||
}
|
||||
|
||||
uint8 APU::DMC::clock() {
|
||||
|
@ -19,10 +19,10 @@ uint8 APU::DMC::clock() {
|
|||
dma_delay_counter--;
|
||||
|
||||
if(dma_delay_counter == 1) {
|
||||
cpu.set_rdy_addr({ true, uint16(0x8000 | read_addr) });
|
||||
cpu.set_rdy_addr(true, 0x8000 | read_addr);
|
||||
} else if(dma_delay_counter == 0) {
|
||||
cpu.set_rdy_line(1);
|
||||
cpu.set_rdy_addr({ false, 0u });
|
||||
cpu.set_rdy_addr(false);
|
||||
|
||||
dma_buffer = cpu.mdr();
|
||||
have_dma_buffer = true;
|
||||
|
|
|
@ -119,7 +119,7 @@ Board::Board(Markup::Node &document) {
|
|||
Board::~Board() {
|
||||
}
|
||||
|
||||
Board* Board::load(const string &manifest) {
|
||||
Board* Board::load(string manifest) {
|
||||
auto document = Markup::Document(manifest);
|
||||
cartridge.information.title = document["information/title"].text();
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ struct Board {
|
|||
Board(Markup::Node& document);
|
||||
virtual ~Board();
|
||||
|
||||
static Board* load(const string &manifest);
|
||||
static Board* load(string manifest);
|
||||
|
||||
struct Information {
|
||||
string type;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Famicom {
|
|||
|
||||
Cheat cheat;
|
||||
|
||||
bool Cheat::decode(const string &code_, unsigned &addr, unsigned &data, unsigned &comp) {
|
||||
bool Cheat::decode(string code_, unsigned& addr, unsigned& data, unsigned& comp) {
|
||||
static bool initialize = false;
|
||||
static uint8 mapProActionReplay[256], mapGameGenie[256];
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ struct CheatCode {
|
|||
};
|
||||
|
||||
struct Cheat : public vector<CheatCode> {
|
||||
static bool decode(const string &code, unsigned &addr, unsigned &data, unsigned &comp);
|
||||
static bool decode(string code, unsigned& addr, unsigned& data, unsigned& comp);
|
||||
|
||||
void synchronize();
|
||||
bool override[65536];
|
||||
|
|
|
@ -60,7 +60,8 @@ void CPU::reset() {
|
|||
status.irq_apu_line = 0;
|
||||
|
||||
status.rdy_line = 1;
|
||||
status.rdy_addr = { false, 0x0000 };
|
||||
status.rdy_addr_valid = false;
|
||||
status.rdy_addr_value = 0x0000;
|
||||
|
||||
status.oam_dma_pending = false;
|
||||
status.oam_dma_page = 0x00;
|
||||
|
|
|
@ -9,7 +9,8 @@ struct CPU : Processor::R6502, Thread {
|
|||
bool irq_apu_line;
|
||||
|
||||
bool rdy_line;
|
||||
optional<uint16> rdy_addr;
|
||||
bool rdy_addr_valid;
|
||||
uint16 rdy_addr_value;
|
||||
|
||||
bool oam_dma_pending;
|
||||
uint8 oam_dma_page;
|
||||
|
@ -49,7 +50,7 @@ struct CPU : Processor::R6502, Thread {
|
|||
void set_irq_apu_line(bool);
|
||||
|
||||
void set_rdy_line(bool);
|
||||
void set_rdy_addr(optional<uint16>);
|
||||
void set_rdy_addr(bool valid, uint16 value = 0);
|
||||
};
|
||||
|
||||
extern CPU cpu;
|
||||
|
|
|
@ -11,12 +11,8 @@ void CPU::serialize(serializer &s) {
|
|||
s.integer(status.irq_apu_line);
|
||||
|
||||
s.integer(status.rdy_line);
|
||||
bool rdy_addr_valid = status.rdy_addr;
|
||||
unsigned rdy_addr_value = 0;
|
||||
if(rdy_addr_valid) rdy_addr_value = status.rdy_addr();
|
||||
s.integer(rdy_addr_valid);
|
||||
s.integer(rdy_addr_value);
|
||||
if(rdy_addr_valid) status.rdy_addr = rdy_addr_value;
|
||||
s.integer(status.rdy_addr_valid);
|
||||
s.integer(status.rdy_addr_value);
|
||||
|
||||
s.integer(status.oam_dma_pending);
|
||||
s.integer(status.oam_dma_page);
|
||||
|
|
|
@ -6,7 +6,7 @@ uint8 CPU::op_read(uint16 addr) {
|
|||
}
|
||||
|
||||
while(status.rdy_line == 0) {
|
||||
regs.mdr = bus.read(status.rdy_addr ? status.rdy_addr() : addr);
|
||||
regs.mdr = bus.read(status.rdy_addr_valid ? status.rdy_addr_value : addr);
|
||||
add_clocks(12);
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ void CPU::set_rdy_line(bool line) {
|
|||
status.rdy_line = line;
|
||||
}
|
||||
|
||||
void CPU::set_rdy_addr(optional<uint16> addr) {
|
||||
status.rdy_addr = addr;
|
||||
void CPU::set_rdy_addr(bool valid, uint16 value) {
|
||||
status.rdy_addr_valid = valid;
|
||||
status.rdy_addr_value = value;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ struct Input {
|
|||
void power();
|
||||
void reset();
|
||||
|
||||
void serialize(serializer &s);
|
||||
void serialize(serializer&);
|
||||
|
||||
private:
|
||||
Device port1;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
struct Video {
|
||||
unsigned *palette;
|
||||
unsigned* palette = nullptr;
|
||||
void generate_palette();
|
||||
|
||||
Video();
|
||||
|
|
|
@ -20,9 +20,6 @@ void APU::Noise::run() {
|
|||
}
|
||||
|
||||
void APU::Noise::clock_length() {
|
||||
//if(counter && length) {
|
||||
// if(--length == 0) enable = false;
|
||||
//}
|
||||
if(enable && counter) {
|
||||
if(++length == 0) enable = false;
|
||||
}
|
||||
|
@ -38,7 +35,6 @@ void APU::Noise::clock_envelope() {
|
|||
|
||||
void APU::Noise::write(unsigned r, uint8 data) {
|
||||
if(r == 1) { //$ff20 NR41
|
||||
//length = 64 - (data & 0x3f);
|
||||
length = data & 0x3f;
|
||||
}
|
||||
|
||||
|
@ -66,7 +62,6 @@ void APU::Noise::write(unsigned r, uint8 data) {
|
|||
lfsr = ~0U;
|
||||
envelope_period = envelope_frequency;
|
||||
volume = envelope_volume;
|
||||
//if(length == 0) length = 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,6 @@ void APU::Square1::sweep(bool update) {
|
|||
}
|
||||
|
||||
void APU::Square1::clock_length() {
|
||||
//if(counter && length) {
|
||||
// if(--length == 0) enable = false;
|
||||
//}
|
||||
|
||||
if(counter && enable) {
|
||||
if(++length == 0) enable = false;
|
||||
}
|
||||
|
@ -74,7 +70,6 @@ void APU::Square1::write(unsigned r, uint8 data) {
|
|||
|
||||
if(r == 1) { //$ff11 NR11
|
||||
duty = data >> 6;
|
||||
//length = 64 - (data & 0x3f);
|
||||
length = data & 0x3f;
|
||||
}
|
||||
|
||||
|
@ -104,7 +99,6 @@ void APU::Square1::write(unsigned r, uint8 data) {
|
|||
sweep_enable = sweep_period || sweep_shift;
|
||||
sweep_negate = false;
|
||||
if(sweep_shift) sweep(0);
|
||||
//if(length == 0) length = 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,6 @@ void APU::Square2::run() {
|
|||
}
|
||||
|
||||
void APU::Square2::clock_length() {
|
||||
//if(counter && length) {
|
||||
// if(--length == 0) enable = false;
|
||||
//}
|
||||
|
||||
if(counter && enable) {
|
||||
if(++length == 0) enable = false;
|
||||
}
|
||||
|
@ -43,7 +39,6 @@ void APU::Square2::clock_envelope() {
|
|||
void APU::Square2::write(unsigned r, uint8 data) {
|
||||
if(r == 1) { //$ff16 NR21
|
||||
duty = data >> 6;
|
||||
//length = 64 - (data & 0x3f);
|
||||
length = (data & 0x3f);
|
||||
}
|
||||
|
||||
|
@ -68,7 +63,6 @@ void APU::Square2::write(unsigned r, uint8 data) {
|
|||
period = 4 * (2048 - frequency);
|
||||
envelope_period = envelope_frequency;
|
||||
volume = envelope_volume;
|
||||
//if(length == 0) length = 64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,6 @@ void APU::Wave::run() {
|
|||
}
|
||||
|
||||
void APU::Wave::clock_length() {
|
||||
//if(counter && length) {
|
||||
// if(--length == 0) enable = false;
|
||||
//}
|
||||
if(enable && counter) {
|
||||
if(++length == 0) enable = false;
|
||||
}
|
||||
|
@ -28,7 +25,6 @@ void APU::Wave::write(unsigned r, uint8 data) {
|
|||
}
|
||||
|
||||
if(r == 1) { //$ff1b NR31
|
||||
//length = 256 - data;
|
||||
length = data;
|
||||
}
|
||||
|
||||
|
@ -54,7 +50,6 @@ void APU::Wave::write(unsigned r, uint8 data) {
|
|||
enable = dac_enable;
|
||||
period = 2 * (2048 - frequency);
|
||||
pattern_offset = 0;
|
||||
//if(length == 0) length = 256;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace GameBoy {
|
|||
|
||||
Cheat cheat;
|
||||
|
||||
bool Cheat::decode(const string &code_, unsigned &addr, unsigned &data, unsigned &comp) {
|
||||
bool Cheat::decode(string code_, unsigned& addr, unsigned& data, unsigned& comp) {
|
||||
static bool initialize = false;
|
||||
static uint8 mapProActionReplay[256], mapGameGenie[256];
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ struct CheatCode {
|
|||
};
|
||||
|
||||
struct Cheat : public vector<CheatCode> {
|
||||
static bool decode(const string &code, unsigned &addr, unsigned &data, unsigned &comp);
|
||||
static bool decode(string code, unsigned& addr, unsigned& data, unsigned& comp);
|
||||
|
||||
void synchronize();
|
||||
bool override[65536];
|
||||
|
|
|
@ -23,8 +23,8 @@ void Scheduler::init() {
|
|||
|
||||
Scheduler::Scheduler() {
|
||||
exit_reason = ExitReason::UnknownEvent;
|
||||
host_thread = 0;
|
||||
active_thread = 0;
|
||||
host_thread = nullptr;
|
||||
active_thread = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,9 +78,9 @@ struct context {
|
|||
|
||||
for(unsigned n = 0; n < length; n++) {
|
||||
string fn = part[1];
|
||||
fn.replace("n", decimal(n));
|
||||
fn.replace("o", decimal(offset));
|
||||
fn.replace("p", decimal(buffer.size()));
|
||||
fn.replace("n", string{n});
|
||||
fn.replace("o", string{offset});
|
||||
fn.replace("p", string{buffer.size()});
|
||||
buffer.resize(offset + 1);
|
||||
buffer[offset] = eval(fn);
|
||||
offset += stride;
|
||||
|
|
|
@ -53,7 +53,7 @@ struct stream {
|
|||
buffer.resize(size() + 1);
|
||||
buffer[size()] = 0;
|
||||
seek(0);
|
||||
read((uint8_t*)buffer(), size());
|
||||
read((uint8_t*)buffer.data(), size());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
#include <nall/platform.hpp>
|
||||
#include <nall/atoi.hpp>
|
||||
|
@ -22,29 +23,21 @@
|
|||
#include <nall/windows/utf8.hpp>
|
||||
|
||||
#define NALL_STRING_INTERNAL_HPP
|
||||
#include <nall/string/char.hpp>
|
||||
#include <nall/string/base.hpp>
|
||||
#include <nall/string/bsv.hpp>
|
||||
#include <nall/string/ref.hpp>
|
||||
#include <nall/string/cast.hpp>
|
||||
#include <nall/string/compare.hpp>
|
||||
#include <nall/string/convert.hpp>
|
||||
#include <nall/string/core.hpp>
|
||||
#include <nall/string/cstring.hpp>
|
||||
#include <nall/string/datetime.hpp>
|
||||
#include <nall/string/file.hpp>
|
||||
#include <nall/string/filename.hpp>
|
||||
#include <nall/string/format.hpp>
|
||||
#include <nall/string/math-fixed-point.hpp>
|
||||
#include <nall/string/math-floating-point.hpp>
|
||||
#include <nall/string/list.hpp>
|
||||
#include <nall/string/platform.hpp>
|
||||
#include <nall/string/strm.hpp>
|
||||
#include <nall/string/strpos.hpp>
|
||||
#include <nall/string/trim.hpp>
|
||||
#include <nall/string/replace.hpp>
|
||||
#include <nall/string/split.hpp>
|
||||
#include <nall/string/static.hpp>
|
||||
#include <nall/string/utf8.hpp>
|
||||
#include <nall/string/utility.hpp>
|
||||
#include <nall/string/variadic.hpp>
|
||||
#include <nall/string/wildcard.hpp>
|
||||
#include <nall/string/wrapper.hpp>
|
||||
#include <nall/string/markup/node.hpp>
|
||||
#include <nall/string/markup/bml.hpp>
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
struct cstring;
|
||||
|
||||
struct string;
|
||||
struct stringref;
|
||||
struct lstring;
|
||||
template<typename T> inline const char* to_string(T);
|
||||
|
||||
struct cstring {
|
||||
inline operator const char*() const;
|
||||
inline unsigned length() const;
|
||||
inline bool operator==(const char*) const;
|
||||
inline bool operator!=(const char*) const;
|
||||
inline optional<unsigned> position(const char* key) const;
|
||||
inline optional<unsigned> iposition(const char* key) const;
|
||||
inline cstring& operator=(const char* data);
|
||||
inline cstring(const char* data);
|
||||
inline cstring();
|
||||
|
||||
protected:
|
||||
const char* data;
|
||||
};
|
||||
typedef const stringref& rstring;
|
||||
|
||||
struct string {
|
||||
inline static string read(const string& filename);
|
||||
protected:
|
||||
std::shared_ptr<char> _data;
|
||||
unsigned _capacity;
|
||||
unsigned _size;
|
||||
|
||||
inline static string date();
|
||||
inline static string time();
|
||||
inline static string datetime();
|
||||
public:
|
||||
//core.hpp
|
||||
inline char* data();
|
||||
inline const char* data() const;
|
||||
inline unsigned length() const;
|
||||
inline unsigned size() const;
|
||||
inline unsigned capacity() const;
|
||||
inline bool empty() const;
|
||||
|
||||
inline void reset();
|
||||
inline void reserve(unsigned);
|
||||
inline void resize(unsigned);
|
||||
inline void clear(char);
|
||||
inline bool empty() const;
|
||||
|
||||
template<typename... Args> inline string& assign(Args&&... args);
|
||||
template<typename... Args> inline string& append(Args&&... args);
|
||||
|
||||
inline bool readfile(const string&);
|
||||
//file.hpp
|
||||
inline static string read(rstring filename);
|
||||
inline bool readfile(rstring);
|
||||
|
||||
template<unsigned Limit = 0> inline string& replace(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline string& ireplace(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline string& qreplace(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline string& iqreplace(const char*, const char*);
|
||||
//datetime.hpp
|
||||
inline static string date();
|
||||
inline static string time();
|
||||
inline static string datetime();
|
||||
|
||||
inline unsigned length() const;
|
||||
inline unsigned capacity() const;
|
||||
//replace.hpp
|
||||
template<unsigned Limit = 0> inline string& replace(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline string& ireplace(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline string& qreplace(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline string& iqreplace(rstring, rstring);
|
||||
|
||||
template<unsigned Limit = 0> inline lstring split(const char*) const;
|
||||
template<unsigned Limit = 0> inline lstring isplit(const char*) const;
|
||||
template<unsigned Limit = 0> inline lstring qsplit(const char*) const;
|
||||
template<unsigned Limit = 0> inline lstring iqsplit(const char*) const;
|
||||
//wrapper.hpp
|
||||
template<unsigned Limit = 0> inline lstring split(rstring) const;
|
||||
template<unsigned Limit = 0> inline lstring isplit(rstring) const;
|
||||
template<unsigned Limit = 0> inline lstring qsplit(rstring) const;
|
||||
template<unsigned Limit = 0> inline lstring iqsplit(rstring) const;
|
||||
|
||||
inline bool equals(const char*) const;
|
||||
inline bool iequals(const char*) const;
|
||||
inline bool equals(rstring) const;
|
||||
inline bool iequals(rstring) const;
|
||||
|
||||
inline bool wildcard(const char*) const;
|
||||
inline bool iwildcard(const char*) const;
|
||||
inline bool wildcard(rstring) const;
|
||||
inline bool iwildcard(rstring) const;
|
||||
|
||||
inline bool beginswith(const char*) const;
|
||||
inline bool ibeginswith(const char*) const;
|
||||
inline bool endswith(const char*) const;
|
||||
inline bool iendswith(const char*) const;
|
||||
inline bool beginswith(rstring) const;
|
||||
inline bool ibeginswith(rstring) const;
|
||||
inline bool endswith(rstring) const;
|
||||
inline bool iendswith(rstring) const;
|
||||
|
||||
inline string& lower();
|
||||
inline string& upper();
|
||||
inline string& qlower();
|
||||
inline string& qupper();
|
||||
inline string& transform(const char* before, const char* after);
|
||||
inline string& transform(rstring before, rstring after);
|
||||
inline string& reverse();
|
||||
|
||||
template<unsigned limit = 0> inline string& ltrim(const char* key = " ");
|
||||
template<unsigned limit = 0> inline string& rtrim(const char* key = " ");
|
||||
template<unsigned limit = 0> inline string& trim(const char* key = " ", const char* rkey = nullptr);
|
||||
template<unsigned limit = 0> inline string& ltrim(rstring key = " ");
|
||||
template<unsigned limit = 0> inline string& rtrim(rstring key = " ");
|
||||
template<unsigned limit = 0> inline string& trim(rstring key = " ", rstring rkey = "");
|
||||
inline string& strip();
|
||||
|
||||
inline optional<unsigned> position(const char* key) const;
|
||||
inline optional<unsigned> iposition(const char* key) const;
|
||||
inline optional<unsigned> qposition(const char* key) const;
|
||||
inline optional<unsigned> iqposition(const char* key) const;
|
||||
inline optional<unsigned> position(rstring key) const;
|
||||
inline optional<unsigned> iposition(rstring key) const;
|
||||
inline optional<unsigned> qposition(rstring key) const;
|
||||
inline optional<unsigned> iqposition(rstring key) const;
|
||||
|
||||
//core.hpp
|
||||
inline explicit operator bool() const;
|
||||
inline operator const char*() const;
|
||||
inline char* operator()();
|
||||
inline char& operator[](int);
|
||||
inline char& operator[](unsigned);
|
||||
inline const char& operator[](unsigned) const;
|
||||
|
||||
inline bool operator==(const char*) const;
|
||||
inline bool operator!=(const char*) const;
|
||||
|
@ -95,25 +95,23 @@ namespace nall {
|
|||
inline string& operator=(const string&);
|
||||
inline string& operator=(string&&);
|
||||
|
||||
template<typename... Args> inline string(Args&&... args);
|
||||
template<typename T, typename... Args> inline string(T&& source, Args&&... args);
|
||||
inline string();
|
||||
inline string(const string&);
|
||||
inline string(string&&);
|
||||
inline ~string();
|
||||
|
||||
inline char* begin() { return &data[0]; }
|
||||
inline char* end() { return &data[length()]; }
|
||||
inline const char* begin() const { return &data[0]; }
|
||||
inline const char* end() const { return &data[length()]; }
|
||||
inline char* begin() { return &data()[0]; }
|
||||
inline char* end() { return &data()[size()]; }
|
||||
inline const char* begin() const { return &data()[0]; }
|
||||
inline const char* end() const { return &data()[size()]; }
|
||||
|
||||
//internal functions
|
||||
inline string& assign_(const char*);
|
||||
inline string& append_(const char*);
|
||||
|
||||
protected:
|
||||
char* data;
|
||||
unsigned size;
|
||||
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> inline string& ureplace(const char*, const char*);
|
||||
//protected:
|
||||
struct exception_out_of_bounds{};
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> inline string& ureplace(rstring, rstring);
|
||||
inline void _unique();
|
||||
inline void _copy();
|
||||
inline string& _append(const char*);
|
||||
|
||||
#if defined(QSTRING_H)
|
||||
public:
|
||||
|
@ -121,19 +119,15 @@ namespace nall {
|
|||
#endif
|
||||
};
|
||||
|
||||
//list.hpp
|
||||
struct lstring : vector<string> {
|
||||
inline optional<unsigned> find(const char*) const;
|
||||
inline string concatenate(const char*) const;
|
||||
inline optional<unsigned> find(rstring) const;
|
||||
inline string concatenate(const string&) const;
|
||||
inline lstring& isort();
|
||||
inline lstring& strip();
|
||||
inline void append() {}
|
||||
template<typename... Args> inline void append(const string&, Args&&...);
|
||||
|
||||
template<unsigned Limit = 0> inline lstring& split(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline lstring& isplit(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline lstring& qsplit(const char*, const char*);
|
||||
template<unsigned Limit = 0> inline lstring& iqsplit(const char*, const char*);
|
||||
|
||||
inline bool operator==(const lstring&) const;
|
||||
inline bool operator!=(const lstring&) const;
|
||||
|
||||
|
@ -146,25 +140,22 @@ namespace nall {
|
|||
inline lstring(lstring&);
|
||||
inline lstring(lstring&&);
|
||||
|
||||
//split.hpp
|
||||
template<unsigned Limit = 0> inline lstring& split(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline lstring& isplit(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline lstring& qsplit(rstring, rstring);
|
||||
template<unsigned Limit = 0> inline lstring& iqsplit(rstring, rstring);
|
||||
|
||||
protected:
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> inline lstring& usplit(const char*, const char*);
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> inline lstring& usplit(rstring, rstring);
|
||||
};
|
||||
|
||||
//compare.hpp
|
||||
inline char chrlower(char c);
|
||||
inline char chrupper(char c);
|
||||
inline int istrcmp(const char* str1, const char* str2);
|
||||
inline bool strbegin(const char* str, const char* key);
|
||||
inline bool istrbegin(const char* str, const char* key);
|
||||
inline bool strend(const char* str, const char* key);
|
||||
inline bool istrend(const char* str, const char* key);
|
||||
|
||||
//convert.hpp
|
||||
inline char* strlower(char* str);
|
||||
inline char* strupper(char* str);
|
||||
inline char* qstrlower(char* str);
|
||||
inline char* qstrupper(char* str);
|
||||
inline char* strtr(char* dest, const char* before, const char* after);
|
||||
//filename.hpp
|
||||
inline string dir(string name);
|
||||
inline string notdir(string name);
|
||||
inline string parentdir(string name);
|
||||
inline string basename(string name);
|
||||
inline string extension(string name);
|
||||
|
||||
//format.hpp
|
||||
template<signed precision = 0, char padchar = ' '> inline string format(const string& value);
|
||||
|
@ -172,10 +163,6 @@ namespace nall {
|
|||
template<signed precision = 0, char padchar = '0'> inline string octal(uintmax_t value);
|
||||
template<signed precision = 0, char padchar = '0'> inline string binary(uintmax_t value);
|
||||
|
||||
//math.hpp
|
||||
inline bool strint(const char* str, int& result);
|
||||
inline bool strmath(const char* str, int& result);
|
||||
|
||||
//platform.hpp
|
||||
inline string activepath();
|
||||
inline string realpath(const string& name);
|
||||
|
@ -184,50 +171,22 @@ namespace nall {
|
|||
inline string sharedpath();
|
||||
inline string temppath();
|
||||
|
||||
//strm.hpp
|
||||
inline unsigned strmcpy(char* target, const char* source, unsigned length);
|
||||
inline unsigned strmcat(char* target, const char* source, unsigned length);
|
||||
inline bool strccpy(char* target, const char* source, unsigned length);
|
||||
inline bool strccat(char* target, const char* source, unsigned length);
|
||||
inline void strpcpy(char*& target, const char* source, unsigned& length);
|
||||
|
||||
//strpos.hpp
|
||||
inline optional<unsigned> strpos(const char* str, const char* key);
|
||||
inline optional<unsigned> istrpos(const char* str, const char* key);
|
||||
inline optional<unsigned> qstrpos(const char* str, const char* key);
|
||||
inline optional<unsigned> iqstrpos(const char* str, const char* key);
|
||||
template<bool Insensitive = false, bool Quoted = false> inline optional<unsigned> ustrpos(const char* str, const char* key);
|
||||
|
||||
//trim.hpp
|
||||
template<unsigned limit = 0> inline char* ltrim(char* str, const char* key = " ");
|
||||
template<unsigned limit = 0> inline char* rtrim(char* str, const char* key = " ");
|
||||
template<unsigned limit = 0> inline char* trim(char* str, const char* key = " ", const char* rkey = nullptr);
|
||||
inline char* strip(char* s);
|
||||
|
||||
//utility.hpp
|
||||
template<bool Insensitive> alwaysinline bool chrequal(char x, char y);
|
||||
template<bool Quoted, typename T> alwaysinline bool quoteskip(T*& p);
|
||||
template<bool Quoted, typename T> alwaysinline bool quotecopy(char*& t, T*& p);
|
||||
inline string substr(const char* src, unsigned start = 0, unsigned length = ~0u);
|
||||
inline string substr(rstring source, unsigned offset = 0, unsigned length = ~0u);
|
||||
inline string sha256(const uint8_t* data, unsigned size);
|
||||
inline bool tokenize(lstring& list, const char* s, const char* p);
|
||||
|
||||
inline char* integer(char* result, intmax_t value);
|
||||
inline char* decimal(char* result, uintmax_t value);
|
||||
|
||||
//these functions are deprecated, use format() instead:
|
||||
template<unsigned length = 0, char padding = ' '> inline string integer(intmax_t value);
|
||||
template<unsigned length = 0, char padding = ' '> inline string linteger(intmax_t value);
|
||||
template<unsigned length = 0, char padding = ' '> inline string decimal(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = ' '> inline string ldecimal(uintmax_t value);
|
||||
inline unsigned fp(char* str, long double value);
|
||||
inline string fp(long double value);
|
||||
|
||||
//variadic.hpp
|
||||
inline void sprint(string& output);
|
||||
template<typename T, typename... Args> inline void sprint(string& output, const T& value, Args&&... args);
|
||||
template<typename... Args> inline void print(Args&&... args);
|
||||
|
||||
//wildcard.hpp
|
||||
inline bool wildcard(const char* str, const char* pattern);
|
||||
inline bool iwildcard(const char* str, const char* pattern);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
//BSV v1.0 parser
|
||||
//revision 0.02
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct BSV {
|
||||
static inline string decode(const char* input) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
while(*input) {
|
||||
//illegal characters
|
||||
if(*input == '}' ) return "";
|
||||
if(*input == '\r') return "";
|
||||
if(*input == '\n') return "";
|
||||
|
||||
//normal characters
|
||||
if(*input != '{') { output[offset++] = *input++; continue; }
|
||||
|
||||
//entities
|
||||
if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; }
|
||||
if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; }
|
||||
if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; }
|
||||
|
||||
//illegal entities
|
||||
return "";
|
||||
}
|
||||
output[offset] = 0;
|
||||
return output;
|
||||
}
|
||||
|
||||
static inline string encode(const char* input) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
while(*input) {
|
||||
//illegal characters
|
||||
if(*input == '\r') return "";
|
||||
|
||||
if(*input == '\n') {
|
||||
output[offset++] = '{';
|
||||
output[offset++] = 'l';
|
||||
output[offset++] = 'f';
|
||||
output[offset++] = '}';
|
||||
input++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*input == '{') {
|
||||
output[offset++] = '{';
|
||||
output[offset++] = 'l';
|
||||
output[offset++] = 'b';
|
||||
output[offset++] = '}';
|
||||
input++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(*input == '}') {
|
||||
output[offset++] = '{';
|
||||
output[offset++] = 'r';
|
||||
output[offset++] = 'b';
|
||||
output[offset++] = '}';
|
||||
input++;
|
||||
continue;
|
||||
}
|
||||
|
||||
output[offset++] = *input++;
|
||||
}
|
||||
output[offset] = 0;
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -168,18 +168,6 @@ template<> struct stringify<const string&> {
|
|||
stringify(const string& value) : value(value) {}
|
||||
};
|
||||
|
||||
template<> struct stringify<cstring> {
|
||||
const char* value;
|
||||
operator const char*() const { return value; }
|
||||
stringify(const cstring& value) : value(value) {}
|
||||
};
|
||||
|
||||
template<> struct stringify<const cstring&> {
|
||||
const char* value;
|
||||
operator const char*() const { return value; }
|
||||
stringify(const cstring& value) : value(value) {}
|
||||
};
|
||||
|
||||
#if defined(QSTRING_H)
|
||||
|
||||
template<> struct stringify<QString> {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
#include <nall/string/char/base.hpp>
|
||||
#include <nall/string/char/compare.hpp>
|
||||
#include <nall/string/char/convert.hpp>
|
||||
#include <nall/string/char/math-fixed-point.hpp>
|
||||
#include <nall/string/char/math-floating-point.hpp>
|
||||
#include <nall/string/char/strm.hpp>
|
||||
#include <nall/string/char/strpos.hpp>
|
||||
#include <nall/string/char/trim.hpp>
|
||||
#include <nall/string/char/utf8.hpp>
|
||||
#include <nall/string/char/utility.hpp>
|
||||
#include <nall/string/char/wildcard.hpp>
|
||||
|
||||
#endif
|
|
@ -0,0 +1,83 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
//collection of functions to extend libc
|
||||
//none of these functions require nall::string
|
||||
//and thus, require no changes when nall::string is modified
|
||||
|
||||
namespace nall {
|
||||
|
||||
//compare.hpp
|
||||
inline char chrlower(char c);
|
||||
inline char chrupper(char c);
|
||||
inline int imemcmp(const char* str1, const char* str2, unsigned size);
|
||||
inline int istrcmp(const char* str1, const char* str2);
|
||||
inline bool strbegin(const char* str, const char* key);
|
||||
inline bool istrbegin(const char* str, const char* key);
|
||||
inline bool strend(const char* str, const char* key);
|
||||
inline bool istrend(const char* str, const char* key);
|
||||
|
||||
//convert.hpp
|
||||
inline char* strlower(char* str);
|
||||
inline char* strupper(char* str);
|
||||
inline char* qstrlower(char* str);
|
||||
inline char* qstrupper(char* str);
|
||||
inline char* strtr(char* dest, const char* before, const char* after);
|
||||
|
||||
//math-fixed-point.hpp
|
||||
namespace fixedpoint {
|
||||
inline intmax_t eval_integer(const char*& s);
|
||||
inline intmax_t eval(const char*& s, int depth = 0);
|
||||
inline bool eval(const char* s, intmax_t& result);
|
||||
inline intmax_t parse(const char* s);
|
||||
}
|
||||
|
||||
//math-floating-point.hpp
|
||||
namespace floatingpoint {
|
||||
inline double eval_integer(const char*& s);
|
||||
inline double eval(const char*& s, int depth = 0);
|
||||
inline bool eval(const char* s, double& result);
|
||||
inline double parse(const char* s);
|
||||
}
|
||||
|
||||
//strm.hpp
|
||||
inline unsigned strmcpy(char* target, const char* source, unsigned length);
|
||||
inline unsigned strmcat(char* target, const char* source, unsigned length);
|
||||
inline bool strccpy(char* target, const char* source, unsigned length);
|
||||
inline bool strccat(char* target, const char* source, unsigned length);
|
||||
inline void strpcpy(char*& target, const char* source, unsigned& length);
|
||||
|
||||
//strpos.hpp
|
||||
inline optional<unsigned> strpos(const char* str, const char* key);
|
||||
inline optional<unsigned> istrpos(const char* str, const char* key);
|
||||
inline optional<unsigned> qstrpos(const char* str, const char* key);
|
||||
inline optional<unsigned> iqstrpos(const char* str, const char* key);
|
||||
template<bool Insensitive = false, bool Quoted = false> inline optional<unsigned> ustrpos(const char* str, const char* key);
|
||||
|
||||
//trim.hpp
|
||||
template<unsigned Limit = 0> inline char* ltrim(char* str, const char* key = " ");
|
||||
template<unsigned Limit = 0> inline char* rtrim(char* str, const char* key = " ");
|
||||
template<unsigned Limit = 0> inline char* trim(char* str, const char* key = " ", const char* rkey = nullptr);
|
||||
inline char* strip(char* s);
|
||||
|
||||
//utf8.hpp
|
||||
struct UTF8 {
|
||||
unsigned size; //size of encoded codepoint
|
||||
uint64_t data; //encoded codepoint
|
||||
unsigned codepoint; //decoded codepoint
|
||||
};
|
||||
inline UTF8 utf8_read(const char* s);
|
||||
inline void utf8_write(char* s, const UTF8& utf8);
|
||||
|
||||
//utility.hpp
|
||||
template<bool Insensitive> alwaysinline bool chrequal(char x, char y);
|
||||
template<bool Quoted, typename T> alwaysinline bool quoteskip(T*& p);
|
||||
template<bool Quoted, typename T> alwaysinline bool quotecopy(char*& t, T*& p);
|
||||
|
||||
//wildcard.hpp
|
||||
inline bool wildcard(const char* str, const char* pattern);
|
||||
inline bool iwildcard(const char* str, const char* pattern);
|
||||
inline bool tokenize(const char* s, const char* p);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,6 +10,14 @@ char chrupper(char c) {
|
|||
return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c;
|
||||
}
|
||||
|
||||
int imemcmp(const char* str1, const char* str2, unsigned size) {
|
||||
while(size--) {
|
||||
if(chrlower(*str1) != chrlower(*str2)) break;
|
||||
str1++, str2++;
|
||||
}
|
||||
return (int)chrlower(*str1) - (int)chrlower(*str2);
|
||||
}
|
||||
|
||||
int istrcmp(const char* str1, const char* str2) {
|
||||
while(*str1) {
|
||||
if(chrlower(*str1) != chrlower(*str2)) break;
|
||||
|
@ -19,6 +27,7 @@ int istrcmp(const char* str1, const char* str2) {
|
|||
}
|
||||
|
||||
bool strbegin(const char* str, const char* key) {
|
||||
if(!str || !key) return false;
|
||||
int i, ssl = strlen(str), ksl = strlen(key);
|
||||
|
||||
if(ksl > ssl) return false;
|
||||
|
@ -26,6 +35,7 @@ bool strbegin(const char* str, const char* key) {
|
|||
}
|
||||
|
||||
bool istrbegin(const char* str, const char* key) {
|
||||
if(!str || !key) return false;
|
||||
int ssl = strlen(str), ksl = strlen(key);
|
||||
|
||||
if(ksl > ssl) return false;
|
||||
|
@ -42,6 +52,7 @@ bool istrbegin(const char* str, const char* key) {
|
|||
}
|
||||
|
||||
bool strend(const char* str, const char* key) {
|
||||
if(!str || !key) return false;
|
||||
int ssl = strlen(str), ksl = strlen(key);
|
||||
|
||||
if(ksl > ssl) return false;
|
||||
|
@ -49,6 +60,7 @@ bool strend(const char* str, const char* key) {
|
|||
}
|
||||
|
||||
bool istrend(const char* str, const char* key) {
|
||||
if(!str || !key) return false;
|
||||
int ssl = strlen(str), ksl = strlen(key);
|
||||
|
||||
if(ksl > ssl) return false;
|
10
higan/nall/string/math-fixed-point.hpp → higan/nall/string/char/math-fixed-point.hpp
Executable file → Normal file
10
higan/nall/string/math-fixed-point.hpp → higan/nall/string/char/math-fixed-point.hpp
Executable file → Normal file
|
@ -1,10 +1,11 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
namespace fixedpoint {
|
||||
|
||||
static nall::function<intmax_t (const char*&)> eval_fallback;
|
||||
|
||||
static intmax_t eval_integer(const char*& s) {
|
||||
intmax_t eval_integer(const char*& s) {
|
||||
if(!*s) throw "unrecognized integer";
|
||||
intmax_t value = 0, x = *s, y = *(s + 1);
|
||||
|
||||
|
@ -58,7 +59,7 @@ static intmax_t eval_integer(const char*& s) {
|
|||
throw "unrecognized integer";
|
||||
}
|
||||
|
||||
static intmax_t eval(const char*& s, int depth = 0) {
|
||||
intmax_t eval(const char*& s, int depth) {
|
||||
while(*s == ' ' || *s == '\t') s++; //trim whitespace
|
||||
if(!*s) throw "unrecognized token";
|
||||
intmax_t value = 0, x = *s, y = *(s + 1);
|
||||
|
@ -142,7 +143,7 @@ static intmax_t eval(const char*& s, int depth = 0) {
|
|||
return value;
|
||||
}
|
||||
|
||||
static bool eval(const char* s, intmax_t &result) {
|
||||
bool eval(const char* s, intmax_t& result) {
|
||||
try {
|
||||
result = eval(s);
|
||||
return true;
|
||||
|
@ -152,7 +153,7 @@ static bool eval(const char* s, intmax_t &result) {
|
|||
}
|
||||
}
|
||||
|
||||
static intmax_t parse(const char* s) {
|
||||
intmax_t parse(const char* s) {
|
||||
try {
|
||||
intmax_t result = eval(s);
|
||||
return result;
|
||||
|
@ -161,6 +162,7 @@ static intmax_t parse(const char* s) {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
15
higan/nall/string/math-floating-point.hpp → higan/nall/string/char/math-floating-point.hpp
Executable file → Normal file
15
higan/nall/string/math-floating-point.hpp → higan/nall/string/char/math-floating-point.hpp
Executable file → Normal file
|
@ -1,10 +1,11 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
namespace floatingpoint {
|
||||
|
||||
static nall::function<double (const char*&)> eval_fallback;
|
||||
|
||||
static double eval_integer(const char*& s) {
|
||||
double eval_integer(const char*& s) {
|
||||
if(!*s) throw "unrecognized integer";
|
||||
intmax_t value = 0, radix = 0, x = *s, y = *(s + 1);
|
||||
|
||||
|
@ -45,9 +46,10 @@ static double eval_integer(const char*& s) {
|
|||
return value;
|
||||
}
|
||||
//floating-point
|
||||
unsigned divisor = 1;
|
||||
while(true) {
|
||||
if(*s >= '0' && *s <= '9') { radix = radix * 10 + (*s++ - '0'); continue; }
|
||||
return atof(nall::string{ nall::decimal(value), ".", nall::decimal(radix) });
|
||||
if(*s >= '0' && *s <= '9') { radix = radix * 10 + (*s++ - '0'); divisor *= 10; continue; }
|
||||
return (double)value + (double)radix / (double)divisor;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +66,7 @@ static double eval_integer(const char*& s) {
|
|||
throw "unrecognized integer";
|
||||
}
|
||||
|
||||
static double eval(const char*& s, int depth = 0) {
|
||||
double eval(const char*& s, int depth) {
|
||||
while(*s == ' ' || *s == '\t') s++; //trim whitespace
|
||||
if(!*s) throw "unrecognized token";
|
||||
double value = 0, x = *s, y = *(s + 1);
|
||||
|
@ -133,7 +135,7 @@ static double eval(const char*& s, int depth = 0) {
|
|||
return value;
|
||||
}
|
||||
|
||||
static bool eval(const char* s, double& result) {
|
||||
bool eval(const char* s, double& result) {
|
||||
try {
|
||||
result = eval(s);
|
||||
return true;
|
||||
|
@ -143,7 +145,7 @@ static bool eval(const char* s, double& result) {
|
|||
}
|
||||
}
|
||||
|
||||
static double parse(const char* s) {
|
||||
double parse(const char* s) {
|
||||
try {
|
||||
double result = eval(s);
|
||||
return result;
|
||||
|
@ -152,6 +154,7 @@ static double parse(const char* s) {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,8 +4,8 @@ namespace nall {
|
|||
|
||||
//limit defaults to zero, which will underflow on first compare; equivalent to no limit
|
||||
template<unsigned Limit> char* ltrim(char* str, const char* key) {
|
||||
if(!str || !key || !*key) return str;
|
||||
unsigned limit = Limit;
|
||||
if(!key || !*key) return str;
|
||||
while(strbegin(str, key)) {
|
||||
char* dest = str;
|
||||
char* src = str + strlen(key);
|
||||
|
@ -20,8 +20,8 @@ template<unsigned Limit> char* ltrim(char* str, const char* key) {
|
|||
}
|
||||
|
||||
template<unsigned Limit> char* rtrim(char* str, const char* key) {
|
||||
if(!str || !key || !*key) return str;
|
||||
unsigned limit = Limit;
|
||||
if(!key || !*key) return str;
|
||||
while(strend(str, key)) {
|
||||
str[strlen(str) - strlen(key)] = 0;
|
||||
if(--limit == 0) break;
|
||||
|
@ -36,6 +36,8 @@ template<unsigned limit> char* trim(char* str, const char* key, const char* rkey
|
|||
|
||||
//remove whitespace characters from both left and right sides of string
|
||||
char* strip(char* s) {
|
||||
if(!s) return nullptr;
|
||||
|
||||
signed n = 0, p = 0;
|
||||
while(s[n]) {
|
||||
if(s[n] != ' ' && s[n] != '\t' && s[n] != '\r' && s[n] != '\n') break;
|
||||
|
@ -48,6 +50,7 @@ char* strip(char* s) {
|
|||
p--;
|
||||
}
|
||||
s[++p] = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -2,13 +2,7 @@
|
|||
|
||||
namespace nall {
|
||||
|
||||
struct UTF8 {
|
||||
unsigned size; //size of encoded codepoint
|
||||
uint64_t data; //encoded codepoint
|
||||
unsigned codepoint; //decoded codepoint
|
||||
};
|
||||
|
||||
inline UTF8 utf8_read(const char* s) {
|
||||
UTF8 utf8_read(const char* s) {
|
||||
UTF8 utf8;
|
||||
|
||||
if((*s & 0xfe) == 0xfc) utf8.size = 6;
|
||||
|
@ -32,7 +26,7 @@ inline UTF8 utf8_read(const char* s) {
|
|||
return utf8;
|
||||
}
|
||||
|
||||
inline void utf8_write(char* s, const UTF8& utf8) {
|
||||
void utf8_write(char* s, const UTF8& utf8) {
|
||||
for(signed n = utf8.size - 1, shift = 0; n >= 0; n--, shift += 8) {
|
||||
s[n] = utf8.data >> shift;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<bool Insensitive>
|
||||
bool chrequal(char x, char y) {
|
||||
if(Insensitive) return chrlower(x) == chrlower(y);
|
||||
return x == y;
|
||||
}
|
||||
|
||||
template<bool Quoted, typename T>
|
||||
bool quoteskip(T*& p) {
|
||||
if(Quoted == false) return false;
|
||||
if(*p != '\'' && *p != '\"') return false;
|
||||
|
||||
while(*p == '\'' || *p == '\"') {
|
||||
char x = *p++;
|
||||
while(*p && *p++ != x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<bool Quoted, typename T>
|
||||
bool quotecopy(char*& t, T*& p) {
|
||||
if(Quoted == false) return false;
|
||||
if(*p != '\'' && *p != '\"') return false;
|
||||
|
||||
while(*p == '\'' || *p == '\"') {
|
||||
char x = *p++;
|
||||
*t++ = x;
|
||||
while(*p && *p != x) *t++ = *p++;
|
||||
*t++ = *p++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
21
higan/nall/string/wildcard.hpp → higan/nall/string/char/wildcard.hpp
Executable file → Normal file
21
higan/nall/string/wildcard.hpp → higan/nall/string/char/wildcard.hpp
Executable file → Normal file
|
@ -44,7 +44,7 @@ bool iwildcard(const char* s, const char* p) {
|
|||
return !*p;
|
||||
}
|
||||
|
||||
inline bool tokenize(const char* s, const char* p) {
|
||||
bool tokenize(const char* s, const char* p) {
|
||||
while(*s) {
|
||||
if(*p == '*') {
|
||||
while(*s) if(tokenize(s++, p + 1)) return true;
|
||||
|
@ -56,25 +56,6 @@ inline bool tokenize(const char* s, const char* p) {
|
|||
return !*p;
|
||||
}
|
||||
|
||||
inline bool tokenize(lstring &list, const char* s, const char* p) {
|
||||
while(*s) {
|
||||
if(*p == '*') {
|
||||
const char* b = s;
|
||||
while(*s) {
|
||||
if(tokenize(list, s++, p + 1)) {
|
||||
list.prepend(substr(b, 0, --s - b));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
list.prepend(b);
|
||||
return !*++p;
|
||||
}
|
||||
if(*s++ != *p++) return false;
|
||||
}
|
||||
while(*p == '*') { list.prepend(s); p++; }
|
||||
return !*p;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,62 +1,74 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
//core functionality
|
||||
//only this header file may access _data, _size, _capacity directly
|
||||
//all other headers must use data(), size(), capacity()
|
||||
|
||||
namespace nall {
|
||||
|
||||
static void istring(string &output) {
|
||||
char* string::data() { _unique(); return _data.get(); }
|
||||
const char* string::data() const { if(!_data) return ""; return _data.get(); }
|
||||
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; }
|
||||
|
||||
//ensure _data is unique
|
||||
void string::_unique() {
|
||||
if(_data.unique()) return;
|
||||
_copy();
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
static void istring(string& output, const T& value, Args&&... args) {
|
||||
output.append_(make_string(value));
|
||||
istring(output, std::forward<Args>(args)...);
|
||||
//copy _data (to make unique or to grow in size)
|
||||
void string::_copy() {
|
||||
auto copy = new char[_capacity + 1];
|
||||
if(_data.get()) memcpy(copy, _data.get(), min(_capacity, _size));
|
||||
copy[_size] = 0;
|
||||
copy[_capacity] = 0;
|
||||
_data.reset(copy);
|
||||
}
|
||||
|
||||
//amortize growth to O(log n)
|
||||
//allocate one extra byte to always store null-terminator for libc usage
|
||||
void string::reserve(unsigned capacity) {
|
||||
if(capacity > _capacity) {
|
||||
_capacity = bit::round(capacity + 1) - 1;
|
||||
_copy();
|
||||
}
|
||||
}
|
||||
|
||||
void string::resize(unsigned size) {
|
||||
reserve(size);
|
||||
data()[_size = size] = 0;
|
||||
}
|
||||
|
||||
void string::reset() {
|
||||
resize(64);
|
||||
*data = 0;
|
||||
}
|
||||
|
||||
void string::reserve(unsigned size_) {
|
||||
if(size_ > size) resize(size_);
|
||||
}
|
||||
|
||||
void string::resize(unsigned size_) {
|
||||
size = size_;
|
||||
data = (char*)realloc(data, size + 1);
|
||||
data[size] = 0;
|
||||
_data.reset();
|
||||
_capacity = 0;
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
void string::clear(char c) {
|
||||
for(unsigned n = 0; n < size; n++) data[n] = c;
|
||||
data[size] = 0;
|
||||
}
|
||||
|
||||
bool string::empty() const {
|
||||
return !*data;
|
||||
for(unsigned n = 0; n < size(); n++) data()[n] = c;
|
||||
}
|
||||
|
||||
template<typename... Args> string& string::assign(Args&&... args) {
|
||||
*data = 0;
|
||||
istring(*this, std::forward<Args>(args)...);
|
||||
reset();
|
||||
sprint(*this, std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> string& string::append(Args&&... args) {
|
||||
istring(*this, std::forward<Args>(args)...);
|
||||
sprint(*this, std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::assign_(const char* s) {
|
||||
unsigned length = strlen(s);
|
||||
reserve(length);
|
||||
strcpy(data, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::append_(const char* s) {
|
||||
unsigned length = strlen(data) + strlen(s);
|
||||
reserve(length);
|
||||
strcat(data, s);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -65,164 +77,64 @@ string::operator bool() const {
|
|||
}
|
||||
|
||||
string::operator const char*() const {
|
||||
return data;
|
||||
return data();
|
||||
}
|
||||
|
||||
char* string::operator()() {
|
||||
return data;
|
||||
char& string::operator[](unsigned position) {
|
||||
if(position > size() + 1) throw exception_out_of_bounds{};
|
||||
return data()[position];
|
||||
}
|
||||
|
||||
char& string::operator[](int index) {
|
||||
reserve(index);
|
||||
return data[index];
|
||||
const char& string::operator[](unsigned 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; }
|
||||
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::operator=(const string& value) {
|
||||
if(&value == this) return *this;
|
||||
assign(value);
|
||||
string& string::operator=(const string& source) {
|
||||
if(&source == this) return *this;
|
||||
_data = source._data;
|
||||
_capacity = source._capacity;
|
||||
_size = source._size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::operator=(string&& source) {
|
||||
if(&source == this) return *this;
|
||||
if(data) free(data);
|
||||
size = source.size;
|
||||
data = source.data;
|
||||
source.data = nullptr;
|
||||
source.size = 0;
|
||||
_data = std::move(source._data);
|
||||
_capacity = source._capacity;
|
||||
_size = source._size;
|
||||
source._capacity = 0;
|
||||
source._size = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> string::string(Args&&... args) {
|
||||
size = 64;
|
||||
data = (char*)malloc(size + 1);
|
||||
*data = 0;
|
||||
istring(*this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
string::string(const string& value) {
|
||||
if(&value == this) return;
|
||||
size = strlen(value);
|
||||
data = strdup(value);
|
||||
string::string(const string& source) {
|
||||
operator=(source);
|
||||
}
|
||||
|
||||
string::string(string&& source) {
|
||||
if(&source == this) return;
|
||||
size = source.size;
|
||||
data = source.data;
|
||||
source.data = nullptr;
|
||||
operator=(std::move(source));
|
||||
}
|
||||
|
||||
template<typename T, typename... Args> string::string(T&& source, Args&&... args) {
|
||||
_capacity = 0;
|
||||
_size = 0;
|
||||
sprint(*this, std::forward<T>(source), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
string::string() {
|
||||
_capacity = 0;
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
string::~string() {
|
||||
if(data) free(data);
|
||||
}
|
||||
|
||||
bool string::readfile(const string& filename) {
|
||||
assign("");
|
||||
|
||||
#if !defined(_WIN32)
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
#else
|
||||
FILE *fp = _wfopen(utf16_t(filename), L"rb");
|
||||
#endif
|
||||
if(!fp) return false;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
unsigned size = ftell(fp);
|
||||
rewind(fp);
|
||||
char *fdata = new char[size + 1];
|
||||
unsigned unused = fread(fdata, 1, size, fp);
|
||||
fclose(fp);
|
||||
fdata[size] = 0;
|
||||
assign(fdata);
|
||||
delete[] fdata;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
optional<unsigned> lstring::find(const char* key) const {
|
||||
for(unsigned i = 0; i < size(); i++) {
|
||||
if(operator[](i) == key) return { true, i };
|
||||
}
|
||||
return { false, 0 };
|
||||
}
|
||||
|
||||
string lstring::concatenate(const char* separator) const {
|
||||
string output;
|
||||
for(unsigned i = 0; i < size(); i++) {
|
||||
output.append(operator[](i), i < size() - 1 ? separator : "");
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
lstring& lstring::isort() {
|
||||
nall::sort(pool, objectsize, [](const string& x, const string& y) {
|
||||
return istrcmp(x, y) < 0;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::strip() {
|
||||
for(unsigned n = 0; n < size(); n++) {
|
||||
operator[](n).strip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> void lstring::append(const string& data, Args&&... args) {
|
||||
vector::append(data);
|
||||
append(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool lstring::operator==(const lstring& source) const {
|
||||
if(this == &source) return true;
|
||||
if(size() != source.size()) return false;
|
||||
for(unsigned n = 0; n < size(); n++) {
|
||||
if(operator[](n) != source[n]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lstring::operator!=(const lstring& source) const {
|
||||
return !operator==(source);
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(const lstring& source) {
|
||||
vector::operator=(source);
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(lstring& source) {
|
||||
vector::operator=(source);
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(lstring&& source) {
|
||||
vector::operator=(std::move(source));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> lstring::lstring(Args&&... args) {
|
||||
append(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
lstring::lstring(const lstring& source) {
|
||||
vector::operator=(source);
|
||||
}
|
||||
|
||||
lstring::lstring(lstring& source) {
|
||||
vector::operator=(source);
|
||||
}
|
||||
|
||||
lstring::lstring(lstring&& source) {
|
||||
vector::operator=(std::move(source));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
//const string:
|
||||
//bind a const char* pointer to an object that has various testing functionality;
|
||||
//yet lacks the memory allocation and modification functionality of the string class
|
||||
|
||||
namespace nall {
|
||||
|
||||
cstring::operator const char*() const { return data; }
|
||||
unsigned cstring::length() const { return strlen(data); }
|
||||
bool cstring::operator==(const char* s) const { return !strcmp(data, s); }
|
||||
bool cstring::operator!=(const char* s) const { return strcmp(data, s); }
|
||||
optional<unsigned> cstring::position (const char* key) const { return strpos(data, key); }
|
||||
optional<unsigned> cstring::iposition(const char* key) const { return istrpos(data, key); }
|
||||
cstring& cstring::operator=(const char* data) { this->data = data; return *this; }
|
||||
cstring::cstring(const char* data) : data(data) {}
|
||||
cstring::cstring() : data("") {}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -6,9 +6,9 @@ string string::date() {
|
|||
time_t timestamp = ::time(nullptr);
|
||||
tm* info = localtime(×tamp);
|
||||
return {
|
||||
decimal<4, '0'>(1900 + info->tm_year), "-",
|
||||
decimal<2, '0'>(1 + info->tm_mon), "-",
|
||||
decimal<2, '0'>(info->tm_mday)
|
||||
format<4, '0'>(1900 + info->tm_year), "-",
|
||||
format<2, '0'>(1 + info->tm_mon), "-",
|
||||
format<2, '0'>(info->tm_mday)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,9 @@ string string::time() {
|
|||
time_t timestamp = ::time(nullptr);
|
||||
tm* info = localtime(×tamp);
|
||||
return {
|
||||
decimal<2, '0'>(info->tm_hour), ":",
|
||||
decimal<2, '0'>(info->tm_min), ":",
|
||||
decimal<2, '0'>(info->tm_sec)
|
||||
format<2, '0'>(info->tm_hour), ":",
|
||||
format<2, '0'>(info->tm_min), ":",
|
||||
format<2, '0'>(info->tm_sec)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
bool string::readfile(rstring filename) {
|
||||
reset();
|
||||
|
||||
#if !defined(_WIN32)
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
#else
|
||||
FILE* fp = _wfopen(utf16_t(filename), L"rb");
|
||||
#endif
|
||||
if(!fp) return false;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
unsigned fsize = ftell(fp);
|
||||
rewind(fp);
|
||||
char *fdata = new char[fsize + 1];
|
||||
unsigned unused = fread(fdata, 1, fsize, fp);
|
||||
fclose(fp);
|
||||
fdata[fsize] = 0;
|
||||
resize(fsize);
|
||||
memcpy(data(), fdata, fsize);
|
||||
delete[] fdata;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string string::read(rstring filename) {
|
||||
string data;
|
||||
data.readfile(filename);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@ namespace nall {
|
|||
// "/foo/bar.c" -> "/foo/"
|
||||
// "/foo/" -> "/foo/"
|
||||
// "bar.c" -> "./"
|
||||
inline string dir(string name) {
|
||||
string dir(string name) {
|
||||
for(signed i = name.length(); i >= 0; i--) {
|
||||
if(name[i] == '/' || name[i] == '\\') {
|
||||
name[i + 1] = 0;
|
||||
|
@ -19,7 +19,7 @@ inline string dir(string name) {
|
|||
// "/foo/bar.c" -> "bar.c"
|
||||
// "/foo/" -> ""
|
||||
// "bar.c" -> "bar.c"
|
||||
inline string notdir(string name) {
|
||||
string notdir(string name) {
|
||||
for(signed i = name.length(); i >= 0; i--) {
|
||||
if(name[i] == '/' || name[i] == '\\') {
|
||||
return (const char*)name + i + 1;
|
||||
|
@ -31,7 +31,7 @@ inline string notdir(string name) {
|
|||
// "/foo/bar/baz" -> "/foo/bar/"
|
||||
// "/foo/bar/" -> "/foo/"
|
||||
// "/foo/bar" -> "/foo/"
|
||||
inline string parentdir(string name) {
|
||||
string parentdir(string name) {
|
||||
unsigned length = name.length(), paths = 0, prev, last;
|
||||
for(unsigned i = 0; i < length; i++) {
|
||||
if(name[i] == '/' || name[i] == '\\') {
|
||||
|
@ -46,7 +46,7 @@ inline string parentdir(string name) {
|
|||
}
|
||||
|
||||
// "/foo/bar.c" -> "/foo/bar"
|
||||
inline string basename(string name) {
|
||||
string basename(string name) {
|
||||
for(signed i = name.length(); i >= 0; i--) {
|
||||
if(name[i] == '/' || name[i] == '\\') break; //file has no extension
|
||||
if(name[i] == '.') {
|
||||
|
@ -59,7 +59,7 @@ inline string basename(string name) {
|
|||
|
||||
// "/foo/bar.c" -> "c"
|
||||
// "/foo/bar" -> ""
|
||||
inline string extension(string name) {
|
||||
string extension(string name) {
|
||||
for(signed i = name.length(); i >= 0; i--) {
|
||||
if(name[i] == '/' || name[i] == '\\') return ""; //file has no extension
|
||||
if(name[i] == '.') {
|
||||
|
|
|
@ -8,9 +8,8 @@ template<signed precision, char padchar> string format(const string& value) {
|
|||
bool padright = precision >= 0;
|
||||
unsigned padding = abs(precision);
|
||||
|
||||
unsigned length = value.length();
|
||||
if(padding <= length) {
|
||||
if(padright) return substr(value, length - padding);
|
||||
if(padding <= value.size()) {
|
||||
if(padright) return substr(value, value.size() - padding);
|
||||
else return substr(value, 0, padding);
|
||||
}
|
||||
|
||||
|
@ -18,7 +17,7 @@ template<signed precision, char padchar> string format(const string& value) {
|
|||
buffer.resize(padding);
|
||||
buffer.clear(padchar);
|
||||
|
||||
memcpy(buffer() + (padright ? padding - length : 0), value, length);
|
||||
memcpy(buffer.data() + (padright ? padding - value.size() : 0), value, value.size());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
optional<unsigned> lstring::find(rstring key) const {
|
||||
for(unsigned i = 0; i < size(); i++) {
|
||||
if(operator[](i) == key) return {true, i};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string lstring::concatenate(const string& separator) const {
|
||||
string output;
|
||||
for(unsigned i = 0; i < size(); i++) {
|
||||
output.append(operator[](i));
|
||||
if(i < size() - 1) output.append(separator);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
lstring& lstring::isort() {
|
||||
nall::sort(pool, objectsize, [](const string& x, const string& y) {
|
||||
return istrcmp(x, y) < 0;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::strip() {
|
||||
for(unsigned n = 0; n < size(); n++) {
|
||||
operator[](n).strip();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> void lstring::append(const string& data, Args&&... args) {
|
||||
vector::append(data);
|
||||
append(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool lstring::operator==(const lstring& source) const {
|
||||
if(this == &source) return true;
|
||||
if(size() != source.size()) return false;
|
||||
for(unsigned n = 0; n < size(); n++) {
|
||||
if(operator[](n) != source[n]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lstring::operator!=(const lstring& source) const {
|
||||
return !operator==(source);
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(const lstring& source) {
|
||||
vector::operator=(source);
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(lstring& source) {
|
||||
vector::operator=(source);
|
||||
return *this;
|
||||
}
|
||||
|
||||
lstring& lstring::operator=(lstring&& source) {
|
||||
vector::operator=(std::move(source));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> lstring::lstring(Args&&... args) {
|
||||
append(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
lstring::lstring(const lstring& source) {
|
||||
vector::operator=(source);
|
||||
}
|
||||
|
||||
lstring::lstring(lstring& source) {
|
||||
vector::operator=(source);
|
||||
}
|
||||
|
||||
lstring::lstring(lstring&& source) {
|
||||
vector::operator=(std::move(source));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -107,10 +107,9 @@ protected:
|
|||
|
||||
//remove empty lines and comment lines
|
||||
for(unsigned y = 0; y < text.size();) {
|
||||
text[y].rtrim<1>("\n");
|
||||
unsigned x = 0;
|
||||
bool empty = true;
|
||||
while(text[y][x]) {
|
||||
while(x < text[y].size()) {
|
||||
if(text[y][x] == ' ' || text[y][x] == '\t') { x++; continue; }
|
||||
empty = (text[y][x + 0] == '/' && text[y][x + 1] == '/');
|
||||
break;
|
||||
|
|
|
@ -44,7 +44,7 @@ protected:
|
|||
return;
|
||||
#endif
|
||||
|
||||
char* output = target();
|
||||
char* output = target.data();
|
||||
while(length) {
|
||||
if(*source == '&') {
|
||||
if(!memcmp(source, "<", 4)) { *output++ = '<'; source += 4; length -= 4; continue; }
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct stringref {
|
||||
operator const char*() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
const char* data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
unsigned size() const {
|
||||
if(!_initialized) {
|
||||
_size = strlen(_data);
|
||||
_initialized = 1;
|
||||
}
|
||||
return _size;
|
||||
}
|
||||
|
||||
stringref() = delete;
|
||||
stringref(const stringref& source) = delete;
|
||||
stringref(stringref&& source) = delete;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
stringref(T&& source, Args&&... args) {
|
||||
if(sizeof...(Args) == 0) { construct(std::forward<T>(source)); _string = nullptr; return; }
|
||||
_string = new string(std::forward<T>(source), std::forward<Args>(args)...);
|
||||
_data = _string->data();
|
||||
_size = _string->size();
|
||||
_initialized = 1;
|
||||
}
|
||||
|
||||
~stringref() {
|
||||
if(_string) delete _string;
|
||||
}
|
||||
|
||||
protected:
|
||||
const char* _data;
|
||||
string* _string;
|
||||
mutable unsigned _size;
|
||||
mutable bool _initialized;
|
||||
|
||||
template<int size>
|
||||
void construct(const char (&source)[size]) {
|
||||
_data = source;
|
||||
_size = size - 1;
|
||||
_initialized = 1;
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<std::is_same<T, char>::value>::type>
|
||||
void construct(const T* source) {
|
||||
_data = source;
|
||||
_size = 0;
|
||||
_initialized = 0;
|
||||
}
|
||||
|
||||
template<typename T, typename = typename std::enable_if<std::is_same<T, string>::value>::type>
|
||||
void construct(const T& source) {
|
||||
_data = source.data();
|
||||
_size = source.size();
|
||||
_initialized = 1;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -3,49 +3,52 @@
|
|||
namespace nall {
|
||||
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted>
|
||||
string& string::ureplace(const char* key, const char* token) {
|
||||
if(!key || !*key) return *this;
|
||||
string& string::ureplace(rstring key, rstring token) {
|
||||
if(key.size() == 0) return *this;
|
||||
enum : unsigned { limit = Limit ? Limit : ~0u };
|
||||
|
||||
const char* p = data;
|
||||
unsigned counter = 0, keyLength = 0;
|
||||
const char* p = data();
|
||||
unsigned counter = 0;
|
||||
|
||||
while(*p) {
|
||||
if(quoteskip<Quoted>(p)) continue;
|
||||
for(unsigned n = 0;; n++) {
|
||||
if(key[n] == 0) { counter++; p += n; keyLength = n; break; }
|
||||
if(key[n] == 0) { counter++; p += n; break; }
|
||||
if(!chrequal<Insensitive>(key[n], p[n])) { p++; break; }
|
||||
}
|
||||
}
|
||||
if(counter == 0) return *this;
|
||||
if(Limit) counter = min(counter, Limit);
|
||||
|
||||
char* t = data;
|
||||
char* base;
|
||||
unsigned tokenLength = strlen(token);
|
||||
if(tokenLength > keyLength) {
|
||||
t = base = strdup(data);
|
||||
reserve((unsigned)(p - data) + ((tokenLength - keyLength) * counter));
|
||||
char* t = data();
|
||||
char* base = nullptr;
|
||||
signed displacement = token.size() - key.size();
|
||||
signed displacementSize = displacement * counter;
|
||||
|
||||
if(token.size() > key.size()) {
|
||||
t = base = strdup(data());
|
||||
reserve((unsigned)(p - data()) + displacementSize);
|
||||
}
|
||||
char* o = data;
|
||||
char* o = data();
|
||||
|
||||
while(*t && counter) {
|
||||
if(quotecopy<Quoted>(o, t)) continue;
|
||||
for(unsigned n = 0;; n++) {
|
||||
if(key[n] == 0) { counter--; memcpy(o, token, tokenLength); t += keyLength; o += tokenLength; break; }
|
||||
if(key[n] == 0) { counter--; memcpy(o, token, token.size()); t += key.size(); o += token.size(); break; }
|
||||
if(!chrequal<Insensitive>(key[n], t[n])) { *o++ = *t++; break; }
|
||||
}
|
||||
}
|
||||
do *o++ = *t; while(*t++);
|
||||
if(tokenLength > keyLength) free(base);
|
||||
if(base) free(base);
|
||||
|
||||
resize(_size + displacementSize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned Limit> string& string::replace(const char* key, const char* token) { return ureplace<Limit, false, false>(key, token); }
|
||||
template<unsigned Limit> string& string::ireplace(const char* key, const char* token) { return ureplace<Limit, true, false>(key, token); }
|
||||
template<unsigned Limit> string& string::qreplace(const char* key, const char* token) { return ureplace<Limit, false, true>(key, token); }
|
||||
template<unsigned Limit> string& string::iqreplace(const char* key, const char* token) { return ureplace<Limit, true, true>(key, token); }
|
||||
template<unsigned Limit> string& string::replace(rstring key, rstring token) { return ureplace<Limit, false, false>(key, token); }
|
||||
template<unsigned Limit> string& string::ireplace(rstring key, rstring token) { return ureplace<Limit, true, false>(key, token); }
|
||||
template<unsigned Limit> string& string::qreplace(rstring key, rstring token) { return ureplace<Limit, false, true>(key, token); }
|
||||
template<unsigned Limit> string& string::iqreplace(rstring key, rstring token) { return ureplace<Limit, true, true>(key, token); }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
namespace nall {
|
||||
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> lstring& lstring::usplit(const char* key, const char* base) {
|
||||
template<unsigned Limit, bool Insensitive, bool Quoted> lstring& lstring::usplit(rstring key, rstring base) {
|
||||
reset();
|
||||
if(!key || !*key) return *this;
|
||||
if(key.size() == 0) return *this;
|
||||
|
||||
const char* b = base;
|
||||
const char* p = base;
|
||||
|
||||
while(*p) {
|
||||
|
@ -13,23 +14,23 @@ template<unsigned Limit, bool Insensitive, bool Quoted> lstring& lstring::usplit
|
|||
if(quoteskip<Quoted>(p)) continue;
|
||||
for(unsigned n = 0;; n++) {
|
||||
if(key[n] == 0) {
|
||||
append(substr(base, 0, p - base));
|
||||
append(substr(b, 0, p - b));
|
||||
p += n;
|
||||
base = p;
|
||||
b = p;
|
||||
break;
|
||||
}
|
||||
if(!chrequal<Insensitive>(key[n], p[n])) { p++; break; }
|
||||
}
|
||||
}
|
||||
|
||||
append(base);
|
||||
append(b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned Limit> lstring& lstring::split(const char* key, const char* src) { return usplit<Limit, false, false>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::isplit(const char* key, const char* src) { return usplit<Limit, true, false>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::qsplit(const char* key, const char* src) { return usplit<Limit, false, true>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::iqsplit(const char* key, const char* src) { return usplit<Limit, true, true>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::split(rstring key, rstring src) { return usplit<Limit, false, false>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::isplit(rstring key, rstring src) { return usplit<Limit, true, false>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::qsplit(rstring key, rstring src) { return usplit<Limit, false, true>(key, src); }
|
||||
template<unsigned Limit> lstring& lstring::iqsplit(rstring key, rstring src) { return usplit<Limit, true, true>(key, src); }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
string string::read(const string& filename) {
|
||||
string data;
|
||||
data.readfile(filename);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,50 +2,12 @@
|
|||
|
||||
namespace nall {
|
||||
|
||||
template<bool Insensitive>
|
||||
bool chrequal(char x, char y) {
|
||||
if(Insensitive) return chrlower(x) == chrlower(y);
|
||||
return x == y;
|
||||
}
|
||||
|
||||
template<bool Quoted, typename T>
|
||||
bool quoteskip(T*& p) {
|
||||
if(Quoted == false) return false;
|
||||
if(*p != '\'' && *p != '\"') return false;
|
||||
|
||||
while(*p == '\'' || *p == '\"') {
|
||||
char x = *p++;
|
||||
while(*p && *p++ != x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<bool Quoted, typename T>
|
||||
bool quotecopy(char*& t, T*& p) {
|
||||
if(Quoted == false) return false;
|
||||
if(*p != '\'' && *p != '\"') return false;
|
||||
|
||||
while(*p == '\'' || *p == '\"') {
|
||||
char x = *p++;
|
||||
*t++ = x;
|
||||
while(*p && *p != x) *t++ = *p++;
|
||||
*t++ = *p++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string substr(const char* src, unsigned start, unsigned length) {
|
||||
string dest;
|
||||
if(length == ~0u) {
|
||||
//copy entire string
|
||||
dest.reserve(strlen(src + start) + 1);
|
||||
strcpy(dest(), src + start);
|
||||
} else {
|
||||
//copy partial string
|
||||
dest.reserve(length + 1);
|
||||
strmcpy(dest(), src + start, length + 1);
|
||||
}
|
||||
return dest;
|
||||
string substr(rstring source, unsigned offset, unsigned length) {
|
||||
string result;
|
||||
if(length == ~0u) length = source.size() - offset;
|
||||
result.resize(length);
|
||||
memcpy(result.data(), source.data() + offset, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
string sha256(const uint8_t* data, unsigned size) {
|
||||
|
@ -60,7 +22,24 @@ string sha256(const uint8_t* data, unsigned size) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* cast.hpp arithmetic -> string */
|
||||
bool tokenize(lstring& list, const char* s, const char* p) {
|
||||
while(*s) {
|
||||
if(*p == '*') {
|
||||
const char* b = s;
|
||||
while(*s) {
|
||||
if(tokenize(list, s++, p + 1)) {
|
||||
list.prepend(substr(b, 0, --s - b));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
list.prepend(b);
|
||||
return !*++p;
|
||||
}
|
||||
if(*s++ != *p++) return false;
|
||||
}
|
||||
while(*p == '*') { list.prepend(s); p++; }
|
||||
return !*p;
|
||||
}
|
||||
|
||||
char* integer(char* result, intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
|
@ -97,110 +76,6 @@ char* decimal(char* result, uintmax_t value) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* general-purpose arithmetic -> string */
|
||||
|
||||
template<unsigned length_, char padding> string integer(intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = -value;
|
||||
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
if(negative) buffer[size++] = '-';
|
||||
//buffer[size++] = negative ? '-' : '+';
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, padding, length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_, char padding> string linteger(intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = -value;
|
||||
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
if(negative) buffer[size++] = '-';
|
||||
//buffer[size++] = negative ? '-' : '+';
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, padding, length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_, char padding> string decimal(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, padding, length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_, char padding> string ldecimal(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, padding, length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
//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.
|
||||
|
@ -233,7 +108,7 @@ unsigned fp(char* str, long double value) {
|
|||
string fp(long double value) {
|
||||
string temp;
|
||||
temp.reserve(fp(nullptr, value));
|
||||
fp(temp(), value);
|
||||
fp(temp.data(), value);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,16 @@
|
|||
|
||||
namespace nall {
|
||||
|
||||
template<typename... Args> inline void print(Args&&... args) {
|
||||
void sprint(string& output) {
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void sprint(string& output, const T& value, Args&&... args) {
|
||||
output._append(make_string(value));
|
||||
sprint(output, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args> void print(Args&&... args) {
|
||||
printf("%s", (const char*)string(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,46 +2,101 @@
|
|||
|
||||
namespace nall {
|
||||
|
||||
unsigned string::length() const { return strlen(data); }
|
||||
unsigned string::capacity() const { return size; }
|
||||
template<unsigned limit> lstring string::split(rstring key) const { lstring result; result.split<limit>(key, data()); return result; }
|
||||
template<unsigned limit> lstring string::isplit(rstring key) const { lstring result; result.isplit<limit>(key, data()); return result; }
|
||||
template<unsigned limit> lstring string::qsplit(rstring key) const { lstring result; result.qsplit<limit>(key, data()); return result; }
|
||||
template<unsigned limit> lstring string::iqsplit(rstring key) const { lstring result; result.iqsplit<limit>(key, data()); return result; }
|
||||
|
||||
template<unsigned limit> lstring string::split(const char* key) const { lstring result; result.split<limit>(key, data); return result; }
|
||||
template<unsigned limit> lstring string::isplit(const char* key) const { lstring result; result.isplit<limit>(key, data); return result; }
|
||||
template<unsigned limit> lstring string::qsplit(const char* key) const { lstring result; result.qsplit<limit>(key, data); return result; }
|
||||
template<unsigned limit> lstring string::iqsplit(const char* key) const { lstring result; result.iqsplit<limit>(key, data); return result; }
|
||||
bool string::wildcard(rstring source) const { return nall::wildcard(data(), source); }
|
||||
bool string::iwildcard(rstring source) const { return nall::iwildcard(data(), source); }
|
||||
|
||||
bool string::equals(const char* str) const { return !strcmp(data, str); }
|
||||
bool string::iequals(const char* str) const { return !istrcmp(data, str); }
|
||||
bool string::equals(rstring source) const {
|
||||
if(size() != source.size()) return false;
|
||||
return memcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::wildcard(const char* str) const { return nall::wildcard(data, str); }
|
||||
bool string::iwildcard(const char* str) const { return nall::iwildcard(data, str); }
|
||||
bool string::iequals(rstring source) const {
|
||||
if(size() != source.size()) return false;
|
||||
return imemcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::beginswith(const char* str) const { return strbegin(data, str); }
|
||||
bool string::ibeginswith(const char* str) const { return istrbegin(data, str); }
|
||||
bool string::beginswith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return memcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::endswith(const char* str) const { return strend(data, str); }
|
||||
bool string::iendswith(const char* str) const { return istrend(data, str); }
|
||||
bool string::ibeginswith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return imemcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::endswith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return memcmp(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::iendswith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return imemcmp(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
string& string::lower() { nall::strlower(data()); return *this; }
|
||||
string& string::upper() { nall::strupper(data()); return *this; }
|
||||
string& string::qlower() { nall::qstrlower(data()); return *this; }
|
||||
string& string::qupper() { nall::qstrupper(data()); return *this; }
|
||||
|
||||
string& string::transform(rstring before, rstring after) { nall::strtr(data(), before, after); return *this; }
|
||||
|
||||
string& string::lower() { nall::strlower(data); return *this; }
|
||||
string& string::upper() { nall::strupper(data); return *this; }
|
||||
string& string::qlower() { nall::qstrlower(data); return *this; }
|
||||
string& string::qupper() { nall::qstrupper(data); return *this; }
|
||||
string& string::transform(const char* before, const char* after) { nall::strtr(data, before, after); return *this; }
|
||||
string& string::reverse() {
|
||||
unsigned length = strlen(data), pivot = length >> 1;
|
||||
for(signed x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(data[x], data[y]);
|
||||
unsigned length = size(), pivot = length >> 1;
|
||||
for(signed x = 0, y = length - 1; x < pivot && y >= 0; x++, y--) std::swap(data()[x], data()[y]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned limit> string& string::ltrim(const char* key) { nall::ltrim<limit>(data, key); return *this; }
|
||||
template<unsigned limit> string& string::rtrim(const char* key) { nall::rtrim<limit>(data, key); return *this; }
|
||||
template<unsigned limit> string& string::trim(const char* key, const char* rkey) { nall::trim <limit>(data, key, rkey); return *this; }
|
||||
string& string::strip() { nall::strip(data); return *this; }
|
||||
template<unsigned Limit> string& string::ltrim(rstring key) {
|
||||
if(key.size() == 0) return *this;
|
||||
unsigned limit = Limit ? Limit : ~0u, offset = 0;
|
||||
|
||||
optional<unsigned> string::position(const char* key) const { return strpos(data, key); }
|
||||
optional<unsigned> string::iposition(const char* key) const { return istrpos(data, key); }
|
||||
optional<unsigned> string::qposition(const char* key) const { return qstrpos(data, key); }
|
||||
optional<unsigned> string::iqposition(const char* key) const { return iqstrpos(data, key); }
|
||||
while(limit && size() - offset >= key.size()) {
|
||||
if(memcmp(data() + offset, key.data(), key.size())) break;
|
||||
offset += key.size();
|
||||
limit--;
|
||||
}
|
||||
|
||||
if(offset) memmove(data(), data() + offset, size() - offset);
|
||||
resize(size() - offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned Limit> string& string::rtrim(rstring key) {
|
||||
if(key.size() == 0) return *this;
|
||||
unsigned limit = Limit ? Limit : ~0u, offset = 0;
|
||||
|
||||
while(limit && size() - offset >= key.size()) {
|
||||
if(memcmp(data() + size() - key.size() - offset, key.data(), key.size())) break;
|
||||
offset += key.size();
|
||||
limit--;
|
||||
}
|
||||
|
||||
resize(size() - offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned limit> string& string::trim(rstring key, rstring rkey) {
|
||||
rtrim(rkey.size() ? rkey : key);
|
||||
return ltrim(key);
|
||||
}
|
||||
|
||||
string& string::strip() {
|
||||
nall::strip(data());
|
||||
resize(length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
optional<unsigned> string::position(rstring key) const { return strpos(data(), key); }
|
||||
optional<unsigned> string::iposition(rstring key) const { return istrpos(data(), key); }
|
||||
optional<unsigned> string::qposition(rstring key) const { return qstrpos(data(), key); }
|
||||
optional<unsigned> string::iqposition(rstring key) const { return iqstrpos(data(), key); }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ void Application::quit() {
|
|||
return pApplication::quit();
|
||||
}
|
||||
|
||||
void Application::setName(const string& name) {
|
||||
void Application::setName(string name) {
|
||||
applicationState.name = name;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ string Geometry::text() const {
|
|||
return {x, ",", y, ",", width, ",", height};
|
||||
}
|
||||
|
||||
Geometry::Geometry(const string& text) {
|
||||
Geometry::Geometry(string text) {
|
||||
lstring part = text.split(",");
|
||||
x = integer(part(0, "256"));
|
||||
y = integer(part(1, "256"));
|
||||
|
@ -110,19 +110,19 @@ Geometry::Geometry(const string& text) {
|
|||
//Font
|
||||
//====
|
||||
|
||||
string Font::serif(unsigned size, const string& style) {
|
||||
string Font::serif(unsigned size, string style) {
|
||||
return pFont::serif(size, style);
|
||||
}
|
||||
|
||||
string Font::sans(unsigned size, const string& style) {
|
||||
string Font::sans(unsigned size, string style) {
|
||||
return pFont::sans(size, style);
|
||||
}
|
||||
|
||||
string Font::monospace(unsigned size, const string& style) {
|
||||
string Font::monospace(unsigned size, string style) {
|
||||
return pFont::monospace(size, style);
|
||||
}
|
||||
|
||||
Size Font::size(const string &font, const string& text) {
|
||||
Size Font::size(string font, string text) {
|
||||
return pFont::size(font, text);
|
||||
}
|
||||
|
||||
|
@ -192,12 +192,12 @@ BrowserWindow& BrowserWindow::setParent(Window& parent) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
BrowserWindow& BrowserWindow::setPath(const string& path) {
|
||||
BrowserWindow& BrowserWindow::setPath(string path) {
|
||||
state.path = path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BrowserWindow& BrowserWindow::setTitle(const string& title) {
|
||||
BrowserWindow& BrowserWindow::setTitle(string title) {
|
||||
state.title = title;
|
||||
return *this;
|
||||
}
|
||||
|
@ -233,12 +233,12 @@ MessageWindow& MessageWindow::setParent(Window& parent) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
MessageWindow& MessageWindow::setText(const string& text) {
|
||||
MessageWindow& MessageWindow::setText(string text) {
|
||||
state.text = text;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MessageWindow& MessageWindow::setTitle(const string& title) {
|
||||
MessageWindow& MessageWindow::setTitle(string title) {
|
||||
state.title = title;
|
||||
return *this;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ MessageWindow::Response MessageWindow::warning(MessageWindow::Buttons buttons) {
|
|||
return pMessageWindow::warning(state);
|
||||
}
|
||||
|
||||
MessageWindow::MessageWindow(const string& text):
|
||||
MessageWindow::MessageWindow(string text):
|
||||
state(*new State) {
|
||||
state.text = text;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ void Window::setGeometry(const Geometry& geometry) {
|
|||
return p.setGeometry(geometry);
|
||||
}
|
||||
|
||||
void Window::setMenuFont(const string& font) {
|
||||
void Window::setMenuFont(string font) {
|
||||
state.menuFont = font;
|
||||
return p.setMenuFont(font);
|
||||
}
|
||||
|
@ -433,12 +433,12 @@ void Window::setSmartGeometry(const Geometry& geometry) {
|
|||
});
|
||||
}
|
||||
|
||||
void Window::setStatusFont(const string& font) {
|
||||
void Window::setStatusFont(string font) {
|
||||
state.statusFont = font;
|
||||
return p.setStatusFont(font);
|
||||
}
|
||||
|
||||
void Window::setStatusText(const string& text) {
|
||||
void Window::setStatusText(string text) {
|
||||
state.statusText = text;
|
||||
return p.setStatusText(text);
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ void Window::setStatusVisible(bool visible) {
|
|||
return p.setStatusVisible(visible);
|
||||
}
|
||||
|
||||
void Window::setTitle(const string& text) {
|
||||
void Window::setTitle(string text) {
|
||||
state.title = text;
|
||||
return p.setTitle(text);
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ void Window::setVisible(bool visible) {
|
|||
return p.setVisible(visible);
|
||||
}
|
||||
|
||||
void Window::setWidgetFont(const string& font) {
|
||||
void Window::setWidgetFont(string font) {
|
||||
state.widgetFont = font;
|
||||
return p.setWidgetFont(font);
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ void Menu::setImage(const image& image) {
|
|||
return p.setImage(image);
|
||||
}
|
||||
|
||||
void Menu::setText(const string& text) {
|
||||
void Menu::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -588,7 +588,7 @@ void Item::setImage(const image& image) {
|
|||
return p.setImage(image);
|
||||
}
|
||||
|
||||
void Item::setText(const string& text) {
|
||||
void Item::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ void CheckItem::setChecked(bool checked) {
|
|||
return p.setChecked(checked);
|
||||
}
|
||||
|
||||
void CheckItem::setText(const string& text) {
|
||||
void CheckItem::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ void RadioItem::setChecked() {
|
|||
return p.setChecked();
|
||||
}
|
||||
|
||||
void RadioItem::setText(const string& text) {
|
||||
void RadioItem::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ void Widget::setFocused() {
|
|||
return p.setFocused();
|
||||
}
|
||||
|
||||
void Widget::setFont(const string& font) {
|
||||
void Widget::setFont(string font) {
|
||||
state.font = font;
|
||||
return p.setFont(font);
|
||||
}
|
||||
|
@ -835,7 +835,7 @@ void Button::setImage(const image& image, Orientation orientation) {
|
|||
return p.setImage(image, orientation);
|
||||
}
|
||||
|
||||
void Button::setText(const string& text) {
|
||||
void Button::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -912,7 +912,7 @@ void CheckButton::setChecked(bool checked) {
|
|||
return p.setChecked(checked);
|
||||
}
|
||||
|
||||
void CheckButton::setText(const string& text) {
|
||||
void CheckButton::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ void ComboButton::append_(const lstring& list) {
|
|||
}
|
||||
}
|
||||
|
||||
void ComboButton::modify(unsigned row, const string& text) {
|
||||
void ComboButton::modify(unsigned row, string text) {
|
||||
state.text(row) = text;
|
||||
p.modify(row, text);
|
||||
}
|
||||
|
@ -1097,7 +1097,7 @@ HorizontalSlider::~HorizontalSlider() {
|
|||
//Label
|
||||
//=====
|
||||
|
||||
void Label::setText(const string& text) {
|
||||
void Label::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -1123,7 +1123,7 @@ void LineEdit::setEditable(bool editable) {
|
|||
return p.setEditable(editable);
|
||||
}
|
||||
|
||||
void LineEdit::setText(const string& text) {
|
||||
void LineEdit::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -1276,7 +1276,7 @@ void RadioButton::setChecked() {
|
|||
return p.setChecked();
|
||||
}
|
||||
|
||||
void RadioButton::setText(const string& text) {
|
||||
void RadioButton::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
@ -1310,7 +1310,7 @@ void TextEdit::setEditable(bool editable) {
|
|||
return p.setEditable(editable);
|
||||
}
|
||||
|
||||
void TextEdit::setText(const string& text) {
|
||||
void TextEdit::setText(string text) {
|
||||
state.text = text;
|
||||
return p.setText(text);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ struct Application {
|
|||
static bool pendingEvents();
|
||||
static void processEvents();
|
||||
static void quit();
|
||||
static void setName(const nall::string& name);
|
||||
static void setName(nall::string name);
|
||||
|
||||
Application() = delete;
|
||||
struct State;
|
||||
|
@ -108,16 +108,16 @@ struct Geometry {
|
|||
inline Geometry() : x(0), y(0), width(0), height(0) {}
|
||||
inline Geometry(const Position& position, const Size& size) : x(position.x), y(position.y), width(size.width), height(size.height) {}
|
||||
template<typename X, typename Y, typename W, typename H> inline Geometry(X x, Y y, W width, H height) : x(x), y(y), width(width), height(height) {}
|
||||
Geometry(const nall::string& text);
|
||||
Geometry(nall::string text);
|
||||
};
|
||||
|
||||
enum class Orientation : unsigned { Horizontal, Vertical };
|
||||
|
||||
struct Font {
|
||||
static nall::string serif(unsigned size = 0, const nall::string& style = "");
|
||||
static nall::string sans(unsigned size = 0, const nall::string& style = "");
|
||||
static nall::string monospace(unsigned size = 0, const nall::string& style = "");
|
||||
static Size size(const nall::string &font, const nall::string& text);
|
||||
static nall::string serif(unsigned size = 0, nall::string style = "");
|
||||
static nall::string sans(unsigned size = 0, nall::string style = "");
|
||||
static nall::string monospace(unsigned size = 0, nall::string style = "");
|
||||
static Size size(nall::string font, nall::string text);
|
||||
Font() = delete;
|
||||
};
|
||||
|
||||
|
@ -151,8 +151,8 @@ struct BrowserWindow {
|
|||
nall::string save();
|
||||
BrowserWindow& setFilters_(const nall::lstring& filters);
|
||||
BrowserWindow& setParent(Window& parent);
|
||||
BrowserWindow& setPath(const nall::string& path);
|
||||
BrowserWindow& setTitle(const nall::string& title);
|
||||
BrowserWindow& setPath(nall::string path);
|
||||
BrowserWindow& setTitle(nall::string title);
|
||||
|
||||
BrowserWindow();
|
||||
~BrowserWindow();
|
||||
|
@ -179,11 +179,11 @@ struct MessageWindow {
|
|||
Response information(Buttons = Buttons::Ok);
|
||||
Response question(Buttons = Buttons::YesNo);
|
||||
MessageWindow& setParent(Window& parent);
|
||||
MessageWindow& setText(const nall::string& text);
|
||||
MessageWindow& setTitle(const nall::string& title);
|
||||
MessageWindow& setText(nall::string text);
|
||||
MessageWindow& setTitle(nall::string title);
|
||||
Response warning(Buttons = Buttons::Ok);
|
||||
|
||||
MessageWindow(const nall::string& text = "");
|
||||
MessageWindow(nall::string text = "");
|
||||
~MessageWindow();
|
||||
struct State;
|
||||
State& state;
|
||||
|
@ -241,17 +241,17 @@ struct Window : private nall::base_from_member<pWindow&>, Object {
|
|||
void setFocused();
|
||||
void setFullScreen(bool fullScreen = true);
|
||||
void setGeometry(const Geometry& geometry);
|
||||
void setMenuFont(const nall::string& font);
|
||||
void setMenuFont(nall::string font);
|
||||
void setMenuVisible(bool visible = true);
|
||||
void setModal(bool modal = true);
|
||||
void setResizable(bool resizable = true);
|
||||
void setSmartGeometry(const Geometry& geometry);
|
||||
void setStatusFont(const nall::string& font);
|
||||
void setStatusText(const nall::string& text);
|
||||
void setStatusFont(nall::string font);
|
||||
void setStatusText(nall::string text);
|
||||
void setStatusVisible(bool visible = true);
|
||||
void setTitle(const nall::string& text);
|
||||
void setTitle(nall::string text);
|
||||
void setVisible(bool visible = true);
|
||||
void setWidgetFont(const nall::string& font);
|
||||
void setWidgetFont(nall::string font);
|
||||
nall::string statusText();
|
||||
void synchronizeLayout();
|
||||
bool visible();
|
||||
|
@ -283,7 +283,7 @@ struct Menu : private nall::base_from_member<pMenu&>, Action {
|
|||
void append(const nall::group<Action>& list);
|
||||
void remove(const nall::group<Action>& list);
|
||||
void setImage(const nall::image& image = nall::image{});
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
Menu();
|
||||
~Menu();
|
||||
|
@ -302,7 +302,7 @@ struct Item : private nall::base_from_member<pItem&>, Action {
|
|||
nall::function<void ()> onActivate;
|
||||
|
||||
void setImage(const nall::image& image = nall::image{});
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
Item();
|
||||
~Item();
|
||||
|
@ -316,7 +316,7 @@ struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
|
|||
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
CheckItem();
|
||||
~CheckItem();
|
||||
|
@ -333,7 +333,7 @@ struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
|
|||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
nall::string text();
|
||||
|
||||
RadioItem();
|
||||
|
@ -382,7 +382,7 @@ struct Widget : private nall::base_from_member<pWidget&>, Sizable {
|
|||
Size minimumSize();
|
||||
void setEnabled(bool enabled = true);
|
||||
void setFocused();
|
||||
void setFont(const nall::string& font);
|
||||
void setFont(nall::string font);
|
||||
void setGeometry(const Geometry& geometry);
|
||||
void setVisible(bool visible = true);
|
||||
bool visible();
|
||||
|
@ -399,7 +399,7 @@ struct Button : private nall::base_from_member<pButton&>, Widget {
|
|||
nall::function<void ()> onActivate;
|
||||
|
||||
void setImage(const nall::image& image = nall::image{}, Orientation = Orientation::Horizontal);
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
Button();
|
||||
~Button();
|
||||
|
@ -432,7 +432,7 @@ struct CheckButton : private nall::base_from_member<pCheckButton&>, Widget {
|
|||
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
void setText(const nall::string &text);
|
||||
void setText(nall::string text);
|
||||
|
||||
CheckButton();
|
||||
~CheckButton();
|
||||
|
@ -447,7 +447,7 @@ struct ComboButton : private nall::base_from_member<pComboButton&>, Widget {
|
|||
template<typename... Args> void append(Args&&... args) { append_({args...}); }
|
||||
|
||||
void append_(const nall::lstring& list);
|
||||
void modify(unsigned row, const nall::string& text);
|
||||
void modify(unsigned row, nall::string text);
|
||||
void remove(unsigned row);
|
||||
void reset();
|
||||
unsigned selection();
|
||||
|
@ -510,7 +510,7 @@ struct HorizontalSlider : private nall::base_from_member<pHorizontalSlider&>, Wi
|
|||
};
|
||||
|
||||
struct Label : private nall::base_from_member<pLabel&>, Widget {
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
Label();
|
||||
~Label();
|
||||
|
@ -524,7 +524,7 @@ struct LineEdit : private nall::base_from_member<pLineEdit&>, Widget {
|
|||
nall::function<void ()> onChange;
|
||||
|
||||
void setEditable(bool editable = true);
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
nall::string text();
|
||||
|
||||
LineEdit();
|
||||
|
@ -584,7 +584,7 @@ struct RadioButton : private nall::base_from_member<pRadioButton&>, Widget {
|
|||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
|
||||
RadioButton();
|
||||
~RadioButton();
|
||||
|
@ -598,7 +598,7 @@ struct TextEdit : private nall::base_from_member<pTextEdit&>, Widget {
|
|||
|
||||
void setCursorPosition(unsigned position);
|
||||
void setEditable(bool editable = true);
|
||||
void setText(const nall::string& text);
|
||||
void setText(nall::string text);
|
||||
void setWordWrap(bool wordWrap = true);
|
||||
nall::string text();
|
||||
bool wordWrap();
|
||||
|
|
|
@ -14,7 +14,7 @@ void pCheckItem::setChecked(bool checked) {
|
|||
locked = false;
|
||||
}
|
||||
|
||||
void pCheckItem::setText(const string& text) {
|
||||
void pCheckItem::setText(string text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text));
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ void pItem::setImage(const image& image) {
|
|||
}
|
||||
}
|
||||
|
||||
void pItem::setText(const string& text) {
|
||||
void pItem::setText(string text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ void pMenu::setImage(const image& image) {
|
|||
}
|
||||
}
|
||||
|
||||
void pMenu::setText(const string& text) {
|
||||
void pMenu::setText(string text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ void pMenu::orphan() {
|
|||
for(auto& action : menu.state.action) append(action);
|
||||
}
|
||||
|
||||
void pMenu::setFont(const string& font) {
|
||||
void pMenu::setFont(string font) {
|
||||
pAction::setFont(font);
|
||||
for(auto& item : menu.state.action) item.p.setFont(font);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ void pRadioItem::setGroup(const group<RadioItem>& group) {
|
|||
}
|
||||
}
|
||||
|
||||
void pRadioItem::setText(const string& text) {
|
||||
void pRadioItem::setText(string text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), mnemonic(text));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ string pFont::monospace(unsigned size, string style) {
|
|||
return {"Liberation Mono, ", size, ", ", style};
|
||||
}
|
||||
|
||||
Size pFont::size(const string& font, const string& text) {
|
||||
Size pFont::size(string font, string text) {
|
||||
PangoFontDescription* description = create(font);
|
||||
Size size = pFont::size(description, text);
|
||||
free(description);
|
||||
return size;
|
||||
}
|
||||
|
||||
PangoFontDescription* pFont::create(const string& description) {
|
||||
PangoFontDescription* pFont::create(string description) {
|
||||
lstring part;
|
||||
part.split<2>(",", description);
|
||||
for(auto& item : part) item.trim(" ");
|
||||
|
@ -51,7 +51,7 @@ void pFont::free(PangoFontDescription* font) {
|
|||
pango_font_description_free(font);
|
||||
}
|
||||
|
||||
Size pFont::size(PangoFontDescription* font, const string& text) {
|
||||
Size pFont::size(PangoFontDescription* font, string text) {
|
||||
PangoContext* context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
|
||||
PangoLayout* layout = pango_layout_new(context);
|
||||
pango_layout_set_font_description(layout, font);
|
||||
|
@ -62,7 +62,7 @@ Size pFont::size(PangoFontDescription* font, const string& text) {
|
|||
return {width, height};
|
||||
}
|
||||
|
||||
void pFont::setFont(GtkWidget* widget, const string& font) {
|
||||
void pFont::setFont(GtkWidget* widget, string font) {
|
||||
auto gtkFont = pFont::create(font);
|
||||
pFont::setFont(widget, (gpointer)gtkFont);
|
||||
pFont::free(gtkFont);
|
||||
|
|
|
@ -41,12 +41,12 @@ struct pFont {
|
|||
static string serif(unsigned size, string style);
|
||||
static string sans(unsigned size, string style);
|
||||
static string monospace(unsigned size, string style);
|
||||
static Size size(const string& font, const string& text);
|
||||
static Size size(string font, string text);
|
||||
|
||||
static PangoFontDescription* create(const string& description);
|
||||
static PangoFontDescription* create(string description);
|
||||
static void free(PangoFontDescription* font);
|
||||
static Size size(PangoFontDescription* font, const string& text);
|
||||
static void setFont(GtkWidget* widget, const string& font);
|
||||
static Size size(PangoFontDescription* font, string text);
|
||||
static void setFont(GtkWidget* widget, string font);
|
||||
static void setFont(GtkWidget* widget, gpointer font);
|
||||
};
|
||||
|
||||
|
@ -128,16 +128,16 @@ struct pWindow : public pObject {
|
|||
void setFocused();
|
||||
void setFullScreen(bool fullScreen);
|
||||
void setGeometry(const Geometry& geometry);
|
||||
void setMenuFont(const string& font);
|
||||
void setMenuFont(string font);
|
||||
void setMenuVisible(bool visible);
|
||||
void setModal(bool modal);
|
||||
void setResizable(bool resizable);
|
||||
void setStatusFont(const string& font);
|
||||
void setStatusText(const string& text);
|
||||
void setStatusFont(string font);
|
||||
void setStatusText(string text);
|
||||
void setStatusVisible(bool visible);
|
||||
void setTitle(const string& text);
|
||||
void setTitle(string text);
|
||||
void setVisible(bool visible);
|
||||
void setWidgetFont(const string& font);
|
||||
void setWidgetFont(string font);
|
||||
|
||||
pWindow(Window& window) : pObject(window), window(window) {}
|
||||
void constructor();
|
||||
|
@ -166,13 +166,13 @@ struct pMenu : public pAction {
|
|||
void append(Action& action);
|
||||
void remove(Action& action);
|
||||
void setImage(const image& image);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pMenu(Menu &menu) : pAction(menu), menu(menu) {}
|
||||
void constructor();
|
||||
void destructor();
|
||||
void orphan();
|
||||
void setFont(const string& font);
|
||||
void setFont(string font);
|
||||
};
|
||||
|
||||
struct pSeparator : public pAction {
|
||||
|
@ -188,7 +188,7 @@ struct pItem : public pAction {
|
|||
Item& item;
|
||||
|
||||
void setImage(const image& image);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pItem(Item& item) : pAction(item), item(item) {}
|
||||
void constructor();
|
||||
|
@ -201,7 +201,7 @@ struct pCheckItem : public pAction {
|
|||
|
||||
bool checked();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pCheckItem(CheckItem& checkItem) : pAction(checkItem), checkItem(checkItem) {}
|
||||
void constructor();
|
||||
|
@ -215,7 +215,7 @@ struct pRadioItem : public pAction {
|
|||
bool checked();
|
||||
void setChecked();
|
||||
void setGroup(const group<RadioItem>& group);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pRadioItem(RadioItem& radioItem) : pAction(radioItem), radioItem(radioItem) {}
|
||||
void constructor();
|
||||
|
@ -244,7 +244,7 @@ struct pWidget : public pSizable {
|
|||
virtual Size minimumSize();
|
||||
void setEnabled(bool enabled);
|
||||
virtual void setFocused();
|
||||
virtual void setFont(const string& font);
|
||||
virtual void setFont(string font);
|
||||
virtual void setGeometry(const Geometry& geometry);
|
||||
void setVisible(bool visible);
|
||||
|
||||
|
@ -259,7 +259,7 @@ struct pButton : public pWidget {
|
|||
|
||||
Size minimumSize();
|
||||
void setImage(const image& image, Orientation orientation);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pButton(Button& button) : pWidget(button), button(button) {}
|
||||
void constructor();
|
||||
|
@ -286,7 +286,7 @@ struct pCheckButton : public pWidget {
|
|||
bool checked();
|
||||
Size minimumSize();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pCheckButton(CheckButton& checkButton) : pWidget(checkButton), checkButton(checkButton) {}
|
||||
void constructor();
|
||||
|
@ -298,8 +298,8 @@ struct pComboButton : public pWidget {
|
|||
ComboButton& comboButton;
|
||||
unsigned itemCounter;
|
||||
|
||||
void append(const string& text);
|
||||
void modify(unsigned row, const string& text);
|
||||
void append(string text);
|
||||
void modify(unsigned row, string text);
|
||||
void remove(unsigned row);
|
||||
Size minimumSize();
|
||||
void reset();
|
||||
|
@ -371,7 +371,7 @@ struct pLabel : public pWidget {
|
|||
Label& label;
|
||||
|
||||
Size minimumSize();
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pLabel(Label& label) : pWidget(label), label(label) {}
|
||||
void constructor();
|
||||
|
@ -384,7 +384,7 @@ struct pLineEdit : public pWidget {
|
|||
|
||||
Size minimumSize();
|
||||
void setEditable(bool editable);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
string text();
|
||||
|
||||
pLineEdit(LineEdit& lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
|
||||
|
@ -428,7 +428,7 @@ struct pListView : public pWidget {
|
|||
void destructor();
|
||||
void orphan();
|
||||
void setFocused();
|
||||
void setFont(const string& font);
|
||||
void setFont(string font);
|
||||
};
|
||||
|
||||
struct pProgressBar : public pWidget {
|
||||
|
@ -450,7 +450,7 @@ struct pRadioButton : public pWidget {
|
|||
Size minimumSize();
|
||||
void setChecked();
|
||||
void setGroup(const group<RadioButton>& group);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pRadioButton(RadioButton& radioButton) : pWidget(radioButton), radioButton(radioButton) {}
|
||||
void onActivate();
|
||||
|
@ -468,7 +468,7 @@ struct pTextEdit : public pWidget {
|
|||
bool focused();
|
||||
void setCursorPosition(unsigned position);
|
||||
void setEditable(bool editable);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
void setWordWrap(bool wordWrap);
|
||||
string text();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ void pButton::setImage(const image& image, Orientation orientation) {
|
|||
}
|
||||
}
|
||||
|
||||
void pButton::setText(const string& text) {
|
||||
void pButton::setText(string text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
setFont(widget.state.font);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ void pCheckButton::setChecked(bool checked) {
|
|||
locked = false;
|
||||
}
|
||||
|
||||
void pCheckButton::setText(const string& text) {
|
||||
void pCheckButton::setText(string text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ static void ComboButton_change(ComboButton* self) {
|
|||
}
|
||||
}
|
||||
|
||||
void pComboButton::append(const string& text) {
|
||||
void pComboButton::append(string text) {
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text);
|
||||
if(itemCounter++ == 0) setSelection(0);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ Size pComboButton::minimumSize() {
|
|||
return {maximumWidth + 44, size.height + 12};
|
||||
}
|
||||
|
||||
void pComboButton::modify(unsigned row, const string& text) {
|
||||
void pComboButton::modify(unsigned row, string text) {
|
||||
locked = true;
|
||||
unsigned position = selection();
|
||||
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), row);
|
||||
|
|
|
@ -5,7 +5,7 @@ Size pLabel::minimumSize() {
|
|||
return {size.width, size.height};
|
||||
}
|
||||
|
||||
void pLabel::setText(const string& text) {
|
||||
void pLabel::setText(string text) {
|
||||
gtk_label_set_text(GTK_LABEL(gtkWidget), text);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ void pLineEdit::setEditable(bool editable) {
|
|||
gtk_editable_set_editable(GTK_EDITABLE(gtkWidget), editable);
|
||||
}
|
||||
|
||||
void pLineEdit::setText(const string& text) {
|
||||
void pLineEdit::setText(string text) {
|
||||
locked = true;
|
||||
gtk_entry_set_text(GTK_ENTRY(gtkWidget), text);
|
||||
locked = false;
|
||||
|
|
|
@ -217,7 +217,7 @@ void pListView::setFocused() {
|
|||
gtk_widget_grab_focus(subWidget);
|
||||
}
|
||||
|
||||
void pListView::setFont(const string& font) {
|
||||
void pListView::setFont(string font) {
|
||||
pFont::setFont(gtkWidget, font);
|
||||
for(auto& cell : column) pFont::setFont(cell.label, font);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void pRadioButton::setGroup(const group<RadioButton>& group) {
|
|||
parent().locked = false;
|
||||
}
|
||||
|
||||
void pRadioButton::setText(const string& text) {
|
||||
void pRadioButton::setText(string text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ void pTextEdit::setEditable(bool editable) {
|
|||
gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable);
|
||||
}
|
||||
|
||||
void pTextEdit::setText(const string& text) {
|
||||
void pTextEdit::setText(string text) {
|
||||
locked = true;
|
||||
gtk_text_buffer_set_text(textBuffer, text, -1);
|
||||
locked = false;
|
||||
|
|
|
@ -22,7 +22,7 @@ void pWidget::setFocused() {
|
|||
gtk_widget_grab_focus(gtkWidget);
|
||||
}
|
||||
|
||||
void pWidget::setFont(const string& font) {
|
||||
void pWidget::setFont(string font) {
|
||||
pFont::setFont(gtkWidget, font);
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ void pWindow::setGeometry(const Geometry& geometry) {
|
|||
}
|
||||
}
|
||||
|
||||
void pWindow::setMenuFont(const string& font) {
|
||||
void pWindow::setMenuFont(string font) {
|
||||
for(auto& item : window.state.menu) item.p.setFont(font);
|
||||
}
|
||||
|
||||
|
@ -268,11 +268,11 @@ void pWindow::setResizable(bool resizable) {
|
|||
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable);
|
||||
}
|
||||
|
||||
void pWindow::setStatusFont(const string& font) {
|
||||
void pWindow::setStatusFont(string font) {
|
||||
pFont::setFont(status, font);
|
||||
}
|
||||
|
||||
void pWindow::setStatusText(const string& text) {
|
||||
void pWindow::setStatusText(string text) {
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(status), 1);
|
||||
gtk_statusbar_push(GTK_STATUSBAR(status), 1, text);
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ void pWindow::setStatusVisible(bool visible) {
|
|||
gtk_widget_set_visible(status, visible);
|
||||
}
|
||||
|
||||
void pWindow::setTitle(const string& text) {
|
||||
void pWindow::setTitle(string text) {
|
||||
gtk_window_set_title(GTK_WINDOW(widget), text);
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ void pWindow::setVisible(bool visible) {
|
|||
}
|
||||
}
|
||||
|
||||
void pWindow::setWidgetFont(const string& font) {
|
||||
void pWindow::setWidgetFont(string font) {
|
||||
}
|
||||
|
||||
void pWindow::constructor() {
|
||||
|
|
|
@ -7,7 +7,7 @@ bool pCheckItem::checked() {
|
|||
void pCheckItem::setChecked(bool checked) {
|
||||
}
|
||||
|
||||
void pCheckItem::setText(const string& text) {
|
||||
void pCheckItem::setText(string text) {
|
||||
}
|
||||
|
||||
void pCheckItem::constructor() {
|
||||
|
|
|
@ -5,7 +5,7 @@ struct pCheckItem : public pAction {
|
|||
|
||||
bool checked();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pCheckItem(CheckItem& checkItem) : pAction(checkItem), checkItem(checkItem) {}
|
||||
void constructor();
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace phoenix {
|
|||
void pItem::setImage(const image& image) {
|
||||
}
|
||||
|
||||
void pItem::setText(const string& text) {
|
||||
void pItem::setText(string text) {
|
||||
}
|
||||
|
||||
void pItem::constructor() {
|
||||
|
|
|
@ -4,7 +4,7 @@ struct pItem : public pAction {
|
|||
Item& item;
|
||||
|
||||
void setImage(const image& image);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pItem(Item& item) : pAction(item), item(item) {}
|
||||
void constructor();
|
||||
|
|
|
@ -9,7 +9,7 @@ void pMenu::remove(Action& action) {
|
|||
void pMenu::setImage(const image& image) {
|
||||
}
|
||||
|
||||
void pMenu::setText(const string& text) {
|
||||
void pMenu::setText(string text) {
|
||||
}
|
||||
|
||||
void pMenu::constructor() {
|
||||
|
|
|
@ -6,7 +6,7 @@ struct pMenu : public pAction {
|
|||
void append(Action& action);
|
||||
void remove(Action& action);
|
||||
void setImage(const image& image);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pMenu(Menu& menu) : pAction(menu), menu(menu) {}
|
||||
void constructor();
|
||||
|
|
|
@ -10,7 +10,7 @@ void pRadioItem::setChecked() {
|
|||
void pRadioItem::setGroup(const group<RadioItem>& group) {
|
||||
}
|
||||
|
||||
void pRadioItem::setText(const string& text) {
|
||||
void pRadioItem::setText(string text) {
|
||||
}
|
||||
|
||||
void pRadioItem::constructor() {
|
||||
|
|
|
@ -6,7 +6,7 @@ struct pRadioItem : public pAction {
|
|||
bool checked();
|
||||
void setChecked();
|
||||
void setGroup(const group<RadioItem>& group);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pRadioItem(RadioItem& radioItem) : pAction(radioItem), radioItem(radioItem) {}
|
||||
void constructor();
|
||||
|
|
|
@ -12,7 +12,7 @@ string pFont::monospace(unsigned size, string style) {
|
|||
return "";
|
||||
}
|
||||
|
||||
Size pFont::size(const string& font, const string& text) {
|
||||
Size pFont::size(string font, string text) {
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ struct pFont {
|
|||
static string serif(unsigned size, string style);
|
||||
static string sans(unsigned size, string style);
|
||||
static string monospace(unsigned size, string style);
|
||||
static Size size(const string& font, const string& text);
|
||||
static Size size(string font, string text);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace phoenix {
|
|||
void pButton::setImage(const image& image, Orientation orientation) {
|
||||
}
|
||||
|
||||
void pButton::setText(const string& text) {
|
||||
void pButton::setText(string text) {
|
||||
}
|
||||
|
||||
void pButton::constructor() {
|
||||
|
|
|
@ -4,7 +4,7 @@ struct pButton : public pWidget {
|
|||
Button& button;
|
||||
|
||||
void setImage(const image& image, Orientation orientation);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pButton(Button& button) : pWidget(button), button(button) {}
|
||||
void constructor();
|
||||
|
|
|
@ -7,7 +7,7 @@ bool pCheckButton::checked() {
|
|||
void pCheckButton::setChecked(bool checked) {
|
||||
}
|
||||
|
||||
void pCheckButton::setText(const string& text) {
|
||||
void pCheckButton::setText(string text) {
|
||||
}
|
||||
|
||||
void pCheckButton::constructor() {
|
||||
|
|
|
@ -5,7 +5,7 @@ struct pCheckButton : public pWidget {
|
|||
|
||||
bool checked();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pCheckButton(CheckButton& checkButton) : pWidget(checkButton), checkButton(checkButton) {}
|
||||
void constructor();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace phoenix {
|
||||
|
||||
void pComboButton::append(const string& text) {
|
||||
void pComboButton::append(string text) {
|
||||
}
|
||||
|
||||
void pComboButton::modify(unsigned row, const string& text) {
|
||||
void pComboButton::modify(unsigned row, string text) {
|
||||
}
|
||||
|
||||
void pComboButton::remove(unsigned row) {
|
||||
|
|
|
@ -3,8 +3,8 @@ namespace phoenix {
|
|||
struct pComboButton : public pWidget {
|
||||
ComboButton& comboButton;
|
||||
|
||||
void append(const string& text);
|
||||
void modify(unsigned row, const string& text);
|
||||
void append(string text);
|
||||
void modify(unsigned row, string text);
|
||||
void remove(unsigned row);
|
||||
void reset();
|
||||
unsigned selection();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace phoenix {
|
||||
|
||||
void pLabel::setText(const string& text) {
|
||||
void pLabel::setText(string text) {
|
||||
}
|
||||
|
||||
void pLabel::constructor() {
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace phoenix {
|
|||
struct pLabel : public pWidget {
|
||||
Label& label;
|
||||
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pLabel(Label& label) : pWidget(label), label(label) {}
|
||||
void constructor();
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace phoenix {
|
|||
void pLineEdit::setEditable(bool editable) {
|
||||
}
|
||||
|
||||
void pLineEdit::setText(const string& text) {
|
||||
void pLineEdit::setText(string text) {
|
||||
}
|
||||
|
||||
string pLineEdit::text() {
|
||||
|
|
|
@ -4,7 +4,7 @@ struct pLineEdit : public pWidget {
|
|||
LineEdit& lineEdit;
|
||||
|
||||
void setEditable(bool editable);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
string text();
|
||||
|
||||
pLineEdit(LineEdit& lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
|
||||
|
|
|
@ -10,7 +10,7 @@ void pRadioButton::setChecked() {
|
|||
void pRadioButton::setGroup(const group<RadioButton>& group) {
|
||||
}
|
||||
|
||||
void pRadioButton::setText(const string& text) {
|
||||
void pRadioButton::setText(string text) {
|
||||
}
|
||||
|
||||
void pRadioButton::constructor() {
|
||||
|
|
|
@ -6,7 +6,7 @@ struct pRadioButton : public pWidget {
|
|||
bool checked();
|
||||
void setChecked();
|
||||
void setGroup(const group<RadioButton>& group);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
|
||||
pRadioButton(RadioButton& radioButton) : pWidget(radioButton), radioButton(radioButton) {}
|
||||
void constructor();
|
||||
|
|
|
@ -6,7 +6,7 @@ void pTextEdit::setCursorPosition(unsigned position) {
|
|||
void pTextEdit::setEditable(bool editable) {
|
||||
}
|
||||
|
||||
void pTextEdit::setText(const string& text) {
|
||||
void pTextEdit::setText(string text) {
|
||||
}
|
||||
|
||||
void pTextEdit::setWordWrap(bool wordWrap) {
|
||||
|
|
|
@ -5,7 +5,7 @@ struct pTextEdit : public pWidget {
|
|||
|
||||
void setCursorPosition(unsigned position);
|
||||
void setEditable(bool editable);
|
||||
void setText(const string& text);
|
||||
void setText(string text);
|
||||
void setWordWrap(bool wordWrap);
|
||||
string text();
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ void pWidget::setEnabled(bool enabled) {
|
|||
void pWidget::setFocused() {
|
||||
}
|
||||
|
||||
void pWidget::setFont(const string& font) {
|
||||
void pWidget::setFont(string font) {
|
||||
}
|
||||
|
||||
void pWidget::setGeometry(const Geometry& geometry) {
|
||||
|
|
|
@ -8,7 +8,7 @@ struct pWidget : public pSizable {
|
|||
Size minimumSize();
|
||||
void setEnabled(bool enabled);
|
||||
void setFocused();
|
||||
void setFont(const string& font);
|
||||
void setFont(string font);
|
||||
void setGeometry(const Geometry& geometry);
|
||||
void setVisible(bool visible);
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ void pWindow::setFullScreen(bool fullScreen) {
|
|||
void pWindow::setGeometry(const Geometry& geometry) {
|
||||
}
|
||||
|
||||
void pWindow::setMenuFont(const string& font) {
|
||||
void pWindow::setMenuFont(string font) {
|
||||
}
|
||||
|
||||
void pWindow::setMenuVisible(bool visible) {
|
||||
|
@ -64,22 +64,22 @@ void pWindow::setModal(bool modal) {
|
|||
void pWindow::setResizable(bool resizable) {
|
||||
}
|
||||
|
||||
void pWindow::setStatusFont(const string& font) {
|
||||
void pWindow::setStatusFont(string font) {
|
||||
}
|
||||
|
||||
void pWindow::setStatusText(const string& text) {
|
||||
void pWindow::setStatusText(string text) {
|
||||
}
|
||||
|
||||
void pWindow::setStatusVisible(bool visible) {
|
||||
}
|
||||
|
||||
void pWindow::setTitle(const string& text) {
|
||||
void pWindow::setTitle(string text) {
|
||||
}
|
||||
|
||||
void pWindow::setVisible(bool visible) {
|
||||
}
|
||||
|
||||
void pWindow::setWidgetFont(const string& font) {
|
||||
void pWindow::setWidgetFont(string font) {
|
||||
}
|
||||
|
||||
void pWindow::constructor() {
|
||||
|
|
|
@ -19,16 +19,16 @@ struct pWindow : public pObject {
|
|||
void setFocused();
|
||||
void setFullScreen(bool fullScreen);
|
||||
void setGeometry(const Geometry& geometry);
|
||||
void setMenuFont(const string& font);
|
||||
void setMenuFont(string font);
|
||||
void setMenuVisible(bool visible);
|
||||
void setModal(bool modal);
|
||||
void setResizable(bool resizable);
|
||||
void setStatusFont(const string& font);
|
||||
void setStatusText(const string& text);
|
||||
void setStatusFont(string font);
|
||||
void setStatusText(string text);
|
||||
void setStatusVisible(bool visible);
|
||||
void setTitle(const string& text);
|
||||
void setTitle(string text);
|
||||
void setVisible(bool visible);
|
||||
void setWidgetFont(const string& font);
|
||||
void setWidgetFont(string font);
|
||||
|
||||
pWindow(Window& window) : pObject(window), window(window) {}
|
||||
void constructor();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue