aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.cxx
diff options
context:
space:
mode:
authornyamatongwe <unknown>2003-11-01 11:40:37 +0000
committernyamatongwe <unknown>2003-11-01 11:40:37 +0000
commit1cb0c37b721cfa4909a260a48aa82999f61cacc0 (patch)
treed176377cdf80118ee4a7fc9363f14492317c5fb3 /src/Document.cxx
parent40780f412ede5e9a0aee4378d22909172ad3ace3 (diff)
downloadscintilla-mirror-1cb0c37b721cfa4909a260a48aa82999f61cacc0.tar.gz
Patch from Roy Wood to allow changing the characters that are in the
whitespace class.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r--src/Document.cxx53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 130a920e1..53d01d2b8 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -50,7 +50,7 @@ Document::Document() {
stylingBits = 5;
stylingBitsMask = 0x1F;
stylingMask = 0;
- SetWordChars(0);
+ SetDefaultCharClasses();
endStyled = 0;
styleClock = 0;
enteredCount = 0;
@@ -1119,29 +1119,74 @@ void Document::ChangeCase(Range r, bool makeUpperCase) {
}
}
-void Document::SetWordChars(unsigned char *chars) {
+
+void Document::SetDefaultCharClasses() {
int ch;
+ // Initialize all char classes to default values
for (ch = 0; ch < 256; ch++) {
if (ch == '\r' || ch == '\n')
charClass[ch] = ccNewLine;
else if (ch < 0x20 || ch == ' ')
charClass[ch] = ccSpace;
+ else if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ charClass[ch] = ccWord;
else
charClass[ch] = ccPunctuation;
}
+}
+
+void Document::SetCharClasses(unsigned char *chars, charClassification newCharClass) {
+ int ch;
+ // The old code always reset all chars to their default charClass and then applied the new charClass
+ // to a specific set of chars, so the most reasonable way to honour the old promise is to reset all chars
+ // that currently are of class newCharClass, and then apply the newCharClass to any specified chars. Remember,
+ // the point is to allow the caller to explicitly define all chars which are to be of class newCharClass.
+ // The only other tricky thing is that the old promise was that if the user passes in NULL for the chars
+ // parameter, we are supposed to reset all chars that default to newCharClass, which is not the
+ // same as resetting the char class of any chars that are currently of newCharClass (user might have altered
+ // some char classes from their default class).
+
+ // If all of that seems a little complex, well, it is. If we could break the old promise and make some
+ // simplifying assumptions, this would all be waaaaay simpler. This way though, Scintilla will do the right
+ // thing if lots of changes of charClass are applied during the lifetime of the Document object (not very likely,
+ // but as long as I'm doing this, might as well get it right).
+
+ // So, first reset the char class of any chars that are currently of the class newCharClass
+ for (ch = 0; ch < 256; ch++) {
+ if (charClass[ch] == newCharClass) {
+ if (ch == '\r' || ch == '\n')
+ charClass[ch] = ccNewLine;
+ else if (ch < 0x20 || ch == ' ')
+ charClass[ch] = ccSpace;
+ else if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ charClass[ch] = ccWord;
+ else
+ charClass[ch] = ccPunctuation;
+ }
+ }
+
+ // Next, apply the newCharClass to the specifed chars
if (chars) {
while (*chars) {
- charClass[*chars] = ccWord;
+ charClass[*chars] = newCharClass;
chars++;
}
} else {
+ // If user passed NULL for chars, reinitialize only the specified class of chars
for (ch = 0; ch < 256; ch++) {
- if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ if ((ch == '\r' || ch == '\n') && newCharClass == ccNewLine)
+ charClass[ch] = ccNewLine;
+ else if ((ch < 0x20 || ch == ' ') && newCharClass == ccSpace)
+ charClass[ch] = ccSpace;
+ else if ((ch >= 0x80 || isalnum(ch) || ch == '_') && newCharClass == ccWord)
charClass[ch] = ccWord;
+ else if (newCharClass == ccPunctuation)
+ charClass[ch] = ccPunctuation;
}
}
}
+
void Document::SetStylingBits(int bits) {
stylingBits = bits;
stylingBitsMask = 0;