Definition at line 139 of file utilities.py.
◆ diff_linesToWords()
| def diff_linesToWords |
( |
|
self, |
|
|
|
text1, |
|
|
|
text2, |
|
|
|
delimiter = re.compile('\n') |
|
) |
| |
Split two texts into an array of strings. Reduce the texts to a string
of hashes where each Unicode character represents one line.
95% of this function code is copied from `diff_linesToChars` on:
https://github.com/google/diff-match-patch/blob/895a9512bbcee0ac5a8ffcee36062c8a79f5dcda/python3/diff_match_patch.py#L381
Copyright 2018 The diff-match-patch Authors.
https://github.com/google/diff-match-patch
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Args:
text1: First string.
text2: Second string.
delimiter: a re.compile() expression for the word delimiter type
Returns:
Three element tuple, containing the encoded text1, the encoded text2 and
the array of unique strings. The zeroth element of the array of unique
strings is intentionally blank.
Definition at line 216 of file utilities.py.
218 Split two texts into an array of strings. Reduce the texts to a string 219 of hashes where each Unicode character represents one line. 221 95% of this function code is copied from `diff_linesToChars` on: 222 https://github.com/google/diff-match-patch/blob/895a9512bbcee0ac5a8ffcee36062c8a79f5dcda/python3/diff_match_patch.py#L381 224 Copyright 2018 The diff-match-patch Authors. 225 https://github.com/google/diff-match-patch 226 Licensed under the Apache License, Version 2.0 (the "License"); 227 you may not use this file except in compliance with the License. 228 You may obtain a copy of the License at 229 http://www.apache.org/licenses/LICENSE-2.0 233 text2: Second string. 234 delimiter: a re.compile() expression for the word delimiter type 237 Three element tuple, containing the encoded text1, the encoded text2 and 238 the array of unique strings. The zeroth element of the array of unique 239 strings is intentionally blank. 248 def diff_linesToCharsMunge(text):
249 """Split a text into an array of strings. Reduce the texts to a string 250 of hashes where each Unicode character represents one line. 251 Modifies linearray and linehash through being a closure. 253 text: String to encode. 263 while lineEnd < len(text) - 1:
264 lineEnd = delimiter.search(text, lineStart)
267 lineEnd = lineEnd.start()
270 lineEnd = len(text) - 1
272 line = text[lineStart:lineEnd + 1]
275 chars.append(unichr(lineHash[line]))
277 if len(lineArray) == maxLines:
279 line = text[lineStart:]
281 lineArray.append(line)
282 lineHash[line] = len(lineArray) - 1
283 chars.append(unichr(len(lineArray) - 1))
284 lineStart = lineEnd + 1
285 return "".join(chars)
288 maxLines = _g_maximum_lines
289 chars1 = diff_linesToCharsMunge(text1)
290 maxLines = _g_char_limit
291 chars2 = diff_linesToCharsMunge(text2)
292 return (chars1, chars2, lineArray)
◆ diff_prettyText()
| def diff_prettyText |
( |
|
self, |
|
|
|
diffs |
|
) |
| |
Convert a diff array into a pretty Text report.
Args:
diffs: Array of diff tuples.
Returns:
Text representation.
Definition at line 141 of file utilities.py.
142 """Convert a diff array into a pretty Text report. 144 diffs: Array of diff tuples. 149 last_op_type = self.DIFF_EQUAL
152 cut_next_new_line = [
False]
155 operations = (self.DIFF_INSERT, self.DIFF_DELETE)
166 new = textwrap_indent(
"%s" % new, sign,
lambda line:
True )
169 if len(results_diff) > 0:
174 if op == self.DIFF_INSERT
and next_text
and new[-1] ==
'\n' and next_text[0] ==
'\n':
175 cut_next_new_line[0] =
True;
178 if len(text) > 1: new = new +
'%s\n' % sign
180 elif next_op
not in operations
and next_text
and next_text[0] !=
'\n':
186 for index
in range(len(diffs)):
187 op, text = diffs[index]
188 if index < len(diffs) - 1:
189 next_op, next_text = diffs[index+1]
191 next_op, next_text = (0,
"")
193 if op == self.DIFF_INSERT:
194 results_diff.append( parse(
"+ " ) )
196 elif op == self.DIFF_DELETE:
197 results_diff.append( parse(
"- " ) )
199 elif op == self.DIFF_EQUAL:
202 text = textwrap_indent(text,
" ")
204 if cut_next_new_line[0]:
205 cut_next_new_line[0] =
False 208 results_diff.append(text)
214 return "".join(results_diff)
The documentation for this class was generated from the following file: