| 391 | }; |
| 392 | |
| 393 | class sdsstring : public sdsview |
| 394 | { |
| 395 | public: |
| 396 | sdsstring() = default; |
| 397 | explicit sdsstring(sds str) |
| 398 | : sdsview(str) |
| 399 | {} |
| 400 | |
| 401 | sdsstring(const sdsstring &other) |
| 402 | : sdsview() |
| 403 | { |
| 404 | if (other.m_str != nullptr) |
| 405 | m_str = sdsdup(other.m_str); |
| 406 | } |
| 407 | |
| 408 | sdsstring(const char *rgch, size_t cch) |
| 409 | : sdsview(sdsnewlen(rgch, cch)) |
| 410 | {} |
| 411 | |
| 412 | sdsstring(sdsstring &&other) |
| 413 | : sdsview(other.m_str) |
| 414 | { |
| 415 | other.m_str = nullptr; |
| 416 | } |
| 417 | |
| 418 | sdsstring &operator=(const sdsstring &other) |
| 419 | { |
| 420 | sdsfree(m_str); |
| 421 | if (other.m_str != nullptr) |
| 422 | m_str = sdsdup(other.m_str); |
| 423 | else |
| 424 | m_str = nullptr; |
| 425 | return *this; |
| 426 | } |
| 427 | |
| 428 | sdsstring &operator=(sds other) |
| 429 | { |
| 430 | sdsfree(m_str); |
| 431 | m_str = sdsdup(other); |
| 432 | return *this; |
| 433 | } |
| 434 | |
| 435 | sdsstring &operator=(sdsstring &&other) |
| 436 | { |
| 437 | sds tmp = m_str; |
| 438 | m_str = other.m_str; |
| 439 | other.m_str = tmp; |
| 440 | return *this; |
| 441 | } |
| 442 | |
| 443 | template<typename... Args> |
| 444 | sdsstring catfmt(const char *fmt, Args... args) |
| 445 | { |
| 446 | m_str = sdscatfmt(m_str, fmt, args...); |
| 447 | return *this; |
| 448 | } |
| 449 | |
| 450 | sds release() { |