Skip to content

Commit 73c84f0

Browse files
committed
If no space found, split long lines before start of multibyte character
1 parent a8e8065 commit 73c84f0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

doc.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,31 @@ Unicode range UTF-8 bytes
16271627
(m_pCurrentLine->len >= m_pCurrentLine->iMemoryAllocated)) // emergency bail-out
16281628
{
16291629

1630-
// do auto line wrapping here
1630+
// do auto line wrapping here
1631+
1632+
// first see if we can split at a multibyte character if no space was found
1633+
1634+
if (m_pCurrentLine->last_space < 0 && // no space found
1635+
(m_pCurrentLine->len - m_pCurrentLine->last_space) >= m_nWrapColumn &&
1636+
m_pCurrentLine->len >= 10 &&
1637+
!m_bUTF_8) // not for UTF-8
1638+
{
1639+
int multibyte_start = -1;
1640+
for (int i = 0; i < m_pCurrentLine->len - 1; i++)
1641+
{
1642+
unsigned char c1 = m_pCurrentLine->text [i];
1643+
unsigned char c2 = m_pCurrentLine->text [i + 1];
1644+
if (c1 >= 0x81 && c1 <= 0xFE && // first Big5 character
1645+
((c2 >= 0x40 && c2 <= 0x7E) || (c2 >= 0xA1 && c2 <= 0xFE))) // second Big5 character
1646+
multibyte_start = i++; // remember position, jump the second byte
1647+
else if (c1 >= 0xA1 && c1 <= 0xF7 && c2 >= 0xA1 && c2 <= 0xFE) // GB2132
1648+
multibyte_start = i++; // remember position, jump the second byte
1649+
else if (c1 <= 0x7F)
1650+
multibyte_start = i; // we can split after any ordinary character
1651+
}
1652+
1653+
m_pCurrentLine->last_space = multibyte_start;
1654+
} // end of checking for a Big5 or GB2132 break point
16311655

16321656
if (!m_wrap ||
16331657
m_pCurrentLine->last_space < 0 ||

0 commit comments

Comments
 (0)