From 52d3985ffab11d1b35d50188bf13cc2182e3988a Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 26 Nov 2024 09:45:37 -0800 Subject: [PATCH] added getLineNumberAtCursor() method to ZString. --- ZString.cpp | 9 +++++++++ ZString.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/ZString.cpp b/ZString.cpp index 5f0b1ec..172c31d 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -575,4 +575,13 @@ namespace coreutils { return temp; } + int ZString::getLineNumberAtCursor() { + int line = 1; + while(cursor != data) + if(*cursor-- == '\n') + ++line; + return line; + } + + } diff --git a/ZString.h b/ZString.h index dc1436e..d870b95 100644 --- a/ZString.h +++ b/ZString.h @@ -438,6 +438,13 @@ namespace coreutils { /// ZString removeTrailingZeros(); + + /// + /// Returns the number of line termination characters + 1 based upon + /// the cursor position. + /// + + int getLineNumberAtCursor(); protected: char *data;