| 58 | } |
| 59 | |
| 60 | void CLineInput::SetRange(const char *pString, size_t Begin, size_t End) |
| 61 | { |
| 62 | if(Begin > End) |
| 63 | std::swap(Begin, End); |
| 64 | Begin = std::clamp<size_t>(Begin, 0, m_Len); |
| 65 | End = std::clamp<size_t>(End, 0, m_Len); |
| 66 | |
| 67 | size_t RemovedCharSize, RemovedCharCount; |
| 68 | str_utf8_stats(m_pStr + Begin, End - Begin + 1, m_MaxChars, &RemovedCharSize, &RemovedCharCount); |
| 69 | |
| 70 | size_t AddedCharSize, AddedCharCount; |
| 71 | str_utf8_stats(pString, m_MaxSize - m_Len + RemovedCharSize, m_MaxChars - m_NumChars + RemovedCharCount, &AddedCharSize, &AddedCharCount); |
| 72 | |
| 73 | if(RemovedCharSize || AddedCharSize) |
| 74 | { |
| 75 | if(AddedCharSize < RemovedCharSize) |
| 76 | { |
| 77 | if(AddedCharSize) |
| 78 | mem_copy(m_pStr + Begin, pString, AddedCharSize); |
| 79 | mem_move(m_pStr + Begin + AddedCharSize, m_pStr + Begin + RemovedCharSize, m_Len - Begin - AddedCharSize); |
| 80 | } |
| 81 | else if(AddedCharSize > RemovedCharSize) |
| 82 | mem_move(m_pStr + End + AddedCharSize - RemovedCharSize, m_pStr + End, m_Len - End); |
| 83 | |
| 84 | if(AddedCharSize >= RemovedCharSize) |
| 85 | mem_copy(m_pStr + Begin, pString, AddedCharSize); |
| 86 | |
| 87 | m_CursorPos = End - RemovedCharSize + AddedCharSize; |
| 88 | m_Len += AddedCharSize - RemovedCharSize; |
| 89 | m_NumChars += AddedCharCount - RemovedCharCount; |
| 90 | m_WasChanged = true; |
| 91 | m_WasCursorChanged = true; |
| 92 | m_pStr[m_Len] = '\0'; |
| 93 | m_SelectionStart = m_SelectionEnd = m_CursorPos; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void CLineInput::Insert(const char *pString, size_t Begin) |
| 98 | { |
no test coverage detected