ToBytes returns the Text of this edit record to a byte string, with newlines at end of each line -- nil if Text is empty
()
| 36 | // ToBytes returns the Text of this edit record to a byte string, with |
| 37 | // newlines at end of each line -- nil if Text is empty |
| 38 | func (te *Edit) ToBytes() []byte { |
| 39 | if te == nil { |
| 40 | return nil |
| 41 | } |
| 42 | sz := len(te.Text) |
| 43 | if sz == 0 { |
| 44 | return nil |
| 45 | } |
| 46 | if sz == 1 { |
| 47 | return []byte(string(te.Text[0])) |
| 48 | } |
| 49 | tsz := 0 |
| 50 | for i := range te.Text { |
| 51 | tsz += len(te.Text[i]) + 10 // don't bother converting to runes, just extra slack |
| 52 | } |
| 53 | b := make([]byte, 0, tsz) |
| 54 | for i := range te.Text { |
| 55 | b = append(b, []byte(string(te.Text[i]))...) |
| 56 | if i < sz-1 { |
| 57 | b = append(b, '\n') |
| 58 | } |
| 59 | } |
| 60 | return b |
| 61 | } |
| 62 | |
| 63 | // AdjustPosDel determines what to do with positions within deleted region |
| 64 | type AdjustPosDel int |
no outgoing calls
no test coverage detected