translateIndentLevel returns the file-side lead for an inserted splice line by translating the caller's indent level. rLead is the inserted replacement line's lead, sLead is the reference search line's lead (the pair the splice would have inherited from), cLead is the matched content's lead at that
(rLead, sLead, cLead, searchUnit, fileUnit string)
| 833 | // reference slot. Returns ("", false) when any of the leads are |
| 834 | // not clean multiples of their respective units. |
| 835 | func translateIndentLevel(rLead, sLead, cLead, searchUnit, fileUnit string) (string, bool) { |
| 836 | repLevel, ok := indentLevel(rLead, searchUnit) |
| 837 | if !ok { |
| 838 | return "", false |
| 839 | } |
| 840 | searchBase, ok := indentLevel(sLead, searchUnit) |
| 841 | if !ok { |
| 842 | return "", false |
| 843 | } |
| 844 | fileBase, ok := indentLevel(cLead, fileUnit) |
| 845 | if !ok { |
| 846 | return "", false |
| 847 | } |
| 848 | targetLevel := fileBase + (repLevel - searchBase) |
| 849 | if targetLevel < 0 { |
| 850 | return "", false |
| 851 | } |
| 852 | return strings.Repeat(fileUnit, targetLevel), true |
| 853 | } |
| 854 | |
| 855 | // indentLevel returns len(lead) / len(unit) when lead is a clean |
| 856 | // multiple of unit. Returns (0, false) when lead doesn't divide |