diff options
author | nyamatongwe <unknown> | 2013-05-04 23:38:19 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-05-04 23:38:19 +1000 |
commit | c37c824e3a9f0ef57c5cdd41a42834b55ed78b91 (patch) | |
tree | b709170bd7a00a7d56ace176bf2743f8ec99085f | |
parent | a06f5a50adf59e79f95b73d5db5a9f8e758f8af7 (diff) | |
download | scintilla-mirror-c37c824e3a9f0ef57c5cdd41a42834b55ed78b91.tar.gz |
Replacing raw pointers and allocations with std::vector and std::string.
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 36 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.cpp | 10 |
2 files changed, 20 insertions, 26 deletions
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index c7ec303ed..83512ba0b 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -979,30 +979,26 @@ void ListBoxImpl::SetList(const char *list, char separator, char typesep) // It is borrowed from the GTK implementation. Clear(); int count = strlen(list) + 1; - char *words = new char[count]; - if (words) { - memcpy(words, list, count); - char *startword = words; - char *numword = NULL; - int i = 0; - for (; words[i]; i++) { - if (words[i] == separator) { - words[i] = '\0'; - if (numword) - *numword = '\0'; - Append(startword, numword?atoi(numword + 1):-1); - startword = words + i + 1; - numword = NULL; - } else if (words[i] == typesep) { - numword = words + i; - } - } - if (startword) { + std::vector<char> words(list, list+count); + char *startword = words.data(); + char *numword = NULL; + int i = 0; + for (; words[i]; i++) { + if (words[i] == separator) { + words[i] = '\0'; if (numword) *numword = '\0'; Append(startword, numword?atoi(numword + 1):-1); + startword = words.data() + i + 1; + numword = NULL; + } else if (words[i] == typesep) { + numword = words.data() + i; } - delete []words; + } + if (startword) { + if (numword) + *numword = '\0'; + Append(startword, numword?atoi(numword + 1):-1); } } diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 03e3b42b3..8c6e89e60 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -339,9 +339,9 @@ void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode_) QString text = clipboard->text(clipboardMode_); QByteArray utext = BytesForDocument(text); int len = utext.length(); - char *dest = Document::TransformLineEnds(&len, utext, len, pdoc->eolMode); + std::string dest = Document::TransformLineEnds(utext, len, pdoc->eolMode); SelectionText selText; - selText.Set(dest, len, pdoc->dbcsCodePage, CharacterSetOfDocument(), isRectangular, false); + selText.Copy(dest.c_str(), dest.length(), pdoc->dbcsCodePage, CharacterSetOfDocument(), isRectangular, false); UndoGroup ug(pdoc); ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); @@ -763,12 +763,10 @@ void ScintillaQt::Drop(const Point &point, const QMimeData *data, bool move) bool rectangular = IsRectangularInMime(data); QByteArray bytes = BytesForDocument(text); int len = bytes.length(); - char *dest = Document::TransformLineEnds(&len, bytes, len, pdoc->eolMode); + std::string dest = Document::TransformLineEnds(bytes, len, pdoc->eolMode); SelectionPosition movePos = SPositionFromLocation(point, false, false, UserVirtualSpace()); - DropAt(movePos, dest, move, rectangular); - - delete []dest; + DropAt(movePos, dest.c_str(), move, rectangular); } |