* Copy a string into the textbuffer. * @param text Source. */
| 418 | * @param text Source. |
| 419 | */ |
| 420 | void Textbuf::Assign(std::string_view text) |
| 421 | { |
| 422 | size_t bytes = std::min<size_t>(this->max_bytes - 1, text.size()); |
| 423 | this->buf = StrMakeValid(text.substr(0, bytes)); |
| 424 | |
| 425 | /* Make sure the name isn't too long for the text buffer in the number of |
| 426 | * characters (not bytes). max_chars also counts the '\0' characters. */ |
| 427 | Utf8View view(text); |
| 428 | auto it = view.begin(); |
| 429 | const auto end = view.end(); |
| 430 | for (size_t len = 1; len < this->max_chars && it != end; ++len) ++it; |
| 431 | |
| 432 | if (it != end) { |
| 433 | this->buf.erase(it.GetByteOffset(), std::string::npos); |
| 434 | } |
| 435 | |
| 436 | this->UpdateSize(); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | /** |
no test coverage detected