@@ -1627,57 +1627,56 @@ Unicode range UTF-8 bytes
1627
1627
(m_pCurrentLine->len >= m_pCurrentLine->iMemoryAllocated )) // emergency bail-out
1628
1628
{
1629
1629
1630
+ int last_space = -1 ;
1631
+
1630
1632
// do auto line wrapping here
1631
1633
1632
- // first see if we can split at a multibyte character if no space was found
1634
+ // see if we can split at a multibyte character
1633
1635
1634
- if (m_pCurrentLine->last_space < 0 && // no space found
1635
- (m_pCurrentLine->len - m_pCurrentLine->last_space ) >= m_nWrapColumn &&
1636
+ if (m_pCurrentLine->len >= m_nWrapColumn &&
1636
1637
m_pCurrentLine->len >= 10 &&
1637
1638
!m_bUTF_8) // not for UTF-8
1638
1639
{
1639
- int multibyte_start = -1 ;
1640
1640
for (int i = 0 ; i < m_pCurrentLine->len - 1 ; i++)
1641
1641
{
1642
1642
unsigned char c1 = m_pCurrentLine->text [i];
1643
1643
unsigned char c2 = m_pCurrentLine->text [i + 1 ];
1644
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
1645
+ ((c2 >= 0x40 && c2 <= 0x7E ) || (c2 >= 0xA1 && c2 <= 0xFE ))) // second Big5 character
1646
+ last_space = i++; // remember position, skip the second byte
1647
+ else if (c1 >= 0xA1 && c1 <= 0xF7 &&
1648
+ c2 >= 0xA1 && c2 <= 0xFE ) // GB2132
1649
+ last_space = i++; // remember position, skip the second byte
1650
+ else if (c1 == ' ' && m_wrap)
1651
+ last_space = i; // or split at a space
1651
1652
}
1652
1653
1653
- m_pCurrentLine->last_space = multibyte_start;
1654
1654
} // end of checking for a Big5 or GB2132 break point
1655
1655
1656
1656
if (!m_wrap ||
1657
- m_pCurrentLine-> last_space < 0 ||
1658
- (m_pCurrentLine->len - m_pCurrentLine-> last_space ) >= m_nWrapColumn)
1657
+ last_space < 0 ||
1658
+ (m_pCurrentLine->len - last_space) >= m_nWrapColumn)
1659
1659
StartNewLine_KeepPreviousStyle (flags);
1660
1660
else
1661
1661
{
1662
- saved_count = m_pCurrentLine->len -
1663
- m_pCurrentLine->last_space ;
1662
+ saved_count = m_pCurrentLine->len - last_space;
1664
1663
1665
1664
// note - saved_count should not be zero because length is 1-relative
1666
1665
// (eg. 1) and last_space is zero-relative (eg. 0)
1667
1666
if (!m_indent_paras)
1668
1667
{
1669
1668
saved_count--; // one less to copy
1670
- m_pCurrentLine-> last_space ++; // one more on this line (the space)
1671
- m_pCurrentLine->len = m_pCurrentLine-> last_space ; // this line is longer
1669
+ last_space++; // one more on this line (the space)
1670
+ m_pCurrentLine->len = last_space; // this line is longer
1672
1671
} // end of indenting not wanted
1673
1672
1674
1673
// saved_count might be zero now, because of no indenting
1675
1674
if (saved_count > 0 )
1676
1675
{
1677
1676
// save portion of text destined for new line
1678
- CString strText = CString (&m_pCurrentLine->text [m_pCurrentLine-> last_space ],
1677
+ CString strText = CString (&m_pCurrentLine->text [last_space],
1679
1678
saved_count);
1680
- m_pCurrentLine->len = m_pCurrentLine-> last_space ;
1679
+ m_pCurrentLine->len = last_space;
1681
1680
1682
1681
CLine * pPreviousLine = m_pCurrentLine; // remember this line
1683
1682
@@ -1744,9 +1743,6 @@ Unicode range UTF-8 bytes
1744
1743
1745
1744
} // end of line wrapping wanted and possible
1746
1745
} // end of line being full
1747
- else
1748
- if (c == ' ' )
1749
- m_pCurrentLine->last_space = m_pCurrentLine->len ;
1750
1746
1751
1747
ASSERT (m_pCurrentLine->text );
1752
1748
@@ -2189,9 +2185,15 @@ CString strLine (lpszText, size);
2189
2185
} // end of \n\n
2190
2186
else
2191
2187
{
2188
+ // work out where the last space is
2189
+ const char * space = strnrchr (m_pCurrentLine->text , ' ' , m_pCurrentLine->len );
2190
+ int last_space = -1 ;
2191
+ if (space)
2192
+ last_space = space - m_pCurrentLine->text ;
2193
+
2192
2194
// don't run words together - if a newline follows a word,
2193
2195
// insert a space
2194
- if (m_pCurrentLine-> last_space != (m_pCurrentLine->len - 1 ))
2196
+ if (last_space != (m_pCurrentLine->len - 1 ))
2195
2197
{
2196
2198
if (m_cLastChar == ' .' && m_pCurrentLine->len < m_nWrapColumn)
2197
2199
AddToLine (" " , flags); // two spaces after period
@@ -2237,7 +2239,6 @@ CString strLine (lpszText, size);
2237
2239
2238
2240
m_pCurrentLine->hard_return = false ;
2239
2241
m_pCurrentLine->len = 0 ;
2240
- m_pCurrentLine->last_space = -1 ;
2241
2242
2242
2243
} // end of letting a \r delete line contents
2243
2244
@@ -2254,8 +2255,14 @@ CString strLine (lpszText, size);
2254
2255
case ' ' : // space
2255
2256
if (m_bInParagraph && !(flags & NOTE_OR_COMMAND)) // for <P>
2256
2257
{
2258
+ // work out where the last space is
2259
+ const char * space = strnrchr (m_pCurrentLine->text , ' ' , m_pCurrentLine->len );
2260
+ int last_space = -1 ;
2261
+ if (space)
2262
+ last_space = space - m_pCurrentLine->text ;
2263
+
2257
2264
// multiple consecutive spaces - discard extras
2258
- if (m_pCurrentLine-> last_space == (m_pCurrentLine->len - 1 ))
2265
+ if (last_space == (m_pCurrentLine->len - 1 ))
2259
2266
{
2260
2267
if (m_cLastChar != ' \n ' )
2261
2268
m_cLastChar = c; // remember it
0 commit comments