本文整理匯總了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
};
}
示例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;
}
}
示例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;
}
示例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();
}
});
});
}