From 706467b15ad45ab2653733eff7e3afdf3486b251 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 16 Nov 2011 10:43:52 +1100 Subject: Bug #3283519. CountCharacters added to count the number of characters between two positions. From Andrey Moskalyov. --- src/Document.cxx | 14 ++++++++++++++ src/Document.h | 1 + src/Editor.cxx | 3 +++ 3 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/Document.cxx b/src/Document.cxx index 86d5c6077..c721c88ff 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1094,6 +1094,20 @@ int Document::GetColumn(int pos) { return column; } +int Document::CountCharacters(int startPos, int endPos) { + startPos = MovePositionOutsideChar(startPos, 1, false); + endPos = MovePositionOutsideChar(endPos, -1, false); + int count = 0; + int i = startPos; + while (i < endPos) { + count++; + if (IsCrLf(i)) + i++; + i = NextPosition(i, 1); + } + return count; +} + int Document::FindColumn(int line, int column) { int position = LineStart(line); if ((line >= 0) && (line < LinesTotal())) { diff --git a/src/Document.h b/src/Document.h index bd8a58274..ec41603eb 100644 --- a/src/Document.h +++ b/src/Document.h @@ -303,6 +303,7 @@ public: void SetLineIndentation(int line, int indent); int GetLineIndentPosition(int line) const; int GetColumn(int position); + int CountCharacters(int startPos, int endPos); int FindColumn(int line, int column); void Indent(bool forwards, int lineBottom, int lineTop); static char *TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolModeWanted); diff --git a/src/Editor.cxx b/src/Editor.cxx index 4c647b61e..8c939fdb1 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -9259,6 +9259,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETTECHNOLOGY: return technology; + case SCI_COUNTCHARACTERS: + return pdoc->CountCharacters(wParam, lParam); + default: return DefWndProc(iMessage, wParam, lParam); } -- cgit v1.2.3