2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2015-09-28 11:56:46 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view() {
|
|
|
|
_string = nullptr;
|
|
|
|
_data = "";
|
|
|
|
_size = 0;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view(const string_view& source) {
|
|
|
|
if(this == &source) return;
|
|
|
|
_string = nullptr;
|
|
|
|
_data = source._data;
|
|
|
|
_size = source._size;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view(string_view&& source) {
|
|
|
|
if(this == &source) return;
|
|
|
|
_string = source._string;
|
|
|
|
_data = source._data;
|
|
|
|
_size = source._size;
|
|
|
|
source._string = nullptr;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view(const char* data) {
|
|
|
|
_string = nullptr;
|
|
|
|
_data = data;
|
|
|
|
_size = -1; //defer length calculation, as it is often unnecessary
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view(const char* data, uint size) {
|
|
|
|
_string = nullptr;
|
|
|
|
_data = data;
|
|
|
|
_size = size;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::string_view(const string& source) {
|
|
|
|
_string = nullptr;
|
|
|
|
_data = source.data();
|
|
|
|
_size = source.size();
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
template<typename... P>
|
|
|
|
string_view::string_view(P&&... p) {
|
|
|
|
_string = new string{forward<P>(p)...};
|
|
|
|
_data = _string->data();
|
|
|
|
_size = _string->size();
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::~string_view() {
|
|
|
|
if(_string) delete _string;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
auto string_view::operator=(const string_view& source) -> string_view& {
|
|
|
|
if(this == &source) return *this;
|
|
|
|
_string = nullptr;
|
|
|
|
_data = source._data;
|
|
|
|
_size = source._size;
|
|
|
|
return *this;
|
|
|
|
};
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
auto string_view::operator=(string_view&& source) -> string_view& {
|
|
|
|
if(this == &source) return *this;
|
|
|
|
_string = source._string;
|
|
|
|
_data = source._data;
|
|
|
|
_size = source._size;
|
|
|
|
source._string = nullptr;
|
|
|
|
return *this;
|
|
|
|
};
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
string_view::operator const char*() const {
|
|
|
|
return _data;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
auto string_view::data() const -> const char* {
|
|
|
|
return _data;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
2016-05-16 09:51:12 +00:00
|
|
|
auto string_view::size() const -> uint {
|
|
|
|
if(_size < 0) _size = strlen(_data);
|
|
|
|
return _size;
|
|
|
|
}
|
2015-09-28 11:56:46 +00:00
|
|
|
|
|
|
|
}
|