Cleanup - fix various tests.

This commit is contained in:
Per Bothner
2023-05-17 18:37:27 -07:00
parent 2f7fe1189c
commit 67e968926c
12 changed files with 136 additions and 54 deletions
-1
View File
@@ -296,7 +296,6 @@ export interface IOscLinkService {
/** Width and Grapheme_Cluster_Break properties of a character. */
export type UnicodeCharProperties = number;
export const UnicodeInitialProperties: UnicodeCharProperties = 0; // UNEEDED?
export type UnicodeCharWidth = 0 | 1 | 2;
export const IUnicodeService = createDecorator<IUnicodeService>('UnicodeService');
+1 -1
View File
@@ -12,7 +12,7 @@ class DummyProvider implements IUnicodeVersionProvider {
public wcwidth(n: number): 0 | 1 | 2 {
return 2;
}
charProperties(codepoint: number): number {
public charProperties(codepoint: number): number {
return UnicodeService.createPropertyValue(0, this.wcwidth(codepoint));
}
}
+9 -2
View File
@@ -70,6 +70,7 @@ export class UnicodeService implements IUnicodeService {
public getStringCellWidth(s: string): number {
let result = 0;
let precedingInfo = 0;
const length = s.length;
for (let i = 0; i < length; ++i) {
let code = s.charCodeAt(i);
@@ -92,12 +93,18 @@ export class UnicodeService implements IUnicodeService {
result += this.wcwidth(second);
}
}
result += this.wcwidth(code);
const currentInfo = this.charProperties(code, precedingInfo);
let chWidth = UnicodeService.extractWidth(currentInfo);
if (UnicodeService.extractShouldJoin(currentInfo)) {
chWidth -= UnicodeService.extractWidth(precedingInfo);
}
result += chWidth;
precedingInfo = currentInfo;
}
return result;
}
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
return this._activeProvider.charProperties(codepoint, preceding);
}
}