| 789 | } |
| 790 | |
| 791 | void SmallStringBase::erase(s32 offset, s32 count) |
| 792 | { |
| 793 | // calc real offset |
| 794 | u32 real_offset; |
| 795 | if (offset < 0) |
| 796 | real_offset = static_cast<u32>(std::max<s32>(0, static_cast<s32>(m_length + offset))); |
| 797 | else |
| 798 | real_offset = std::min((u32)offset, m_length); |
| 799 | |
| 800 | // calc real count |
| 801 | u32 real_count; |
| 802 | if (count < 0) |
| 803 | { |
| 804 | real_count = |
| 805 | std::min(m_length - real_offset, static_cast<u32>(std::max<s32>(0, static_cast<s32>(m_length) + count))); |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | real_count = std::min(m_length - real_offset, static_cast<u32>(count)); |
| 810 | } |
| 811 | |
| 812 | // Fastpath: offset == 0, count < 0, wipe whole string. |
| 813 | if (real_offset == 0 && real_count == m_length) |
| 814 | { |
| 815 | clear(); |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | // Fastpath: offset >= 0, count < 0, wipe everything after offset + count |
| 820 | if ((real_offset + real_count) == m_length) |
| 821 | { |
| 822 | m_length -= real_count; |
| 823 | #ifdef _DEBUG |
| 824 | std::memset(m_buffer + m_length, 0, m_buffer_size - m_length); |
| 825 | #else |
| 826 | m_buffer[m_length] = 0; |
| 827 | #endif |
| 828 | } |
| 829 | // Slowpath: offset >= 0, count < length |
| 830 | else |
| 831 | { |
| 832 | const u32 after_erase_block = m_length - real_offset - real_count; |
| 833 | pxAssert(after_erase_block > 0); |
| 834 | |
| 835 | std::memmove(m_buffer + offset, m_buffer + real_offset + real_count, after_erase_block); |
| 836 | m_length = m_length - real_count; |
| 837 | |
| 838 | #ifdef _DEBUG |
| 839 | std::memset(m_buffer + m_length, 0, m_buffer_size - m_length); |
| 840 | #else |
| 841 | m_buffer[m_length] = 0; |
| 842 | #endif |
| 843 | } |
| 844 | } |
no test coverage detected