mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Add support for std::string::assign()
This commit is contained in:
parent
b5388bdb30
commit
f096a602ce
@ -521,6 +521,33 @@ public:
|
|||||||
return base_assign(sv);
|
return base_assign(sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename It>
|
||||||
|
basic_string& assign(It it, It end){
|
||||||
|
auto n = std::distance(it, end);
|
||||||
|
|
||||||
|
set_size(n);
|
||||||
|
|
||||||
|
auto need = n + 1;
|
||||||
|
|
||||||
|
if(capacity() < need){
|
||||||
|
auto capacity = need;
|
||||||
|
|
||||||
|
if(is_small()){
|
||||||
|
new (&storage.big) base_long<CharT>(capacity, new CharT[capacity]);
|
||||||
|
|
||||||
|
set_small(false);
|
||||||
|
} else {
|
||||||
|
storage.big.capacity = capacity;
|
||||||
|
storage.big.data.reset(new CharT[capacity]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::copy(it, end, begin());
|
||||||
|
data_ptr()[size()] = '\0';
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ensure_capacity(size_t new_capacity){
|
void ensure_capacity(size_t new_capacity){
|
||||||
@ -546,6 +573,9 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Cleanup the duplication with ensure_capacity()
|
||||||
|
//Make sure to avoid the unecessary copy
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
basic_string& base_assign(const T& rhs){
|
basic_string& base_assign(const T& rhs){
|
||||||
set_size(rhs.size());
|
set_size(rhs.size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user