MCPcopy Create free account
hub / github.com/chhoumann/quickadd / collapseControlRunsWithSpaces

Function collapseControlRunsWithSpaces

src/utils/generatedFilePath.ts:25–53  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

23// space run is not followed by a control character the regex left it
24// untouched, so the scanner copies it verbatim and jumps past it.
25function collapseControlRunsWithSpaces(value: string): string {
26 let out = "";
27 let i = 0;
28 while (i < value.length) {
29 let j = i;
30 while (j < value.length && value.charCodeAt(j) === 0x20 /* space */) {
31 j++;
32 }
33 if (j < value.length && isControlOrLineSeparator(value.charCodeAt(j))) {
34 while (
35 j < value.length &&
36 isControlOrLineSeparator(value.charCodeAt(j))
37 ) {
38 j++;
39 }
40 while (j < value.length && value.charCodeAt(j) === 0x20) {
41 j++;
42 }
43 out += " ";
44 i = j;
45 continue;
46 }
47 // No control char after the space run: nothing here can start a match,
48 // so copy [i, j] verbatim (run + the non-matching char) and move on.
49 out += value.slice(i, Math.min(j + 1, value.length));
50 i = j + 1;
51 }
52 return out;
53}
54
55/**
56 * Linear trailing-trim for a small character set. The historical

Callers 1

Calls 1

isControlOrLineSeparatorFunction · 0.85

Tested by

no test coverage detected