summaryrefslogtreecommitdiffstats
path: root/Parser/pegen.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r--Parser/pegen.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c
index ff02e88..cbceaae 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -18,12 +18,8 @@ _PyPegen_interactive_exit(Parser *p)
}
Py_ssize_t
-_PyPegen_byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset)
+_PyPegen_byte_offset_to_character_offset_raw(const char* str, Py_ssize_t col_offset)
{
- const char *str = PyUnicode_AsUTF8(line);
- if (!str) {
- return -1;
- }
Py_ssize_t len = strlen(str);
if (col_offset > len + 1) {
col_offset = len + 1;
@@ -93,6 +89,16 @@ _PyPegen_calculate_display_width(PyObject *line, Py_ssize_t character_offset)
return width;
}
+Py_ssize_t
+_PyPegen_byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset)
+{
+ const char *str = PyUnicode_AsUTF8(line);
+ if (!str) {
+ return -1;
+ }
+ return _PyPegen_byte_offset_to_character_offset_raw(str, col_offset);
+}
+
// Here, mark is the start of the node, while p->mark is the end.
// If node==NULL, they should be the same.
int