MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _make_line

Function _make_line

tools/python-3.11.9-amd64/Lib/difflib.py:1382–1436  ·  view source on GitHub ↗

Returns line of text with user's change markup and line formatting. lines -- list of lines from the ndiff generator to produce a line of text from. When producing the line of text to return, the lines used are removed from this list. format_ke

(lines, format_key, side, num_lines=[0,0])

Source from the content-addressed store, hash-verified

1380 diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
1381
1382 def _make_line(lines, format_key, side, num_lines=[0,0]):
1383 """Returns line of text with user's change markup and line formatting.
1384
1385 lines -- list of lines from the ndiff generator to produce a line of
1386 text from. When producing the line of text to return, the
1387 lines used are removed from this list.
1388 format_key -- '+' return first line in list with "add" markup around
1389 the entire line.
1390 '-' return first line in list with "delete" markup around
1391 the entire line.
1392 '?' return first line in list with add/delete/change
1393 intraline markup (indices obtained from second line)
1394 None return first line in list with no markup
1395 side -- indice into the num_lines list (0=from,1=to)
1396 num_lines -- from/to current line number. This is NOT intended to be a
1397 passed parameter. It is present as a keyword argument to
1398 maintain memory of the current line numbers between calls
1399 of this function.
1400
1401 Note, this function is purposefully not defined at the module scope so
1402 that data it needs from its parent function (within whose context it
1403 is defined) does not need to be of module scope.
1404 """
1405 num_lines[side] += 1
1406 # Handle case where no user markup is to be added, just return line of
1407 # text with user's line format to allow for usage of the line number.
1408 if format_key is None:
1409 return (num_lines[side],lines.pop(0)[2:])
1410 # Handle case of intraline changes
1411 if format_key == '?':
1412 text, markers = lines.pop(0), lines.pop(0)
1413 # find intraline changes (store change type and indices in tuples)
1414 sub_info = []
1415 def record_sub_info(match_object,sub_info=sub_info):
1416 sub_info.append([match_object.group(1)[0],match_object.span()])
1417 return match_object.group(1)
1418 change_re.sub(record_sub_info,markers)
1419 # process each tuple inserting our special marks that won't be
1420 # noticed by an xml/html escaper.
1421 for key,(begin,end) in reversed(sub_info):
1422 text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:]
1423 text = text[2:]
1424 # Handle case of add/delete entire line
1425 else:
1426 text = lines.pop(0)[2:]
1427 # if line of text is just a newline, insert a space so there is
1428 # something for the user to highlight and see.
1429 if not text:
1430 text = ' '
1431 # insert marks that won't be noticed by an xml/html escaper.
1432 text = '\0' + format_key + text + '\1'
1433 # Return line of text, first allow user's line formatter to do its
1434 # thing (such as adding the line number) then replace the special
1435 # marks with what the user's change markup.
1436 return (num_lines[side],text)
1437
1438 def _line_iterator():
1439 """Yields from/to lines of text with a change indication.

Callers 1

_line_iteratorFunction · 0.85

Calls 2

popMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected