comparers.ts ×24

Frontier kind: Code frontier

unlabeled · c_de1252238054

600 tests · 6566 LOC · 35 files · introduces 0 tests · 91 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
24 ranges91 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
928 ranges6566 lines · 35 files · Browse complete extent
All tests (intent)
600 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 91 introduced LOC across 24 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/comparers.ts 91 introduced LOC · 24 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- comparers.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { safeIntl } from './date.js';
7 > import { Lazy } from './lazy.js';
8 > import { sep } from './path.js';
9 >
10 > // When comparing large numbers of strings it's better for performance to create an
11 > // Intl.Collator object and use the function provided by its compare property
12 > // than it is to use String.prototype.localeCompare()
13 >
14 > // A collator with numeric sorting enabled, and no sensitivity to case, accents or diacritics.
15 > const intlFileNameCollatorBaseNumeric: Lazy<{ collator: Intl.Collator; collatorIsNumeric: boolean }> = new Lazy(() => {
16 const collator = safeIntl.Collator(undefined, { numeric: true, sensitivity: 'base' }).value;
17 return {
20 };
21 });
23 > // A collator with numeric sorting enabled.
24 > const intlFileNameCollatorNumeric: Lazy<{ collator: Intl.Collator }> = new Lazy(() => {
25 const collator = safeIntl.Collator(undefined, { numeric: true }).value;
26 return {
28 };
29 });
31 > // A collator with numeric sorting enabled, and sensitivity to accents and diacritics but not case.
32 > const intlFileNameCollatorNumericCaseInsensitive: Lazy<{ collator: Intl.Collator }> = new Lazy(() => {
33 const collator = safeIntl.Collator(undefined, { numeric: true, sensitivity: 'accent' }).value;
34 return {
36 };
37 });
39 > /** Compares filenames without distinguishing the name from the extension. Disambiguates by unicode comparison. */
40 > export function compareFileNames(one: string | null, other: string | null, caseSensitive = false): number {
41 const a = one || '';
42 const b = other || '';
50 return result;
51 }
53 > /** Compares full filenames without grouping by case. */
54 > export function compareFileNamesDefault(one: string | null, other: string | null): number {
55 const collatorNumeric = intlFileNameCollatorNumeric.value.collator;
56 one = one || '';
59 return compareAndDisambiguateByLength(collatorNumeric, one, other);
60 }
62 > /** Compares full filenames grouping uppercase names before lowercase. */
63 > export function compareFileNamesUpper(one: string | null, other: string | null) {
64 const collatorNumeric = intlFileNameCollatorNumeric.value.collator;
65 one = one || '';
68 return compareCaseUpperFirst(one, other) || compareAndDisambiguateByLength(collatorNumeric, one, other);
69 }
71 > /** Compares full filenames grouping lowercase names before uppercase. */
72 > export function compareFileNamesLower(one: string | null, other: string | null) {
73 const collatorNumeric = intlFileNameCollatorNumeric.value.collator;
74 one = one || '';
77 return compareCaseLowerFirst(one, other) || compareAndDisambiguateByLength(collatorNumeric, one, other);
78 }
80 > /** Compares full filenames by unicode value. */
81 > export function compareFileNamesUnicode(one: string | null, other: string | null) {
82 one = one || '';
83 other = other || '';
89 return one < other ? -1 : 1;
90 }
92 > /** Compares filenames by extension, then by name. Disambiguates by unicode comparison. */
93 > export function compareFileExtensions(one: string | null, other: string | null): number {
94 const [oneName, oneExtension] = extractNameAndExtension(one);
95 const [otherName, otherExtension] = extractNameAndExtension(other);
113 return result;
114 }
115 > comparers.ts
116 > /** Compares filenames by extension, then by full filename. Mixes uppercase and lowercase names together. */
117 > export function compareFileExtensionsDefault(one: string | null, other: string | null): number {
118 one = one || '';
119 other = other || '';
126 compareAndDisambiguateByLength(collatorNumeric, one, other);
127 }
128 > comparers.ts
129 > /** Compares filenames by extension, then case, then full filename. Groups uppercase names before lowercase. */
130 > export function compareFileExtensionsUpper(one: string | null, other: string | null): number {
131 one = one || '';
132 other = other || '';
140 compareAndDisambiguateByLength(collatorNumeric, one, other);
141 }
142 > comparers.ts
143 > /** Compares filenames by extension, then case, then full filename. Groups lowercase names before uppercase. */
144 > export function compareFileExtensionsLower(one: string | null, other: string | null): number {
145 one = one || '';
146 other = other || '';
154 compareAndDisambiguateByLength(collatorNumeric, one, other);
155 }
156 > comparers.ts
157 > /** Compares filenames by case-insensitive extension unicode value, then by full filename unicode value. */
158 > export function compareFileExtensionsUnicode(one: string | null, other: string | null) {
159 one = one || '';
160 other = other || '';
174 return 0;
175 }
176 > comparers.ts
177 > const FileNameMatch = /^(.*?)(\.([^.]*))?$/;
178 >
179 > /** Extracts the name and extension from a full filename, with optional special handling for dotfiles */
180 function extractNameAndExtension(str?: string | null, dotfilesAsNames = false): [string, string] {
181 const match = str ? FileNameMatch.exec(str) as Array<string> : ([] as Array<string>);
191 return result;
192 }
193 > comparers.ts
194 > /** Extracts the extension from a full filename. Treats dotfiles as names, not extensions. */
195 function extractExtension(str?: string | null): string {
196 const match = str ? FileNameMatch.exec(str) as Array<string> : ([] as Array<string>);
198 return (match && match[1] && match[1].charAt(0) !== '.' && match[3]) || '';
199 }
200 > comparers.ts
201 function compareAndDisambiguateByLength(collator: Intl.Collator, one: string, other: string) {
202 // Check for differences
214 return 0;
215 }
216 > comparers.ts
217 > /** @returns `true` if the string is starts with a lowercase letter. Otherwise, `false`. */
218 function startsWithLower(string: string) {
219 const character = string.charAt(0);
221 return (character.toLocaleUpperCase() !== character) ? true : false;
222 }
223 > comparers.ts
224 > /** @returns `true` if the string starts with an uppercase letter. Otherwise, `false`. */
225 function startsWithUpper(string: string) {
226 const character = string.charAt(0);
228 return (character.toLocaleLowerCase() !== character) ? true : false;
229 }
230 > comparers.ts
231 > /**
232 > * Compares the case of the provided strings - lowercase before uppercase
233 > *
234 > * @returns
235 > * ```text
236 > * -1 if one is lowercase and other is uppercase
237 > * 1 if one is uppercase and other is lowercase
238 > * 0 otherwise
239 > * ```
240 > */
241 function compareCaseLowerFirst(one: string, other: string): number {
242 if (startsWithLower(one) && startsWithUpper(other)) {
245 return (startsWithUpper(one) && startsWithLower(other)) ? 1 : 0;
246 }
247 > comparers.ts
248 > /**
249 > * Compares the case of the provided strings - uppercase before lowercase
250 > *
251 > * @returns
252 > * ```text
253 > * -1 if one is uppercase and other is lowercase
254 > * 1 if one is lowercase and other is uppercase
255 > * 0 otherwise
256 > * ```
257 > */
258 function compareCaseUpperFirst(one: string, other: string): number {
259 if (startsWithUpper(one) && startsWithLower(other)) {
262 return (startsWithLower(one) && startsWithUpper(other)) ? 1 : 0;
263 }
264 > comparers.ts
265 function comparePathComponents(one: string, other: string, caseSensitive = false): number {
266 if (!caseSensitive) {
275 return one < other ? -1 : 1;
276 }
277 > comparers.ts
278 > export function comparePaths(one: string, other: string, caseSensitive = false): number {
279 const oneParts = one.split(sep);
280 const otherParts = other.split(sep);
303 }
304 }
305 > comparers.ts
306 > export function compareAnything(one: string, other: string, lookFor: string): number {
307 const elementAName = one.toLowerCase();
308 const elementBName = other.toLowerCase();
330 return elementAName.localeCompare(elementBName);
331 }
332 > comparers.ts
333 > export function compareByPrefix(one: string, other: string, lookFor: string): number {
334 const elementAName = one.toLowerCase();
335 const elementBName = other.toLowerCase();