/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/utextwrap.py

  • Committer: INADA Naoki
  • Date: 2011-05-14 14:32:02 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: songofacandy@gmail.com-20110514143202-47r07mp2ebipg2yq
Fix error when fix_sentence_endings=True.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2011 Canonical Ltd
2
2
#
3
3
# UTextWrapper._handle_long_word, UTextWrapper._wrap_chunks,
4
 
# wrap and fill is copied from Python's textwrap module
5
 
# (under PSF license) and modified for support CJK.
 
4
# UTextWrapper._fix_sentence_endings, wrap and fill is copied from Python's
 
5
# textwrap module (under PSF license) and modified for support CJK.
6
6
# Original Copyright for these functions:
7
7
#
8
8
# Copyright (C) 1999-2001 Gregory P. Ward.
107
107
                return s[:pos], s[pos:]
108
108
        return s, u''
109
109
 
 
110
    def _fix_sentence_endings(self, chunks):
 
111
        """_fix_sentence_endings(chunks : [string])
 
112
 
 
113
        Correct for sentence endings buried in 'chunks'.  Eg. when the
 
114
        original text contains "... foo.\nBar ...", munge_whitespace()
 
115
        and split() will convert that to [..., "foo.", " ", "Bar", ...]
 
116
        which has one too few spaces; this method simply changes the one
 
117
        space to two.
 
118
 
 
119
        Note: This function is copied from textwrap.TextWrap and modified
 
120
        to use unicode always.
 
121
        """
 
122
        i = 0
 
123
        L = len(chunks)-1
 
124
        patsearch = self.sentence_end_re.search
 
125
        while i < L:
 
126
            if chunks[i+1] == u" " and patsearch(chunks[i]):
 
127
                chunks[i+1] = u"  "
 
128
                i += 2
 
129
            else:
 
130
                i += 1
 
131
 
110
132
    def _handle_long_word(self, chunks, cur_line, cur_len, width):
111
133
        # Figure out when indent is larger than the specified width, and make
112
134
        # sure at least one character is stripped off on every pass
192
214
            # Convert current line back to a string and store it in list
193
215
            # of all lines (return value).
194
216
            if cur_line:
195
 
                lines.append(indent + ''.join(cur_line))
 
217
                lines.append(indent + u''.join(cur_line))
196
218
 
197
219
        return lines
198
220
 
202
224
        for chunk in chunks:
203
225
            prev_pos = 0
204
226
            for pos, char in enumerate(chunk):
205
 
                if _eawidth(char) in 'FWA':
 
227
                if self._unicode_char_width(char) == 2:
206
228
                    if prev_pos < pos:
207
229
                        cjk_split_chunks.append(chunk[prev_pos:pos])
208
230
                    cjk_split_chunks.append(char)