@@ -8,55 +8,73 @@ A library for diff-ing strings.
88" app.tulz" %%% " stringdiff" % " 0.1.1"
99```
1010
11+ ### Usage
12+
13+ #### Output with ANSI colors:
1114
1215``` scala
13- import app .tulz .diff .StringDiff
16+ import app .tulz .diff ._
1417
1518StringDiff (" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )
1619// or
17- StringDiff .default (" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )
20+ StringDiff .withFormat (" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )( AnsiColorDiffFormat )
1821```
1922
2023![ screenshot 1] ( doc/images/screenshot1.png )
2124
25+ #### Output without colors
26+
2227``` scala
23- import app .tulz .diff .StringDiff
28+ import app .tulz .diff ._
2429
25- StringDiff .xml(" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )
30+ StringDiff .text(" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )
31+ // or
32+ StringDiff .withFormat(" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" )(TextDiffFormat )
2633```
2734
28- ``` xml
29- < diff >< no-match >< expected >< empty /></ expected >< actual > prefix </ actual ></ no-match >< match > common1 common2 </ match >< no-match >< expected >inside2</ expected >< actual > inside1</ actual ></ no-match >< match > common3 </ match >< no-match >< expected > suffix</ expected >< actual >common4</ actual ></ no-match ></ diff >
35+ ```
36+ [ prefix |∅] common1 common2 [ inside1 |inside2 ] common3 [∅| suffix]
3037```
3138
39+ #### Raw AST
3240
3341``` scala
42+ import app .tulz .diff .StringDiff
3443
44+ StringDiff .raw(" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 common3 suffix" ) // List[DiffBlock]
45+ ```
3546
36- import scala .Console ._
37-
38- val diff = new StringDiff (
39- beforeAll = " " ,
40- beforeNoMatch = " [" ,
41- beforeExpected = s " expected: ${YELLOW }" ,
42- afterExpected = RESET ,
43- between = " , " ,
44- beforeActual = s " actual: ${RED }" ,
45- afterActual = RESET ,
46- empty = s " ${MAGENTA }empty ${RESET }" ,
47- afterNoMatch = " ]" ,
48- beforeMatch = GREEN ,
49- afterMatch = RESET ,
50- afterAll = " "
47+ ``` scala
48+ List (
49+ Extra (List (" prefix" , " " )),
50+ Match (List (" common1" , " " , " common2" , " " )),
51+ Different (List (" inside1" , " " ),List (" inside2" , " " )),
52+ Match (List (" common3" , " " )),
53+ Missing (List (" suffix" ))
5154)
55+ ```
5256
53- diff( " prefix common1 common2 inside1 common3 common4 " , " common1 common2 inside2 common3 suffix " )
57+ #### Custom format
5458
55- // custom
59+ ``` scala
60+ import app .tulz .diff .StringDiff
61+ import scala .Console ._
62+
63+ val customFormat : DiffFormat [String ] = (diff : List [DiffBlock ]) =>
64+ diff.map {
65+ case DiffBlock .Match (m) => m.mkString
66+ case DiffBlock .Missing (expected) => s " [missing: ${YELLOW }${expected.mkString}${RESET }] "
67+ case DiffBlock .Extra (actual) => s " [extra: ${RED }${actual.mkString}${RESET }] "
68+ case DiffBlock .Different (actual, expected) => s " [expected: ${YELLOW }${expected.mkString}${RESET }, actual: ${RED }${actual.mkString}${RESET }] "
69+ }.mkString
70+
71+ StringDiff .withFormat(" prefix common1 common2 inside1 common3 common4" , " common1 common2 inside2 inside3 common3 suffix" )(customFormat)
72+ StringDiff .withFormat(" common1 common2 inside1 inside2 common3 common4 suffix" , " prefix common1 common2 inside3 common3" )(customFormat)
5673```
74+
5775![ screenshot 2] ( doc/images/screenshot2.png )
5876
59- ### More examples
77+ ### Examples
6078
6179```
6280token1 token2 token3
0 commit comments