From cd41ef6f518a4b76a4416f25cce062e305b3272e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 8 Dec 2012 00:37:13 +0000 Subject: [PATCH] Strip EOL characters from wxStyledTextCtrl::GetLineText() return value. For consistency with all the other wxTextCtrl-like classes, the value returned by this method must not include line terminator characters (like '\n'). Notice that Scintilla-specific GetLine() does still include them, for consistency with the Scintilla API itself. Closes #13646. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73140 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/stc/stc.h | 12 +++++++++++- src/stc/stc.h.in | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index ca27bc89f7..f71fe5f772 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -4629,7 +4629,17 @@ public: // --------------------------------------------- virtual int GetLineLength(long n) const { return GetLine(n).length(); } - virtual wxString GetLineText(long n) const { return GetLine(n); } + virtual wxString GetLineText(long lineNo) const + { + wxString text = GetLine(static_cast(lineNo)); + size_t lastNewLine = text.find_last_not_of(wxS("\r\n")); + + if ( lastNewLine != wxString::npos ) + text.erase(lastNewLine + 1); // remove trailing cr+lf + else + text.clear(); + return text; + } virtual int GetNumberOfLines() const { return GetLineCount(); } virtual bool IsModified() const { return GetModify(); } diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index abbfe19b2a..e4b3a05406 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -371,7 +371,17 @@ public: // --------------------------------------------- virtual int GetLineLength(long n) const { return GetLine(n).length(); } - virtual wxString GetLineText(long n) const { return GetLine(n); } + virtual wxString GetLineText(long lineNo) const + { + wxString text = GetLine(static_cast(lineNo)); + size_t lastNewLine = text.find_last_not_of(wxS("\r\n")); + + if ( lastNewLine != wxString::npos ) + text.erase(lastNewLine + 1); // remove trailing cr+lf + else + text.clear(); + return text; + } virtual int GetNumberOfLines() const { return GetLineCount(); } virtual bool IsModified() const { return GetModify(); } -- 2.45.2