| 79 | }; |
| 80 | |
| 81 | static std::vector<CodeBlock> extractCodeBlocks(const std::string& content) |
| 82 | { |
| 83 | std::vector<CodeBlock> blocks; |
| 84 | std::istringstream iss(content); |
| 85 | std::string line; |
| 86 | int lineNum = 0; |
| 87 | bool inBlock = false; |
| 88 | std::string lang; |
| 89 | std::string code; |
| 90 | int blockStart = 0; |
| 91 | |
| 92 | while (std::getline(iss, line)) |
| 93 | { |
| 94 | lineNum++; |
| 95 | if (!inBlock) |
| 96 | { |
| 97 | if (line.find("```sqf") == 0 || line.find("```sqs") == 0) |
| 98 | { |
| 99 | inBlock = true; |
| 100 | lang = line.substr(3, 3); |
| 101 | code.clear(); |
| 102 | blockStart = lineNum; |
| 103 | } |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | if (line.find("```") == 0) |
| 108 | { |
| 109 | inBlock = false; |
| 110 | if (!code.empty()) |
| 111 | blocks.push_back({code, lang, blockStart}); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | code += line + "\n"; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | return blocks; |
| 120 | } |
| 121 | |
| 122 | // Replace non-ASCII bytes with spaces to avoid ctype assertion crashes |
| 123 | static std::string sanitizeAscii(const std::string& s) |
no test coverage detected