aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Editor.cxx
diff options
context:
space:
mode:
authorVicente <unknown>2017-03-06 14:54:51 +1100
committerVicente <unknown>2017-03-06 14:54:51 +1100
commit069d842392251d56167e08c005d51fa9ccc12147 (patch)
tree51d5396606bffade50d291781d5227cc404cd87d /src/Editor.cxx
parent41c0c0f7083c0ddde020cf847cddef7894f2ded4 (diff)
downloadscintilla-mirror-069d842392251d56167e08c005d51fa9ccc12147.tar.gz
Use several C++11 features as examples so problems with these features are seen.
Features used are move constructor, unique_ptr, deleted functions, enum class, lambda expression, and range for loop.
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r--src/Editor.cxx33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index cee9cebd7..e5fbc69be 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -816,7 +816,7 @@ void Editor::MovedCaret(SelectionPosition newPos, SelectionPosition previousPos,
if (ensureVisible) {
// In case in need of wrapping to ensure DisplayFromDoc works.
if (currentLine >= wrapPending.start)
- WrapLines(wsAll);
+ WrapLines(WrapScope::wsAll);
XYScrollPosition newXY = XYScrollToMakeVisible(
SelectionRange(posDrag.IsValid() ? posDrag : newPos), xysDefault);
if (previousPos.IsValid() && (newXY.xOffset == xOffset)) {
@@ -1476,7 +1476,7 @@ bool Editor::WrapOneLine(Surface *surface, int lineToWrap) {
// wsVisible: wrap currently visible lines
// wsIdle: wrap one page + 100 lines
// Return true if wrapping occurred.
-bool Editor::WrapLines(enum wrapScope ws) {
+bool Editor::WrapLines(WrapScope ws) {
int goodTopLine = topLine;
bool wrapOccurred = false;
if (!Wrapping()) {
@@ -1494,14 +1494,14 @@ bool Editor::WrapLines(enum wrapScope ws) {
wrapPending.start = std::min(wrapPending.start, pdoc->LinesTotal());
if (!SetIdle(true)) {
// Idle processing not supported so full wrap required.
- ws = wsAll;
+ ws = WrapScope::wsAll;
}
// Decide where to start wrapping
int lineToWrap = wrapPending.start;
int lineToWrapEnd = std::min(wrapPending.end, pdoc->LinesTotal());
const int lineDocTop = cs.DocFromDisplay(topLine);
const int subLineTop = topLine - cs.DisplayFromDoc(lineDocTop);
- if (ws == wsVisible) {
+ if (ws == WrapScope::wsVisible) {
lineToWrap = Platform::Clamp(lineDocTop-5, wrapPending.start, pdoc->LinesTotal());
// Priority wrap to just after visible area.
// Since wrapping could reduce display lines, treat each
@@ -1518,7 +1518,7 @@ bool Editor::WrapLines(enum wrapScope ws) {
// Currently visible text does not need wrapping
return false;
}
- } else if (ws == wsIdle) {
+ } else if (ws == WrapScope::wsIdle) {
lineToWrapEnd = lineToWrap + LinesOnScreen() + 100;
}
const int lineEndNeedWrap = std::min(wrapPending.end, pdoc->LinesTotal());
@@ -1711,7 +1711,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
}
// Wrap the visible lines if needed.
- if (WrapLines(wsVisible)) {
+ if (WrapLines(WrapScope::wsVisible)) {
// The wrapping process has changed the height of some lines so
// abandon this paint for a complete repaint.
if (AbandonPaint()) {
@@ -1872,10 +1872,6 @@ void Editor::FilterSelections() {
}
}
-static bool cmpSelPtrs(const SelectionRange *a, const SelectionRange *b) {
- return *a < *b;
-}
-
// AddCharUTF inserts an array of bytes which may or may not be in UTF-8.
void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
FilterSelections();
@@ -1888,7 +1884,8 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
selPtrs.push_back(&sel.Range(r));
}
// Order selections by position in document.
- std::sort(selPtrs.begin(), selPtrs.end(), cmpSelPtrs);
+ std::sort(selPtrs.begin(), selPtrs.end(),
+ [](const SelectionRange *a, const SelectionRange *b) {return *a < *b;});
// Loop in reverse to avoid disturbing positions of selections yet to be processed.
for (std::vector<SelectionRange *>::reverse_iterator rit = selPtrs.rbegin();
@@ -4029,15 +4026,15 @@ long Editor::SearchText(
std::string Editor::CaseMapString(const std::string &s, int caseMapping) {
std::string ret(s);
- for (size_t i=0; i<ret.size(); i++) {
+ for (char &ch : ret) {
switch (caseMapping) {
case cmUpper:
- if (ret[i] >= 'a' && ret[i] <= 'z')
- ret[i] = static_cast<char>(ret[i] - 'a' + 'A');
+ if (ch >= 'a' && ch <= 'z')
+ ch = static_cast<char>(ch - 'a' + 'A');
break;
case cmLower:
- if (ret[i] >= 'A' && ret[i] <= 'Z')
- ret[i] = static_cast<char>(ret[i] - 'A' + 'a');
+ if (ch >= 'A' && ch <= 'Z')
+ ch = static_cast<char>(ch - 'A' + 'a');
break;
}
}
@@ -4934,7 +4931,7 @@ bool Editor::Idle() {
if (needWrap) {
// Wrap lines during idle.
- WrapLines(wsIdle);
+ WrapLines(WrapScope::wsIdle);
// No more wrapping
needWrap = wrapPending.NeedsWrap();
} else if (needIdleStyling) {
@@ -5373,7 +5370,7 @@ void Editor::EnsureLineVisible(int lineDoc, bool enforcePolicy) {
// In case in need of wrapping to ensure DisplayFromDoc works.
if (lineDoc >= wrapPending.start)
- WrapLines(wsAll);
+ WrapLines(WrapScope::wsAll);
if (!cs.GetVisible(lineDoc)) {
// Back up to find a non-blank line