From c6b6aefd36d49aaf873bca20175b929f828589df Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 28 Mar 2013 18:33:13 +0100 Subject: String::get_coord() calculates line and column of a string position * use to get line and column into a stack frame --- src/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index d0dfd84..d6b8ab3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,6 +111,29 @@ Interface::process_notify(SCNotification *notify) #endif } +void +String::get_coord(const gchar *str, gint pos, + gint &line, gint &column) +{ + line = column = 1; + + for (gint i = 0; i < pos; i++) { + switch (str[i]) { + case '\r': + if (str[i+1] == '\n') + i++; + /* fall through */ + case '\n': + line++; + column = 1; + break; + default: + column++; + break; + } + } +} + #ifdef G_OS_WIN32 /* -- cgit v1.2.3