提交 54e6e40e 编写于 作者: A Alex Dima

More adoption of CharCode

上级 dabbf52a
......@@ -12,8 +12,17 @@
*/
export const enum CharCode {
Null = 0,
/**
* The `\t` character.
*/
Tab = 9,
/**
* The `\n` character.
*/
LineFeed = 10,
/**
* The `\r` character.
*/
CarriageReturn = 13,
Space = 32,
/**
......
......@@ -8,6 +8,7 @@ import * as strings from 'vs/base/common/strings';
import {WrappingIndent} from 'vs/editor/common/editorCommon';
import {PrefixSumComputer} from 'vs/editor/common/viewModel/prefixSumComputer';
import {ILineMapperFactory, ILineMapping, OutputPosition} from 'vs/editor/common/viewModel/splitLinesCollection';
import {CharCode} from 'vs/base/common/charCode';
import {CharacterClassifier} from 'vs/editor/common/core/characterClassifier';
const enum CharacterClass {
......@@ -85,7 +86,6 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
let wrappedTextIndentVisibleColumn = 0;
let wrappedTextIndent = '';
const TAB_CHAR_CODE = '\t'.charCodeAt(0);
let firstNonWhitespaceIndex = -1;
if (hardWrappingIndent !== WrappingIndent.None) {
......@@ -93,7 +93,7 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
if (firstNonWhitespaceIndex !== -1) {
wrappedTextIndent = lineText.substring(0, firstNonWhitespaceIndex);
for (let i = 0; i < firstNonWhitespaceIndex; i++) {
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, lineText.charCodeAt(i) === TAB_CHAR_CODE, 1);
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, lineText.charCodeAt(i) === CharCode.Tab, 1);
}
if (hardWrappingIndent === WrappingIndent.Indent) {
wrappedTextIndent += '\t';
......@@ -125,7 +125,7 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
// but the character at `i` might not fit
let charCode = lineText.charCodeAt(i);
let charCodeIsTab = (charCode === TAB_CHAR_CODE);
let charCodeIsTab = (charCode === CharCode.Tab);
let charCodeClass = classifier.get(charCode);
if (charCodeClass === CharacterClass.BREAK_BEFORE) {
......
......@@ -13,6 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {ICommentsConfiguration} from 'vs/editor/common/modes';
import {BlockCommentCommand} from './blockCommentCommand';
import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry';
import {CharCode} from 'vs/base/common/charCode';
export interface IInsertionPoint {
ignore: boolean;
......@@ -114,7 +115,6 @@ export class LineCommentCommand implements editorCommon.ICommand {
lineNumber:number,
shouldRemoveComments:boolean,
lineContent: string,
_space = ' '.charCodeAt(0),
onlyWhitespaceLines = true;
if (type === Type.Toggle) {
......@@ -162,7 +162,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
if (shouldRemoveComments) {
commentStrEndOffset = lineContentStartOffset + lineData.commentStrLength;
if (commentStrEndOffset < lineContent.length && lineContent.charCodeAt(commentStrEndOffset) === _space) {
if (commentStrEndOffset < lineContent.length && lineContent.charCodeAt(commentStrEndOffset) === CharCode.Space) {
lineData.commentStrLength += 1;
}
}
......@@ -414,8 +414,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
lineContent: string,
j: number,
lenJ: number,
currentVisibleColumn: number,
_tab = '\t'.charCodeAt(0);
currentVisibleColumn: number;
for (i = 0, len = lines.length; i < len; i++) {
if (lines[i].ignore) {
......@@ -426,7 +425,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
currentVisibleColumn = 0;
for (j = 0, lenJ = lines[i].commentStrOffset; currentVisibleColumn < minVisibleColumn && j < lenJ; j++) {
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === _tab, 1);
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === CharCode.Tab, 1);
}
if (currentVisibleColumn < minVisibleColumn) {
......@@ -445,7 +444,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
currentVisibleColumn = 0;
for (j = 0, lenJ = lines[i].commentStrOffset; currentVisibleColumn < minVisibleColumn && j < lenJ; j++) {
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === _tab, 1);
currentVisibleColumn = LineCommentCommand.nextVisibleColumn(currentVisibleColumn, tabSize, lineContent.charCodeAt(j) === CharCode.Tab, 1);
}
if (currentVisibleColumn > minVisibleColumn) {
......
......@@ -10,6 +10,7 @@ import {DefaultEndOfLine, ITextModelCreationOptions, ITextModelResolvedOptions,
import * as strings from 'vs/base/common/strings';
import {guessIndentation} from 'vs/editor/common/model/indentationGuesser';
import {TPromise} from 'vs/base/common/winjs.base';
import {CharCode} from 'vs/base/common/charCode';
export class ModelBuilderResult {
rawText: IRawText;
......@@ -162,7 +163,7 @@ export class ModelBuilder {
if (this.leftoverEndsInCR) {
chunk = '\r' + chunk;
}
if (chunk.charCodeAt(chunk.length - 1) === 13 /*\r*/) {
if (chunk.charCodeAt(chunk.length - 1) === CharCode.CarriageReturn) {
this.leftoverEndsInCR = true;
chunk = chunk.substr(0, chunk.length - 1);
} else {
......
......@@ -8,6 +8,7 @@ import {Position} from 'vs/editor/common/core/position';
import {Range} from 'vs/editor/common/core/range';
import {IIdentifiedSingleEditOperation} from 'vs/editor/common/editorCommon';
import {testApplyEditsWithSyncedModels} from 'vs/editor/test/common/model/editableTextModelTestUtils';
import {CharCode} from 'vs/base/common/charCode';
const GENERATE_TESTS = false;
......@@ -142,7 +143,7 @@ function getRandomString(minLength: number, maxLength: number): string {
let length = getRandomInt(minLength, maxLength);
let r = '';
for (let i = 0; i < length; i++) {
r += String.fromCharCode(getRandomInt('a'.charCodeAt(0), 'z'.charCodeAt(0)));
r += String.fromCharCode(getRandomInt(CharCode.a, CharCode.z));
}
return r;
}
......
......@@ -5,6 +5,7 @@
'use strict';
import {testModelBuilder, testDifferentHash} from 'vs/editor/test/node/model/modelBuilder.test';
import {CharCode} from 'vs/base/common/charCode';
const GENERATE_TESTS = false;
......@@ -44,7 +45,7 @@ function getRandomString(minLength: number, maxLength: number): string {
let length = getRandomInt(minLength, maxLength);
let r = '';
for (let i = 0; i < length; i++) {
r += String.fromCharCode(getRandomInt('a'.charCodeAt(0), 'z'.charCodeAt(0)));
r += String.fromCharCode(getRandomInt(CharCode.a, CharCode.z));
}
return r;
}
......
......@@ -22,6 +22,7 @@ import {ICompatWorkerService, CompatWorkerAttr} from 'vs/editor/common/services/
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IHTMLConfiguration} from 'vs/languages/html/common/html.contribution';
import {CharCode} from 'vs/base/common/charCode';
export { htmlTokenTypes }; // export to be used by Razor. We are the main module, so Razor should get it from us.
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 {
break;
case States.Content:
if (stream.advanceIfCharCode2('<'.charCodeAt(0))) {
if (stream.advanceIfCharCode2(CharCode.LessThan)) {
if (!stream.eos() && stream.peek() === '!') {
if (stream.advanceIfString2('!--')) {
this.kind = States.WithinComment;
......@@ -126,7 +127,7 @@ export class State extends AbstractState {
return { type: htmlTokenTypes.DELIM_DOCTYPE, dontMergeWithPrev: true };
}
}
if (stream.advanceIfCharCode2('/'.charCodeAt(0))) {
if (stream.advanceIfCharCode2(CharCode.Slash)) {
this.kind = States.OpeningEndTag;
return { type: htmlTokenTypes.DELIM_END, dontMergeWithPrev: true };
}
......@@ -183,7 +184,7 @@ export class State extends AbstractState {
this.kind = States.Content;
return { type: htmlTokenTypes.DELIM_START, dontMergeWithPrev: true };
}
if (stream.advanceIfCharCode2('>'.charCodeAt(0))) {
if (stream.advanceIfCharCode2(CharCode.GreaterThan)) {
if (tagsEmbeddingContent.indexOf(this.lastTagName) !== -1) {
this.kind = States.WithinEmbeddedContent;
return { type: htmlTokenTypes.DELIM_START, dontMergeWithPrev: true };
......@@ -202,7 +203,7 @@ export class State extends AbstractState {
return { type: '' };
}
if (stream.advanceIfCharCode2('='.charCodeAt(0))) {
if (stream.advanceIfCharCode2(CharCode.Equals)) {
this.kind = States.AttributeValue;
return { type: htmlTokenTypes.DELIM_ASSIGN };
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册