Skip to content

Commit 54e6e40

Browse files
committed
More adoption of CharCode
1 parent dabbf52 commit 54e6e40

7 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/vs/base/common/charCode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212
*/
1313
export const enum CharCode {
1414
Null = 0,
15+
/**
16+
* The `\t` character.
17+
*/
1518
Tab = 9,
19+
/**
20+
* The `\n` character.
21+
*/
1622
LineFeed = 10,
23+
/**
24+
* The `\r` character.
25+
*/
1726
CarriageReturn = 13,
1827
Space = 32,
1928
/**

src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as strings from 'vs/base/common/strings';
88
import {WrappingIndent} from 'vs/editor/common/editorCommon';
99
import {PrefixSumComputer} from 'vs/editor/common/viewModel/prefixSumComputer';
1010
import {ILineMapperFactory, ILineMapping, OutputPosition} from 'vs/editor/common/viewModel/splitLinesCollection';
11+
import {CharCode} from 'vs/base/common/charCode';
1112
import {CharacterClassifier} from 'vs/editor/common/core/characterClassifier';
1213

1314
const enum CharacterClass {
@@ -85,15 +86,14 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
8586

8687
let wrappedTextIndentVisibleColumn = 0;
8788
let wrappedTextIndent = '';
88-
const TAB_CHAR_CODE = '\t'.charCodeAt(0);
8989

9090
let firstNonWhitespaceIndex = -1;
9191
if (hardWrappingIndent !== WrappingIndent.None) {
9292
firstNonWhitespaceIndex = strings.firstNonWhitespaceIndex(lineText);
9393
if (firstNonWhitespaceIndex !== -1) {
9494
wrappedTextIndent = lineText.substring(0, firstNonWhitespaceIndex);
9595
for (let i = 0; i < firstNonWhitespaceIndex; i++) {
96-
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, lineText.charCodeAt(i) === TAB_CHAR_CODE, 1);
96+
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, lineText.charCodeAt(i) === CharCode.Tab, 1);
9797
}
9898
if (hardWrappingIndent === WrappingIndent.Indent) {
9999
wrappedTextIndent += '\t';
@@ -125,7 +125,7 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
125125
// but the character at `i` might not fit
126126

127127
let charCode = lineText.charCodeAt(i);
128-
let charCodeIsTab = (charCode === TAB_CHAR_CODE);
128+
let charCodeIsTab = (charCode === CharCode.Tab);
129129
let charCodeClass = classifier.get(charCode);
130130

131131
if (charCodeClass === CharacterClass.BREAK_BEFORE) {

src/vs/editor/contrib/comment/common/lineCommentCommand.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
1313
import {ICommentsConfiguration} from 'vs/editor/common/modes';
1414
import {BlockCommentCommand} from './blockCommentCommand';
1515
import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry';
16+
import {CharCode} from 'vs/base/common/charCode';
1617

1718
export interface IInsertionPoint {
1819
ignore: boolean;
@@ -114,7 +115,6 @@ export class LineCommentCommand implements editorCommon.ICommand {
114115
lineNumber:number,
115116
shouldRemoveComments:boolean,
116117
lineContent: string,
117-
_space = ' '.charCodeAt(0),
118118
onlyWhitespaceLines = true;
119119

120120
if (type === Type.Toggle) {
@@ -162,7 +162,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
162162

163163
if (shouldRemoveComments) {
164164
commentStrEndOffset = lineContentStartOffset + lineData.commentStrLength;
165-
if (commentStrEndOffset < lineContent.length && lineContent.charCodeAt(commentStrEndOffset) === _space) {
165+
if (commentStrEndOffset < lineContent.length && lineContent.charCodeAt(commentStrEndOffset) === CharCode.Space) {
166166
lineData.commentStrLength += 1;
167167
}
168168
}
@@ -414,8 +414,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
414414
lineContent: string,
415415
j: number,
416416
lenJ: number,
417-
currentVisibleColumn: number,
418-
_tab = '\t'.charCodeAt(0);
417+
currentVisibleColumn: number;
419418

420419
for (i = 0, len = lines.length; i < len; i++) {
421420
if (lines[i].ignore) {
@@ -426,7 +425,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
426425

427426
currentVisibleColumn = 0;
428427
for (j = 0, lenJ = lines[i].commentStrOffset; currentVisibleColumn < minVisibleColumn && j < lenJ; j++) {
429-
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === _tab, 1);
428+
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === CharCode.Tab, 1);
430429
}
431430

432431
if (currentVisibleColumn < minVisibleColumn) {
@@ -445,7 +444,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
445444

446445
currentVisibleColumn = 0;
447446
for (j = 0, lenJ = lines[i].commentStrOffset; currentVisibleColumn < minVisibleColumn && j < lenJ; j++) {
448-
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === _tab, 1);
447+
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === CharCode.Tab, 1);
449448
}
450449

451450
if (currentVisibleColumn > minVisibleColumn) {

src/vs/editor/node/model/modelBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {DefaultEndOfLine, ITextModelCreationOptions, ITextModelResolvedOptions,
1010
import * as strings from 'vs/base/common/strings';
1111
import {guessIndentation} from 'vs/editor/common/model/indentationGuesser';
1212
import {TPromise} from 'vs/base/common/winjs.base';
13+
import {CharCode} from 'vs/base/common/charCode';
1314

1415
export class ModelBuilderResult {
1516
rawText: IRawText;
@@ -162,7 +163,7 @@ export class ModelBuilder {
162163
if (this.leftoverEndsInCR) {
163164
chunk = '\r' + chunk;
164165
}
165-
if (chunk.charCodeAt(chunk.length - 1) === 13 /*\r*/) {
166+
if (chunk.charCodeAt(chunk.length - 1) === CharCode.CarriageReturn) {
166167
this.leftoverEndsInCR = true;
167168
chunk = chunk.substr(0, chunk.length - 1);
168169
} else {

src/vs/editor/test/common/model/editableTextModelAuto.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Position} from 'vs/editor/common/core/position';
88
import {Range} from 'vs/editor/common/core/range';
99
import {IIdentifiedSingleEditOperation} from 'vs/editor/common/editorCommon';
1010
import {testApplyEditsWithSyncedModels} from 'vs/editor/test/common/model/editableTextModelTestUtils';
11+
import {CharCode} from 'vs/base/common/charCode';
1112

1213
const GENERATE_TESTS = false;
1314

@@ -142,7 +143,7 @@ function getRandomString(minLength: number, maxLength: number): string {
142143
let length = getRandomInt(minLength, maxLength);
143144
let r = '';
144145
for (let i = 0; i < length; i++) {
145-
r += String.fromCharCode(getRandomInt('a'.charCodeAt(0), 'z'.charCodeAt(0)));
146+
r += String.fromCharCode(getRandomInt(CharCode.a, CharCode.z));
146147
}
147148
return r;
148149
}

src/vs/editor/test/node/model/modelBuilderAuto.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
import {testModelBuilder, testDifferentHash} from 'vs/editor/test/node/model/modelBuilder.test';
8+
import {CharCode} from 'vs/base/common/charCode';
89

910
const GENERATE_TESTS = false;
1011

@@ -44,7 +45,7 @@ function getRandomString(minLength: number, maxLength: number): string {
4445
let length = getRandomInt(minLength, maxLength);
4546
let r = '';
4647
for (let i = 0; i < length; i++) {
47-
r += String.fromCharCode(getRandomInt('a'.charCodeAt(0), 'z'.charCodeAt(0)));
48+
r += String.fromCharCode(getRandomInt(CharCode.a, CharCode.z));
4849
}
4950
return r;
5051
}

src/vs/languages/html/common/html.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {ICompatWorkerService, CompatWorkerAttr} from 'vs/editor/common/services/
2222
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
2323
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
2424
import {IHTMLConfiguration} from 'vs/languages/html/common/html.contribution';
25+
import {CharCode} from 'vs/base/common/charCode';
2526

2627
export { htmlTokenTypes }; // export to be used by Razor. We are the main module, so Razor should get it from us.
2728
export { EMPTY_ELEMENTS }; // export to be used by Razor. We are the main module, so Razor should get it from us.
@@ -115,7 +116,7 @@ export class State extends AbstractState {
115116
break;
116117

117118
case States.Content:
118-
if (stream.advanceIfCharCode2('<'.charCodeAt(0))) {
119+
if (stream.advanceIfCharCode2(CharCode.LessThan)) {
119120
if (!stream.eos() && stream.peek() === '!') {
120121
if (stream.advanceIfString2('!--')) {
121122
this.kind = States.WithinComment;
@@ -126,7 +127,7 @@ export class State extends AbstractState {
126127
return { type: htmlTokenTypes.DELIM_DOCTYPE, dontMergeWithPrev: true };
127128
}
128129
}
129-
if (stream.advanceIfCharCode2('/'.charCodeAt(0))) {
130+
if (stream.advanceIfCharCode2(CharCode.Slash)) {
130131
this.kind = States.OpeningEndTag;
131132
return { type: htmlTokenTypes.DELIM_END, dontMergeWithPrev: true };
132133
}
@@ -183,7 +184,7 @@ export class State extends AbstractState {
183184
this.kind = States.Content;
184185
return { type: htmlTokenTypes.DELIM_START, dontMergeWithPrev: true };
185186
}
186-
if (stream.advanceIfCharCode2('>'.charCodeAt(0))) {
187+
if (stream.advanceIfCharCode2(CharCode.GreaterThan)) {
187188
if (tagsEmbeddingContent.indexOf(this.lastTagName) !== -1) {
188189
this.kind = States.WithinEmbeddedContent;
189190
return { type: htmlTokenTypes.DELIM_START, dontMergeWithPrev: true };
@@ -202,7 +203,7 @@ export class State extends AbstractState {
202203
return { type: '' };
203204
}
204205

205-
if (stream.advanceIfCharCode2('='.charCodeAt(0))) {
206+
if (stream.advanceIfCharCode2(CharCode.Equals)) {
206207
this.kind = States.AttributeValue;
207208
return { type: htmlTokenTypes.DELIM_ASSIGN };
208209
} else {

0 commit comments

Comments
 (0)