(text)
| 46 | } |
| 47 | |
| 48 | export function extractJSONObject(text) { |
| 49 | const start = text.indexOf("{"); |
| 50 | if (start === -1) return null; |
| 51 | |
| 52 | let depth = 0; |
| 53 | let inString = false; |
| 54 | let escaping = false; |
| 55 | |
| 56 | for (let i = start; i < text.length; i++) { |
| 57 | const ch = text[i]; |
| 58 | |
| 59 | if (inString) { |
| 60 | if (escaping) { |
| 61 | escaping = false; |
| 62 | } else if (ch === "\\") { |
| 63 | escaping = true; |
| 64 | } else if (ch === "\"") { |
| 65 | inString = false; |
| 66 | } |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | if (ch === "\"") { |
| 71 | inString = true; |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | if (ch === "{") depth++; |
| 76 | if (ch === "}") depth--; |
| 77 | |
| 78 | if (depth === 0) { |
| 79 | return text.slice(start, i + 1); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return text.slice(start); |
| 84 | } |
| 85 | |
| 86 | export function escapeControlCharsInStrings(text) { |
| 87 | let result = ""; |
no outgoing calls
no test coverage detected