aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2013-05-25 23:47:08 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2013-05-25 23:47:08 +1000
commit0168d3feab947066c2e9cfba3140f0a24be1b5fc (patch)
tree83e06cf296964a1f3ab98d4da80c9c2b1640c446
parent1ae516e14d90899e931cd91ed9094e1e14c95df9 (diff)
downloadscintilla-mirror-0168d3feab947066c2e9cfba3140f0a24be1b5fc.tar.gz
Simplify copying text since it is now using a std::string so no need to
pre-allocate.
-rw-r--r--src/Editor.cxx41
1 files changed, 12 insertions, 29 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 6d833c5d2..8081dcdd6 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -6015,45 +6015,28 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) {
std::string text = RangeText(start, end);
if (pdoc->eolMode != SC_EOL_LF)
- text.append("\r");
+ text.push_back('\r');
if (pdoc->eolMode != SC_EOL_CR)
- text.append("\n");
- ss->Copy(text.c_str(), static_cast<int>(text.length() + 1),
- pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, true);
+ text.push_back('\n');
+ ss->Copy(text, pdoc->dbcsCodePage,
+ vs.styles[STYLE_DEFAULT].characterSet, false, true);
}
} else {
- int delimiterLength = 0;
- if (sel.selType == Selection::selRectangle) {
- if (pdoc->eolMode == SC_EOL_CRLF) {
- delimiterLength = 2;
- } else {
- delimiterLength = 1;
- }
- }
- size_t size = sel.Length() + delimiterLength * sel.Count();
- std::string text(size+1, '\0');
- int j = 0;
+ std::string text;
std::vector<SelectionRange> rangesInOrder = sel.RangesCopy();
if (sel.selType == Selection::selRectangle)
std::sort(rangesInOrder.begin(), rangesInOrder.end());
for (size_t r=0; r<rangesInOrder.size(); r++) {
SelectionRange current = rangesInOrder[r];
- for (int i = current.Start().Position();
- i < current.End().Position();
- i++) {
- text[j++] = pdoc->CharAt(i);
- }
+ text.append(RangeText(current.Start().Position(), current.End().Position()));
if (sel.selType == Selection::selRectangle) {
- if (pdoc->eolMode != SC_EOL_LF) {
- text[j++] = '\r';
- }
- if (pdoc->eolMode != SC_EOL_CR) {
- text[j++] = '\n';
- }
+ if (pdoc->eolMode != SC_EOL_LF)
+ text.push_back('\r');
+ if (pdoc->eolMode != SC_EOL_CR)
+ text.push_back('\n');
}
}
- text[size] = '\0';
- ss->Copy(&text[0], static_cast<int>(size + 1), pdoc->dbcsCodePage,
+ ss->Copy(text, pdoc->dbcsCodePage,
vs.styles[STYLE_DEFAULT].characterSet, sel.IsRectangular(), sel.selType == Selection::selLines);
}
}
@@ -6063,7 +6046,7 @@ void Editor::CopyRangeToClipboard(int start, int end) {
end = pdoc->ClampPositionIntoDocument(end);
SelectionText selectedText;
std::string text = RangeText(start, end);
- selectedText.Copy(text.c_str(), end - start + 1,
+ selectedText.Copy(text,
pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false);
CopyToClipboard(selectedText);
}