MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / extractCodeBlocks

Function extractCodeBlocks

engine/Evaluator/Validate.cpp:81–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79};
80
81static 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
123static std::string sanitizeAscii(const std::string& s)

Callers 1

validateBookFunction · 0.85

Calls 2

clearMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected