github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/luastrings/misc.go (about)

     1  package luastrings
     2  
     3  // StringNormPos returns a normalised position in the string
     4  // i.e. -1 -> len(s)
     5  //      -2 -> len(s) - 1
     6  // etc
     7  func StringNormPos(s string, p int) int {
     8  	if p < 0 {
     9  		p = len(s) + 1 + p
    10  	}
    11  	return p
    12  }