MCPcopy Create free account
hub / github.com/Kitware/VTK / ExtractDataURI

Function ExtractDataURI

IO/Core/vtkURILoader.cxx:231–299  ·  view source on GitHub ↗

Helper to extract data URI header

Source from the content-addressed store, hash-verified

229
230// Helper to extract data URI header
231DataURIInfo ExtractDataURI(const char* begin, const char* end)
232{
233 DataURIInfo output{};
234
235 if (begin == end)
236 {
237 vtkErrorWithObjectMacro(nullptr, "Empty data URI");
238 return output;
239 }
240
241 const auto typeEnd = std::find_if(begin, end, [](char c) { return c == ';' || c == ','; });
242
243 if (typeEnd == end)
244 {
245 vtkErrorWithObjectMacro(nullptr, "No ',' in data URI");
246 return output;
247 }
248
249 if (begin != typeEnd) // type specified
250 {
251 auto type = std::string{ begin, typeEnd };
252 begin = typeEnd;
253
254 output.Type = std::move(type);
255 }
256 else
257 {
258 output.Type = "text/plain;charset=US-ASCII";
259 }
260
261 while (*begin == ';')
262 {
263 ++begin; // discard ;
264 const auto paramEnd = std::find_if(begin, end, [](char c) { return c == ';' || c == ','; });
265
266 if (paramEnd == end)
267 {
268 vtkErrorWithObjectMacro(nullptr, "Truncated data URI header");
269 return output;
270 }
271
272 if (*paramEnd == ',')
273 {
274 auto param = std::string{ begin, paramEnd };
275 if (param == "base64")
276 {
277 output.base64 = true;
278 }
279
280 // Parameters aren't stored since unused, but if needed its where it should be done
281 begin = paramEnd;
282 break;
283 }
284
285 // Parameters aren't stored since unused, but if needed its where it should be done
286 begin = paramEnd;
287 }
288

Callers 1

LoadDataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected