MCPcopy Create free account
hub / github.com/assimp/assimp / ParseTokenAsString

Function ParseTokenAsString

code/AssetLib/FBX/FBXParser.cpp:470–508  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

468
469// ------------------------------------------------------------------------------------------------
470std::string ParseTokenAsString(const Token& t, const char*& err_out)
471{
472 err_out = nullptr;
473
474 if (t.Type() != TokenType_DATA) {
475 err_out = "expected TOK_DATA token";
476 return std::string();
477 }
478
479 if(t.IsBinary())
480 {
481 const char* data = t.begin();
482 if (data[0] != 'S') {
483 err_out = "failed to parse S(tring), unexpected data type (binary)";
484 return std::string();
485 }
486
487 // read string length
488 BE_NCONST int32_t len = SafeParse<int32_t>(data+1, t.end());
489 AI_SWAP4(len);
490
491 ai_assert(t.end() - data == 5 + len);
492 return std::string(data + 5, len);
493 }
494
495 const size_t length = static_cast<size_t>(t.end() - t.begin());
496 if(length < 2) {
497 err_out = "token is too short to hold a string";
498 return std::string();
499 }
500
501 const char* s = t.begin(), *e = t.end() - 1;
502 if (*s != '\"' || *e != '\"') {
503 err_out = "expected double quoted string";
504 return std::string();
505 }
506
507 return std::string(s+1,length-2);
508}
509
510
511namespace {

Callers 15

DeformerMethod · 0.85
NodeAttributeMethod · 0.85
GetMethod · 0.85
ReadHeaderMethod · 0.85
ReadPropertyTemplatesMethod · 0.85
ReadConnectionsMethod · 0.85
checkTokenCountFunction · 0.85
ReadTypedPropertyFunction · 0.85
PeekPropertyNameFunction · 0.85
MaterialMethod · 0.85
TextureMethod · 0.85
VideoMethod · 0.85

Calls 5

ParseErrorFunction · 0.85
TypeMethod · 0.45
IsBinaryMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected