Refactor: Create function isUtf8ContinuationByte
parent
69ea470a26
commit
05b68a4b80
|
@ -197,3 +197,7 @@ std::size_t StrUtils::Utf8StringLength(const std::string &str)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool StrUtils::isUtf8ContinuationByte(char c)
|
||||
{
|
||||
return (c & 0b11'000000) == 0b10'000000;
|
||||
}
|
||||
|
|
|
@ -87,5 +87,8 @@ int Utf8CharSizeAt(const std::string &str, unsigned int pos);
|
|||
//! Returns the length in characters of UTF-8 string \a str
|
||||
std::size_t Utf8StringLength(const std::string &str);
|
||||
|
||||
//! Returns true if char is continuation UTF-8 byte
|
||||
bool isUtf8ContinuationByte(char c);
|
||||
|
||||
} // namespace StrUtil
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "common/logger.h"
|
||||
#include "common/make_unique.h"
|
||||
#include "common/stringutils.h"
|
||||
|
||||
#include "common/resources/inputstream.h"
|
||||
#include "common/resources/outputstream.h"
|
||||
|
@ -2309,7 +2310,10 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
|
|||
if ( m_cursor1 > 0 )
|
||||
{
|
||||
m_cursor1 --;
|
||||
while ( m_cursor1 > 0 && (m_text[m_cursor1] & 0xC0) == 0x80 ) m_cursor1 --;
|
||||
while ( m_cursor1 > 0 && StrUtils::isUtf8ContinuationByte(m_text[m_cursor1]) )
|
||||
{
|
||||
m_cursor1 --;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2362,7 +2366,10 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
|
|||
if ( m_cursor1 < m_len )
|
||||
{
|
||||
m_cursor1 ++;
|
||||
while ( m_cursor1 < m_len && (m_text[m_cursor1] & 0xC0) == 0x80 ) m_cursor1 ++;
|
||||
while ( m_cursor1 < m_len && StrUtils::isUtf8ContinuationByte(m_text[m_cursor1]) )
|
||||
{
|
||||
m_cursor1 ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2795,8 +2802,8 @@ void CEdit::DeleteOne(int dir)
|
|||
if ( m_cursor1 > m_cursor2 ) Math::Swap(m_cursor1, m_cursor2);
|
||||
|
||||
// Expands selection to delete integer number of UTF-8 symbols
|
||||
while ( m_cursor1 > 0 && (m_text[m_cursor1] & 0xC0) == 0x80 ) m_cursor1 --;
|
||||
while ( m_cursor2 < m_len && (m_text[m_cursor2] & 0xC0) == 0x80 ) m_cursor2 ++;
|
||||
while ( m_cursor1 > 0 && StrUtils::isUtf8ContinuationByte(m_text[m_cursor1]) ) m_cursor1 --;
|
||||
while ( m_cursor2 < m_len && StrUtils::isUtf8ContinuationByte(m_text[m_cursor2]) ) m_cursor2 ++;
|
||||
|
||||
hole = m_cursor2-m_cursor1;
|
||||
end = m_len-hole;
|
||||
|
|
Loading…
Reference in New Issue