MCPcopy Create free account
hub / github.com/numpy/numpy / find_position

Function find_position

tools/npy_tempita/__init__.py:765–774  ·  view source on GitHub ↗

Given a string and index, return (line, column)

(string, index, last_index, last_pos)

Source from the content-addressed store, hash-verified

763
764
765def find_position(string, index, last_index, last_pos):
766 """
767 Given a string and index, return (line, column)
768 """
769 lines = string.count('\n', last_index, index)
770 if lines > 0:
771 column = index - string.rfind('\n', last_index, index)
772 else:
773 column = last_pos[1] + (index - last_index)
774 return (last_pos[0] + lines, column)
775
776
777def parse(s, name=None, line_offset=0, delimiters=None):

Callers 1

lexFunction · 0.85

Calls 2

rfindMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected