MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / posrelatI

Function posrelatI

3rd/lua-5.4.3/src/lstrlib.c:71–79  ·  view source on GitHub ↗

** translate a relative initial string position ** (negative means back from end): clip result to [1, inf). ** The length of any string in Lua must fit in a lua_Integer, ** so there are no overflows in the casts. ** The inverted comparison avoids a possible overflow ** computing '-pos'. */

Source from the content-addressed store, hash-verified

69** computing '-pos'.
70*/
71static size_t posrelatI (lua_Integer pos, size_t len) {
72 if (pos > 0)
73 return (size_t)pos;
74 else if (pos == 0)
75 return 1;
76 else if (pos < -(lua_Integer)len) /* inverted comparison */
77 return 1; /* clip to 1 */
78 else return len + (size_t)pos + 1;
79}
80
81
82/*

Callers 5

str_subFunction · 0.85
str_byteFunction · 0.85
str_find_auxFunction · 0.85
gmatchFunction · 0.85
str_unpackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected