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

Function parseString

src/backend/mi_parse.ts:21–55  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

19};
20
21function parseString(str: string): string {
22 const ret = Buffer.alloc(str.length * 4);
23 let bufIndex = 0;
24
25 if (str[0] !== '"' || str[str.length - 1] !== '"') {
26 throw new Error('Not a valid string');
27 }
28 str = str.slice(1, -1);
29 for (let i = 0; i < str.length; i++) {
30 if (str[i] === '\\') {
31 if (++i >= str.length) {
32 throw new Error('Not a valid escape sequence');
33 }
34 const sub = escapeMap[str[i]];
35 if (sub) {
36 bufIndex += ret.write(sub, bufIndex);
37 } else {
38 const m = octalMatch.exec(str.substr(i));
39 if (m) {
40 ret.writeUInt8(parseInt(m[0], 8), bufIndex++);
41 i += 2;
42 }
43 else {
44 bufIndex += ret.write(str[i], bufIndex);
45 }
46 }
47 } else if (str[i] === '"') {
48 throw new Error('Not a valid string');
49 }
50 else {
51 bufIndex += ret.write(str[i], bufIndex);
52 }
53 }
54 return ret.toString('utf8', 0, bufIndex);
55}
56
57export class MINode implements MIInfo {
58 public token: number;

Callers 1

parseCStringFunction · 0.85

Calls 2

toStringMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected