MCPcopy Index your code
hub / github.com/python/cpython / _split_line

Method _split_line

Lib/difflib.py:1807–1860  ·  view source on GitHub ↗

Builds list of text lines by splitting text lines at wrap point This function will determine if the input text line needs to be wrapped (split) into separate lines. If so, the first wrap point will be determined and the first line appended to the output text line li

(self,data_list,line_num,text)

Source from the content-addressed store, hash-verified

1805 return fromlines,tolines
1806
1807 def _split_line(self,data_list,line_num,text):
1808 """Builds list of text lines by splitting text lines at wrap point
1809
1810 This function will determine if the input text line needs to be
1811 wrapped (split) into separate lines. If so, the first wrap point
1812 will be determined and the first line appended to the output
1813 text line list. This function is used recursively to handle
1814 the second part of the split line to further split it.
1815 """
1816 # if blank line or context separator, just add it to the output list
1817 if not line_num:
1818 data_list.append((line_num,text))
1819 return
1820
1821 # if line text doesn't need wrapping, just add it to the output list
1822 size = len(text)
1823 max = self._wrapcolumn
1824 if (size <= max) or ((size -(text.count('\0')*3)) <= max):
1825 data_list.append((line_num,text))
1826 return
1827
1828 # scan text looking for the wrap point, keeping track if the wrap
1829 # point is inside markers
1830 i = 0
1831 n = 0
1832 mark = ''
1833 while n < max and i < size:
1834 if text[i] == '\0':
1835 i += 1
1836 mark = text[i]
1837 i += 1
1838 elif text[i] == '\1':
1839 i += 1
1840 mark = ''
1841 else:
1842 i += 1
1843 n += 1
1844
1845 # wrap point is inside text, break it up into separate lines
1846 line1 = text[:i]
1847 line2 = text[i:]
1848
1849 # if wrap point is inside markers, place end marker at end of first
1850 # line and start marker at beginning of second line because each
1851 # line will have its own table tag markup around it.
1852 if mark:
1853 line1 = line1 + '\1'
1854 line2 = '\0' + mark + line2
1855
1856 # tack on first line onto the output list
1857 data_list.append((line_num,line1))
1858
1859 # use this routine again to wrap the remaining text
1860 self._split_line(data_list,'>',line2)
1861
1862 def _line_wrapper(self,diffs):
1863 """Returns iterator that splits (wraps) mdiff text lines"""

Callers 1

_line_wrapperMethod · 0.95

Calls 2

appendMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected