@@ -1631,30 +1631,35 @@ Unicode range UTF-8 bytes
1631
1631
1632
1632
// do auto line wrapping here
1633
1633
1634
- // see if we can split at a multibyte character
1634
+ // see if we can split at a multibyte character or a space (whichever comes last)
1635
1635
1636
1636
if (m_pCurrentLine->len >= m_nWrapColumn &&
1637
- m_pCurrentLine->len >= 10 &&
1638
- !m_bUTF_8) // not for UTF-8
1637
+ m_pCurrentLine->len >= 2 )
1639
1638
{
1640
1639
for (int i = 0 ; i < m_pCurrentLine->len - 1 ; i++)
1641
1640
{
1642
1641
unsigned char c1 = m_pCurrentLine->text [i];
1643
1642
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
1643
+ // don't test for Big5 if output buffer is UTF-8 (the tests would be wrong)
1644
+ if (c1 >= 0x81 && c1 <= 0xFE && // first Big5 character
1645
+ ((c2 >= 0x40 && c2 <= 0x7E ) || (c2 >= 0xA1 && c2 <= 0xFE )) // second Big5 character
1646
+ && !m_bUTF_8) // not for UTF-8
1646
1647
last_space = i++; // remember position, skip the second byte
1647
- else if (c1 >= 0xA1 && c1 <= 0xF7 &&
1648
- c2 >= 0xA1 && c2 <= 0xFE ) // GB2132
1648
+ else if (c1 >= 0xA1 && c1 <= 0xF7 && // first GB2132 character
1649
+ c2 >= 0xA1 && c2 <= 0xFE && // second GB2132 character
1650
+ !m_bUTF_8) // // not for UTF-8
1649
1651
last_space = i++; // remember position, skip the second byte
1650
1652
else if (c1 == ' ' && m_wrap)
1651
1653
last_space = i; // or split at a space
1652
1654
}
1653
1655
1654
- } // end of checking for a Big5 or GB2132 break point
1656
+ // allow for space being the final thing on the line
1657
+ if (m_pCurrentLine->text [m_pCurrentLine->len - 1 ] == ' ' && m_wrap)
1658
+ last_space = m_pCurrentLine->len - 1 ;
1655
1659
1656
- if (!m_wrap ||
1657
- last_space < 0 ||
1660
+ } // end of checking for a space, Big5 or GB2132 break point
1661
+
1662
+ if (last_space < 0 || // if no break point found, break anyway at end of line
1658
1663
(m_pCurrentLine->len - last_space) >= m_nWrapColumn)
1659
1664
StartNewLine_KeepPreviousStyle (flags);
1660
1665
else
0 commit comments