diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Document.cxx | 22 | ||||
-rw-r--r-- | src/Document.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index 80f306c1a..d5a677499 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1232,6 +1232,28 @@ char *Document::TransformLineEnds(int *pLenOut, const char *s, size_t len, int e return dest; } +std::string Document::TransformLineEnds(const char *s, size_t len, int eolModeWanted) { + std::string dest; + for (size_t i = 0; (i < len) && (s[i]); i++) { + if (s[i] == '\n' || s[i] == '\r') { + if (eolModeWanted == SC_EOL_CR) { + dest.push_back('\r'); + } else if (eolModeWanted == SC_EOL_LF) { + dest.push_back('\n'); + } else { // eolModeWanted == SC_EOL_CRLF + dest.push_back('\r'); + dest.push_back('\n'); + } + if ((s[i] == '\r') && (i+1 < len) && (s[i+1] == '\n')) { + i++; + } + } else { + dest.push_back(s[i]); + } + } + return dest; +} + void Document::ConvertLineEnds(int eolModeSet) { UndoGroup ug(this); diff --git a/src/Document.h b/src/Document.h index cb2f00d7a..b14375acc 100644 --- a/src/Document.h +++ b/src/Document.h @@ -316,6 +316,7 @@ public: 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); + static std::string TransformLineEnds(const char *s, size_t len, int eolModeWanted); void ConvertLineEnds(int eolModeSet); void SetReadOnly(bool set) { cb.SetReadOnly(set); } bool IsReadOnly() { return cb.IsReadOnly(); } |