本文整理汇总了TypeScript中vs/base/common/strings.startsWithUTF8BOM函数的典型用法代码示例。如果您正苦于以下问题:TypeScript startsWithUTF8BOM函数的具体用法?TypeScript startsWithUTF8BOM怎么用?TypeScript startsWithUTF8BOM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startsWithUTF8BOM函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: toRawText
public static toRawText(rawText:string): editorCommon.IRawText {
// Count the number of lines that end with \r\n
var carriageReturnCnt = 0,
lastCarriageReturnIndex = -1;
while ((lastCarriageReturnIndex = rawText.indexOf('\r', lastCarriageReturnIndex + 1)) !== -1) {
carriageReturnCnt++;
}
// Split the text into liens
var lines = rawText.split(/\r\n|\r|\n/);
// Remove the BOM (if present)
var BOM = '';
if (strings.startsWithUTF8BOM(lines[0])) {
BOM = strings.UTF8_BOM_CHARACTER;
lines[0] = lines[0].substr(1);
}
var lineFeedCnt = lines.length - 1;
var EOL = '';
if (lineFeedCnt === 0) {
// This is an empty file or a file with precisely one line
EOL = DEFAULT_PLATFORM_EOL;
} else if (carriageReturnCnt > lineFeedCnt / 2) {
// More than half of the file contains \r\n ending lines
EOL = '\r\n';
} else {
// At least one line more ends in \n
EOL = '\n';
}
return {
BOM: BOM,
EOL: EOL,
lines: lines,
length: rawText.length
};
}
开发者ID:huiyuewidows10,项目名称:vscode,代码行数:38,代码来源:textModel.ts
示例2: acceptChunk
public acceptChunk(chunk: string): void {
if (chunk.length === 0) {
return;
}
if (this.chunks.length === 0) {
if (strings.startsWithUTF8BOM(chunk)) {
this.BOM = strings.UTF8_BOM_CHARACTER;
chunk = chunk.substr(1);
}
}
const lastChar = chunk.charCodeAt(chunk.length - 1);
if (lastChar === CharCode.CarriageReturn || (lastChar >= 0xD800 && lastChar <= 0xDBFF)) {
// last character is \r or a high surrogate => keep it back
this._acceptChunk1(chunk.substr(0, chunk.length - 1), false);
this._hasPreviousChar = true;
this._previousChar = lastChar;
} else {
this._acceptChunk1(chunk, false);
this._hasPreviousChar = false;
this._previousChar = lastChar;
}
}
开发者ID:PKRoma,项目名称:vscode,代码行数:24,代码来源:pieceTreeTextBufferBuilder.ts
示例3: guessMimeTypeByFirstline
function guessMimeTypeByFirstline(firstLine: string): string | null {
if (startsWithUTF8BOM(firstLine)) {
firstLine = firstLine.substr(1);
}
if (firstLine.length > 0) {
// We want to prioritize associations based on the order they are registered so that the last registered
// association wins over all other. This is for https://github.com/Microsoft/vscode/issues/20074
for (let i = registeredAssociations.length - 1; i >= 0; i--) {
const association = registeredAssociations[i];
if (!association.firstline) {
continue;
}
const matches = firstLine.match(association.firstline);
if (matches && matches.length > 0) {
return association.mime;
}
}
}
return null;
}
开发者ID:PKRoma,项目名称:vscode,代码行数:24,代码来源:mime.ts
示例4: colorize
public static colorize(modeService: IModeService, text: string, mimeType: string, options: IColorizerOptions | null | undefined): Promise<string> {
let tabSize = 4;
if (options && typeof options.tabSize === 'number') {
tabSize = options.tabSize;
}
if (strings.startsWithUTF8BOM(text)) {
text = text.substr(1);
}
let lines = text.split(/\r\n|\r|\n/);
let language = modeService.getModeId(mimeType);
if (!language) {
return Promise.resolve(_fakeColorize(lines, tabSize));
}
// Send out the event to create the mode
modeService.triggerMode(language);
const tokenizationSupport = TokenizationRegistry.get(language);
if (tokenizationSupport) {
return _colorize(lines, tabSize, tokenizationSupport);
}
const tokenizationSupportPromise = TokenizationRegistry.getPromise(language);
if (tokenizationSupportPromise) {
// A tokenizer will be registered soon
return new Promise<string>((resolve, reject) => {
tokenizationSupportPromise.then(tokenizationSupport => {
_colorize(lines, tabSize, tokenizationSupport).then(resolve, reject);
}, reject);
});
}
return new Promise<string>((resolve, reject) => {
let listener: IDisposable | null = null;
let timeout: TimeoutTimer | null = null;
const execute = () => {
if (listener) {
listener.dispose();
listener = null;
}
if (timeout) {
timeout.dispose();
timeout = null;
}
const tokenizationSupport = TokenizationRegistry.get(language!);
if (tokenizationSupport) {
_colorize(lines, tabSize, tokenizationSupport).then(resolve, reject);
return;
}
resolve(_fakeColorize(lines, tabSize));
};
// wait 500ms for mode to load, then give up
timeout = new TimeoutTimer();
timeout.cancelAndSet(execute, 500);
listener = TokenizationRegistry.onDidChange((e) => {
if (e.changedLanguages.indexOf(language!) >= 0) {
execute();
}
});
});
}
开发者ID:PKRoma,项目名称:vscode,代码行数:64,代码来源:colorizer.ts
注:本文中的vs/base/common/strings.startsWithUTF8BOM函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论