position

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(content []rune, offset int) string
Example
fmt.Println(Get([]rune("a"), 0))
fmt.Println(Get([]rune("a\nb"), 1))
fmt.Println(Get([]rune("中文2\n\n\n6789"), 7))
Output:

Line 1: a
Char 1: ^
Line 1: a
Char 2:  ^
Line 4: 6789
Char 2:  ^

func GetLineContent

func GetLineContent(content []rune, offset, column int) []rune

func GetLineEnd

func GetLineEnd(content []rune, offset int) int

func OffsetToLineAndColumn

func OffsetToLineAndColumn(content []rune, offset int) (int, int)

line and column begins at 1

Example
fmt.Println(OffsetToLineAndColumn([]rune(""), -1))
fmt.Println(OffsetToLineAndColumn([]rune(""), 0))

fmt.Println(OffsetToLineAndColumn([]rune("a"), 0))
fmt.Println(OffsetToLineAndColumn([]rune("a\nb"), 1))
fmt.Println(OffsetToLineAndColumn([]rune("中文3\n\n\n6789"), 7))

fmt.Println(OffsetToLineAndColumn([]rune("a\r\n"), 2))
fmt.Println(OffsetToLineAndColumn([]rune("a\r\nb"), 3))
Output:

0 0
0 0
1 1
1 2
4 2
1 3
2 1

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL