DiffXIndex returns the equivalent location in s2.
(diffs []Diff, loc int)
| 1100 | |
| 1101 | // DiffXIndex returns the equivalent location in s2. |
| 1102 | func (dmp *DiffMatchPatch) DiffXIndex(diffs []Diff, loc int) int { |
| 1103 | chars1 := 0 |
| 1104 | chars2 := 0 |
| 1105 | lastChars1 := 0 |
| 1106 | lastChars2 := 0 |
| 1107 | lastDiff := Diff{} |
| 1108 | for i := 0; i < len(diffs); i++ { |
| 1109 | aDiff := diffs[i] |
| 1110 | if aDiff.Type != DiffInsert { |
| 1111 | // Equality or deletion. |
| 1112 | chars1 += len(aDiff.Text) |
| 1113 | } |
| 1114 | if aDiff.Type != DiffDelete { |
| 1115 | // Equality or insertion. |
| 1116 | chars2 += len(aDiff.Text) |
| 1117 | } |
| 1118 | if chars1 > loc { |
| 1119 | // Overshot the location. |
| 1120 | lastDiff = aDiff |
| 1121 | break |
| 1122 | } |
| 1123 | lastChars1 = chars1 |
| 1124 | lastChars2 = chars2 |
| 1125 | } |
| 1126 | if lastDiff.Type == DiffDelete { |
| 1127 | // The location was deleted. |
| 1128 | return lastChars2 |
| 1129 | } |
| 1130 | // Add the remaining character length. |
| 1131 | return lastChars2 + (loc - lastChars1) |
| 1132 | } |
| 1133 | |
| 1134 | // DiffPrettyHtml converts a []Diff into a pretty HTML report. |
| 1135 | // It is intended as an example from which to write one's own display functions. |
no outgoing calls