* Given a location (a byte offset in the function source text), * return a line number. * * We expect that this is typically called for a sequence of increasing * location values, so optimize accordingly by tracking the endpoints * of the "current" line. */
| 538 | * of the "current" line. |
| 539 | */ |
| 540 | int |
| 541 | plpgsql_location_to_lineno(int location) |
| 542 | { |
| 543 | const char *loc; |
| 544 | |
| 545 | if (location < 0 || scanorig == NULL) |
| 546 | return 0; /* garbage in, garbage out */ |
| 547 | loc = scanorig + location; |
| 548 | |
| 549 | /* be correct, but not fast, if input location goes backwards */ |
| 550 | if (loc < cur_line_start) |
| 551 | location_lineno_init(); |
| 552 | |
| 553 | while (cur_line_end != NULL && loc > cur_line_end) |
| 554 | { |
| 555 | cur_line_start = cur_line_end + 1; |
| 556 | cur_line_num++; |
| 557 | cur_line_end = strchr(cur_line_start, '\n'); |
| 558 | } |
| 559 | |
| 560 | return cur_line_num; |
| 561 | } |
| 562 | |
| 563 | /* initialize or reset the state for plpgsql_location_to_lineno */ |
| 564 | static void |
nothing calls this directly
no test coverage detected