MCPcopy Create free account
hub / github.com/Marus/cortex-debug / parseDimIndex

Function parseDimIndex

src/frontend/utils.ts:53–98  ·  view source on GitHub ↗
(spec: string, count: number)

Source from the content-addressed store, hash-verified

51}
52
53export function parseDimIndex(spec: string, count: number): string[] {
54 if (spec.indexOf(',') !== -1) {
55 const components = spec.split(',').map((c) => c.trim());
56 if (components.length !== count) {
57 throw new Error('dimIndex Element has invalid specification.');
58 }
59 return components;
60 }
61
62 if (/^([0-9]+)\-([0-9]+)$/i.test(spec)) {
63 const parts = spec.split('-').map((p) => parseInteger(p));
64 const start = parts[0];
65 const end = parts[1];
66
67 const numElements = end - start + 1;
68 if (numElements < count) {
69 throw new Error('dimIndex Element has invalid specification.');
70 }
71
72 const components = [];
73 for (let i = 0; i < count; i++) {
74 components.push(`${start + i}`);
75 }
76
77 return components;
78 }
79
80 if (/^[a-zA-Z]\-[a-zA-Z]$/.test(spec)) {
81 const start = spec.charCodeAt(0);
82 const end = spec.charCodeAt(2);
83
84 const numElements = end - start + 1;
85 if (numElements < count) {
86 throw new Error('dimIndex Element has invalid specification.');
87 }
88
89 const components = [];
90 for (let i = 0; i < count; i++) {
91 components.push(String.fromCharCode(start + i));
92 }
93
94 return components;
95 }
96
97 return [];
98}

Callers

nothing calls this directly

Calls 1

parseIntegerFunction · 0.85

Tested by

no test coverage detected