MCPcopy Create free account
hub / github.com/developer0hye/Yolo_Label / parsePythonDictStr

Method parsePythonDictStr

yolo_detector.cpp:200–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200std::map<int, std::string> YoloDetector::parsePythonDictStr(const std::string& str)
201{
202 // Parse: "{0: 'person', 1: 'bicycle', 2: 'car'}"
203 std::map<int, std::string> result;
204
205 // Find content between outermost braces
206 auto start = str.find('{');
207 auto end = str.rfind('}');
208 if (start == std::string::npos || end == std::string::npos || end <= start)
209 return result;
210
211 std::string content = str.substr(start + 1, end - start - 1);
212
213 // Split by comma, but handle quoted values that may contain commas
214 size_t pos = 0;
215 while (pos < content.size()) {
216 // Find the colon separating key: value
217 auto colonPos = content.find(':', pos);
218 if (colonPos == std::string::npos) break;
219
220 // Parse integer key
221 std::string keyStr = content.substr(pos, colonPos - pos);
222 int key = 0;
223 try { key = std::stoi(keyStr); } catch (...) { break; }
224
225 // Find the value (quoted string)
226 auto quoteStart = content.find_first_of("'\"", colonPos + 1);
227 if (quoteStart == std::string::npos) break;
228 char quoteChar = content[quoteStart];
229 auto quoteEnd = content.find(quoteChar, quoteStart + 1);
230 if (quoteEnd == std::string::npos) break;
231
232 std::string value = content.substr(quoteStart + 1, quoteEnd - quoteStart - 1);
233 result[key] = value;
234
235 // Move past this entry's comma
236 pos = content.find(',', quoteEnd);
237 if (pos == std::string::npos) break;
238 pos++; // skip comma
239 }
240
241 return result;
242}
243
244std::pair<int, int> YoloDetector::parseImgsz(const std::string& str)
245{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected