fix crashes

This commit is contained in:
Vadim Lopatin 2015-02-12 21:36:17 +03:00
parent fd570d2358
commit b597326363
2 changed files with 22 additions and 11 deletions

View File

@ -1375,6 +1375,15 @@ struct StringAppender {
buf[len .. len + s.length] = s;
len += s.length;
}
void append(dchar ch) {
if (len + 1 > buf.length) {
uint newsize = cast(uint)(buf.length * 2);
if (newsize < 128)
newsize = 128;
buf.length = newsize;
}
buf[len++] = ch;
}
void reset() {
len = 0;
}
@ -1781,20 +1790,19 @@ class Tokenizer
return null;
}
protected Token processIdent() {
protected Token processIdent(dchar firstChar) {
_sharedIdentToken.setPos(_startLine, _startPos);
_identAppender.reset();
int startPos = _startPos;
int endPos = _len;
for (int i = startPos + 1; i < _len; i++) {
dchar ch = _lineText[i];
_identAppender.append(firstChar);
for (; _pos < _len; ) {
dchar ch = _lineText[_pos];
if (!isIdentMiddleChar(ch)) {
endPos = i;
break;
}
_identAppender.append(ch);
_pos++;
}
_pos = endPos;
_sharedIdentToken.setText(_lineText[startPos .. endPos]);
_sharedIdentToken.setText(_identAppender.get);
return _sharedIdentToken;
}
@ -2756,7 +2764,7 @@ class Tokenizer
return _sharedKeywordToken;
}
}
return processIdent();
return processIdent(ch);
}
OpCode op = detectOp(ch);
if (op != OpCode.NONE) {

View File

@ -649,8 +649,11 @@ class SimpleDSyntaxHighlighter : SyntaxHighlighter {
for (int i = tokenLine; i <= newLine; i++) {
int start = i > tokenLine ? 0 : tokenPos;
int end = i < newLine ? cast(int)lines[i].length : newPos;
for (int j = start; j < end; j++)
_props[i][j] = category;
for (int j = start; j < end; j++) {
if (j < _props[i].length) {
_props[i][j] = category;
}
}
}
// handle token - convert to category