What I'm trying to find:
Information I have:
How should I go about finding this function's line number in the file?
My current thoughts:
I'm using Golang for the back-end service which I believe will execute this functionality. Though I also have a front-end in JavaScript which I can leverage to help if needed.
Would something like counting newline characters be good enough, or are you looking into something more tweaky?
You could just start counting newlines \n
until you reach the byte index. The line number is the number of newline characters.
Assuming that you have the contents of the file p
as type []byte
and the byte index of the function as int i
, then bytes.Count(p[:i], []byte{'\n'}) + 1
returns the line number for the function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.