SpanPosToRuneIndex returns the absolute rune index for a given span, rune index position -- i.e., the inverse of RuneSpanPos. Returns false if given input position is out of range, and returns last valid index in that case.
(si, ri int)
| 39 | // index position -- i.e., the inverse of RuneSpanPos. Returns false if given |
| 40 | // input position is out of range, and returns last valid index in that case. |
| 41 | func (tx *Text) SpanPosToRuneIndex(si, ri int) (idx int, ok bool) { |
| 42 | idx = 0 |
| 43 | for i := range tx.Spans { |
| 44 | sr := &tx.Spans[i] |
| 45 | if si > i { |
| 46 | idx += len(sr.Render) |
| 47 | continue |
| 48 | } |
| 49 | if ri <= len(sr.Render) { |
| 50 | return idx + ri, true |
| 51 | } |
| 52 | return idx + (len(sr.Render)), false |
| 53 | } |
| 54 | return 0, false |
| 55 | } |
| 56 | |
| 57 | // RuneRelPos returns the relative (starting) position of the given rune |
| 58 | // index, counting progressively through all spans present (adds Span RelPos |
no outgoing calls
no test coverage detected