Merge pull request #127 from g4z3r/codestyle

foreach loops pt. 2
This commit is contained in:
Vadim Lopatin 2015-12-19 22:11:58 +03:00
commit 1b4a34b68d
2 changed files with 22 additions and 21 deletions

View File

@ -176,7 +176,7 @@ class DMLSyntaxSupport : SyntaxSupport {
} }
protected bool isLineComment(dstring s) { protected bool isLineComment(dstring s) {
for (int i = 0; i < cast(int)s.length - 1; i++) { foreach(i; 0 .. s.length - 1) {
if (s[i] == '/' && s[i + 1] == '/') if (s[i] == '/' && s[i + 1] == '/')
return true; return true;
else if (s[i] != ' ' && s[i] != '\t') else if (s[i] != ' ' && s[i] != '\t')
@ -189,7 +189,7 @@ class DMLSyntaxSupport : SyntaxSupport {
dchar[] res; dchar[] res;
int x = 0; int x = 0;
bool commented = false; bool commented = false;
for (int i = 0; i < s.length; i++) { foreach(i; 0 .. s.length) {
dchar ch = s[i]; dchar ch = s[i];
if (ch == '\t') { if (ch == '\t') {
int newX = (x + _content.tabSize) / _content.tabSize * _content.tabSize; int newX = (x + _content.tabSize) / _content.tabSize * _content.tabSize;
@ -232,7 +232,7 @@ class DMLSyntaxSupport : SyntaxSupport {
/// remove single line comment from beginning of line /// remove single line comment from beginning of line
protected dstring uncommentLine(dstring s) { protected dstring uncommentLine(dstring s) {
int p = -1; int p = -1;
for (int i = 0; i < cast(int)s.length - 1; i++) { foreach(int i; 0 .. cast(int)s.length - 1) {
if (s[i] == '/' && s[i + 1] == '/') { if (s[i] == '/' && s[i + 1] == '/') {
p = i; p = i;
break; break;
@ -241,7 +241,7 @@ class DMLSyntaxSupport : SyntaxSupport {
if (p < 0) if (p < 0)
return s; return s;
s = s[0..p] ~ s[p + 2 .. $]; s = s[0..p] ~ s[p + 2 .. $];
for (int i = 0; i < s.length; i++) { foreach(i; 0 .. s.length) {
if (s[i] != ' ' && s[i] != '\t') { if (s[i] != ' ' && s[i] != '\t') {
return s; return s;
} }
@ -353,7 +353,7 @@ class DMLSyntaxSupport : SyntaxSupport {
bool hasNonEmpty = false; bool hasNonEmpty = false;
dstring[] srctext; dstring[] srctext;
dstring[] dsttext; dstring[] dsttext;
for (int i = 0; i < lineCount; i++) { foreach(i; 0 .. lineCount) {
int lineIndex = r.start.line + i; int lineIndex = r.start.line + i;
dstring s = content.line(lineIndex); dstring s = content.line(lineIndex);
srctext ~= s; srctext ~= s;
@ -372,7 +372,7 @@ class DMLSyntaxSupport : SyntaxSupport {
minLeftX = 0; minLeftX = 0;
if (hasNoComments || !hasComments) { if (hasNoComments || !hasComments) {
// comment // comment
for (int i = 0; i < lineCount; i++) { foreach(i; 0 .. lineCount) {
dsttext ~= commentLine(srctext[i], minLeftX); dsttext ~= commentLine(srctext[i], minLeftX);
} }
if (!noEolAtEndOfRange) if (!noEolAtEndOfRange)
@ -381,7 +381,7 @@ class DMLSyntaxSupport : SyntaxSupport {
_content.performOperation(op, source); _content.performOperation(op, source);
} else { } else {
// uncomment // uncomment
for (int i = 0; i < lineCount; i++) { foreach(i; 0 .. lineCount) {
dsttext ~= uncommentLine(srctext[i]); dsttext ~= uncommentLine(srctext[i]);
} }
if (!noEolAtEndOfRange) if (!noEolAtEndOfRange)
@ -428,7 +428,7 @@ class DMLSyntaxSupport : SyntaxSupport {
if (startToken.range == endToken.range && startToken.token.isMultilineComment) { if (startToken.range == endToken.range && startToken.token.isMultilineComment) {
TextRange range = startToken.range; TextRange range = startToken.range;
dstring[] dsttext; dstring[] dsttext;
for (int i = range.start.line; i <= range.end.line; i++) { foreach(i; range.start.line .. range.end.line + 1) {
dstring s = content.line(i); dstring s = content.line(i);
int charsRemoved = 0; int charsRemoved = 0;
if (i == range.start.line) { if (i == range.start.line) {
@ -436,7 +436,7 @@ class DMLSyntaxSupport : SyntaxSupport {
if (i == range.end.line) if (i == range.end.line)
maxp = range.end.pos - 2; maxp = range.end.pos - 2;
charsRemoved = 2; charsRemoved = 2;
for (int j = range.start.pos + charsRemoved; j < maxp; j++) { foreach(j; range.start.pos + charsRemoved .. maxp) {
if (s[j] != s[j - 1]) if (s[j] != s[j - 1])
break; break;
charsRemoved++; charsRemoved++;
@ -482,7 +482,7 @@ class DMLSyntaxSupport : SyntaxSupport {
} }
} }
dstring[] dsttext; dstring[] dsttext;
for (int i = srcrange.start.line; i <= srcrange.end.line; i++) { foreach(i; srcrange.start.line .. srcrange.end.line + 1) {
dstring s = content.line(i); dstring s = content.line(i);
int charsAdded = 0; int charsAdded = 0;
if (i == srcrange.start.line) { if (i == srcrange.start.line) {
@ -531,10 +531,10 @@ class DMLSyntaxSupport : SyntaxSupport {
uint newLine = token.range.start.line; uint newLine = token.range.start.line;
// fill with category // fill with category
for (int i = tokenLine; i <= newLine; i++) { foreach(int i; tokenLine .. newLine + 1) {
int start = i > tokenLine ? 0 : tokenPos; int start = i > tokenLine ? 0 : tokenPos;
int end = i < newLine ? cast(int)lines[i].length : newPos; int end = i < newLine ? cast(int)lines[i].length : newPos;
for (int j = start; j < end; j++) { foreach(j; start .. end) {
if (j < _props[i].length) { if (j < _props[i].length) {
_props[i][j] = category; _props[i][j] = category;
} }
@ -542,30 +542,31 @@ class DMLSyntaxSupport : SyntaxSupport {
} }
// handle token - convert to category // handle token - convert to category
switch(token.token.type) { switch(token.token.type) with(TokenType)
case TokenType.comment: {
case comment:
category = TokenCategory.Comment; category = TokenCategory.Comment;
break; break;
case TokenType.ident: case ident:
if (isWidgetClassName(token.token.text)) if (isWidgetClassName(token.token.text))
category = TokenCategory.Identifier_Class; category = TokenCategory.Identifier_Class;
else else
category = TokenCategory.Identifier; category = TokenCategory.Identifier;
break; break;
case TokenType.str: case str:
category = TokenCategory.String; category = TokenCategory.String;
break; break;
case TokenType.integer: case integer:
category = TokenCategory.Integer; category = TokenCategory.Integer;
break; break;
case TokenType.floating: case floating:
category = TokenCategory.Float; category = TokenCategory.Float;
break; break;
case TokenType.error: case error:
category = TokenCategory.Error; category = TokenCategory.Error;
break; break;
default: default:
if (token.token.type >= TokenType.colon) if (token.token.type >= colon)
category = TokenCategory.Op; category = TokenCategory.Op;
else else
category = 0; category = 0;

View File

@ -344,7 +344,7 @@ class Tokenizer {
protected ref const(Token) parseHex(int prefixLen) { protected ref const(Token) parseHex(int prefixLen) {
dchar ch = 0; dchar ch = 0;
for (int i = 0; i < prefixLen; i++) foreach(i; 0 .. prefixLen)
ch = skipChar(); ch = skipChar();
uint n = decodeHexDigit(ch); uint n = decodeHexDigit(ch);