aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexlib/SparseState.h
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2011-02-13 10:08:08 +1100
committernyamatongwe <devnull@localhost>2011-02-13 10:08:08 +1100
commite75470ad1d39842c12b407820c2886f7ae035ab9 (patch)
tree4668e914b8b3a00d69e6239c065edea184df400a /lexlib/SparseState.h
parent7cf9bf29bb2e51ca412e86b4a73cc5e4545115af (diff)
downloadscintilla-mirror-e75470ad1d39842c12b407820c2886f7ae035ab9.tar.gz
Added Merge method to SparseState to make it possible to detect significant
changes in lexers which will require styling beyond the end of the current range.
Diffstat (limited to 'lexlib/SparseState.h')
-rw-r--r--lexlib/SparseState.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/lexlib/SparseState.h b/lexlib/SparseState.h
index c84fdc861..bd74ecef2 100644
--- a/lexlib/SparseState.h
+++ b/lexlib/SparseState.h
@@ -28,6 +28,7 @@ class SparseState {
return (position == other.position) && (value == other.value);
}
};
+ int positionFirst;
typedef std::vector<State> stateVector;
stateVector states;
@@ -37,6 +38,9 @@ class SparseState {
}
public:
+ SparseState(int positionFirst_=-1) {
+ positionFirst = positionFirst_;
+ }
void Set(int position, T value) {
Delete(position);
if ((states.size() == 0) || (value != states[states.size()-1].value)) {
@@ -69,6 +73,34 @@ public:
size_t size() const {
return states.size();
}
+
+ // Returns true if Merge caused a significant change
+ bool Merge(const SparseState<T> &other, int ignoreAfter) {
+ // Changes caused beyond ignoreAfter are not significant
+ Delete(ignoreAfter+1);
+
+ bool different = true;
+ bool changed = false;
+ typename stateVector::iterator low = Find(other.positionFirst);
+ if (static_cast<size_t>(states.end() - low) == other.states.size()) {
+ // Same number in other as after positionFirst in this
+ different = !std::equal(low, states.end(), other.states.begin());
+ }
+ if (different) {
+ if (low != states.end()) {
+ states.erase(low, states.end());
+ changed = true;
+ }
+ typename stateVector::const_iterator startOther = other.states.begin();
+ if (!states.empty() && states.back().value == startOther->value)
+ startOther++;
+ if (startOther != other.states.end()) {
+ states.insert(states.end(), startOther, other.states.end());
+ changed = true;
+ }
+ }
+ return changed;
+ }
};
#ifdef SCI_NAMESPACE