canon 0.3.45 → 0.3.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2dc57b150c1a0a2b9179f4b88a78c22aeb1529aa74d30857d8ca71a6159d6639
|
|
4
|
+
data.tar.gz: 65db8a7cadb8718b11a475858d3bfd5d4adcf0a4c738a7c940a6dfa60a6bfd3e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d411dc92e7978a904f303a95397f301286e9a12a3fc3732bb91919c2564375221b12cb13db64198f41942edeb5bbe2dfc8512b173cbfbdab44d27409d5a009a9
|
|
7
|
+
data.tar.gz: eaa339eae29ca147aa6ee9a5cecf9a328e69fc9b1f64b3acb742d11f4d451bef89efc11cde012e06e15f21b10ec09f95fbf36e0456c718ba925c015e47dba0ce
|
|
@@ -21,19 +21,22 @@ module Canon
|
|
|
21
21
|
# @param text1 [String] The first document (preprocessed)
|
|
22
22
|
# @param text2 [String] The second document (preprocessed)
|
|
23
23
|
# @return [Array<DiffLine>] The assembled diff lines
|
|
24
|
-
def self.build(diff_nodes, text1, text2)
|
|
24
|
+
def self.build(diff_nodes, text1, text2, lines1: nil, lines2: nil)
|
|
25
25
|
return [] if diff_nodes.nil? || diff_nodes.empty?
|
|
26
26
|
return [] if text1.nil? || text2.nil?
|
|
27
27
|
|
|
28
|
-
new(diff_nodes, text1, text2).build
|
|
28
|
+
new(diff_nodes, text1, text2, lines1, lines2).build
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def initialize(diff_nodes, text1, text2)
|
|
31
|
+
def initialize(diff_nodes, text1, text2, lines1 = nil, lines2 = nil)
|
|
32
32
|
@diff_nodes = diff_nodes
|
|
33
33
|
@text1 = text1
|
|
34
34
|
@text2 = text2
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# The caller may hand in the already-split lines (the
|
|
36
|
+
# formatter splits these documents too); re-splitting both
|
|
37
|
+
# documents per pipeline stage was ~2x the line strings.
|
|
38
|
+
@lines1 = lines1 || text1.split("\n")
|
|
39
|
+
@lines2 = lines2 || text2.split("\n")
|
|
37
40
|
# Build reverse indices for efficient content lookup in gap handling.
|
|
38
41
|
# Maps content string to array of line indices where that content appears.
|
|
39
42
|
@line_to_indices1 = build_line_index(@lines1)
|
|
@@ -22,21 +22,22 @@ module Canon
|
|
|
22
22
|
# @param text1 [String] The first document (preprocessed)
|
|
23
23
|
# @param text2 [String] The second document (preprocessed)
|
|
24
24
|
# @return [Array<DiffNode>] The same DiffNodes, enriched in place
|
|
25
|
-
def self.build(diff_nodes, text1, text2)
|
|
25
|
+
def self.build(diff_nodes, text1, text2, lines1: nil, lines2: nil)
|
|
26
26
|
return diff_nodes if diff_nodes.nil? || diff_nodes.empty?
|
|
27
27
|
return diff_nodes if text1.nil? || text2.nil?
|
|
28
28
|
|
|
29
|
-
new(diff_nodes, text1, text2).enrich
|
|
29
|
+
new(diff_nodes, text1, text2, lines1, lines2).enrich
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def initialize(diff_nodes, text1, text2)
|
|
32
|
+
def initialize(diff_nodes, text1, text2, lines1 = nil, lines2 = nil)
|
|
33
33
|
@diff_nodes = diff_nodes
|
|
34
34
|
@text1 = text1
|
|
35
35
|
@text2 = text2
|
|
36
36
|
@line_map1 = SourceLocator.build_line_map(text1)
|
|
37
37
|
@line_map2 = SourceLocator.build_line_map(text2)
|
|
38
|
-
|
|
39
|
-
@
|
|
38
|
+
# Shared split — see DiffLineBuilder's note.
|
|
39
|
+
@lines1 = lines1 || text1.split("\n")
|
|
40
|
+
@lines2 = lines2 || text2.split("\n")
|
|
40
41
|
# Track occurrences for text_content dimension to find correct element instance
|
|
41
42
|
@text_occurrence1 = Hash.new(0)
|
|
42
43
|
@text_occurrence2 = Hash.new(0)
|
|
@@ -44,12 +44,22 @@ module Canon
|
|
|
44
44
|
# Compute line number width BEFORE formatting
|
|
45
45
|
compute_line_num_width(doc1, doc2)
|
|
46
46
|
|
|
47
|
+
# The pipeline splits both documents once here; every stage
|
|
48
|
+
# downstream reuses the arrays (three redundant full-doc
|
|
49
|
+
# splits per render before).
|
|
50
|
+
@pipeline_lines1 = doc1.split("\n")
|
|
51
|
+
@pipeline_lines2 = doc2.split("\n")
|
|
52
|
+
|
|
47
53
|
# Phase 1: Enrich DiffNodes with character positions
|
|
48
|
-
Canon::Diff::DiffNodeEnricher.build(@differences, doc1, doc2
|
|
54
|
+
Canon::Diff::DiffNodeEnricher.build(@differences, doc1, doc2,
|
|
55
|
+
lines1: @pipeline_lines1,
|
|
56
|
+
lines2: @pipeline_lines2)
|
|
49
57
|
|
|
50
58
|
# Phase 2: Assemble DiffLines from enriched DiffNodes
|
|
51
59
|
diff_lines = Canon::Diff::DiffLineBuilder.build(@differences, doc1,
|
|
52
|
-
doc2
|
|
60
|
+
doc2,
|
|
61
|
+
lines1: @pipeline_lines1,
|
|
62
|
+
lines2: @pipeline_lines2)
|
|
53
63
|
|
|
54
64
|
# Layers 3-5: Build report through pipeline
|
|
55
65
|
report = Canon::Diff::DiffReportBuilder.build(
|
|
@@ -178,8 +188,8 @@ module Canon
|
|
|
178
188
|
def format_report(report, doc1, doc2)
|
|
179
189
|
return "" if report.contexts.empty?
|
|
180
190
|
|
|
181
|
-
lines1 = doc1.split("\n")
|
|
182
|
-
lines2 = doc2.split("\n")
|
|
191
|
+
lines1 = @pipeline_lines1 || doc1.split("\n")
|
|
192
|
+
lines2 = @pipeline_lines2 || doc2.split("\n")
|
|
183
193
|
|
|
184
194
|
output = []
|
|
185
195
|
|
data/lib/canon/version.rb
CHANGED