------------------------------------------------------------------------------------------------ Get a string from the material
| 305 | // ------------------------------------------------------------------------------------------------ |
| 306 | // Get a string from the material |
| 307 | aiReturn aiGetMaterialString(const aiMaterial *pMat, |
| 308 | const char *pKey, |
| 309 | unsigned int type, |
| 310 | unsigned int index, |
| 311 | aiString *pOut) { |
| 312 | ai_assert(pOut != nullptr); |
| 313 | |
| 314 | const aiMaterialProperty *prop{nullptr}; |
| 315 | aiGetMaterialProperty(pMat, pKey, type, index, &prop); |
| 316 | if (!prop) { |
| 317 | return AI_FAILURE; |
| 318 | } |
| 319 | |
| 320 | if (aiPTI_String == prop->mType) { |
| 321 | ai_assert(prop->mDataLength >= 5); |
| 322 | |
| 323 | // The string is stored as 32 but length prefix followed by zero-terminated UTF8 data |
| 324 | pOut->length = static_cast<unsigned int>(*reinterpret_cast<uint32_t *>(prop->mData)); |
| 325 | |
| 326 | ai_assert(pOut->length + 1 + 4 == prop->mDataLength); |
| 327 | ai_assert(!prop->mData[prop->mDataLength - 1]); |
| 328 | memcpy(pOut->data, prop->mData + 4, pOut->length + 1); |
| 329 | } else { |
| 330 | // TODO - implement lexical cast as well |
| 331 | ASSIMP_LOG_ERROR("Material property", pKey, " was found, but is no string"); |
| 332 | return AI_FAILURE; |
| 333 | } |
| 334 | return AI_SUCCESS; |
| 335 | } |
| 336 | |
| 337 | // ------------------------------------------------------------------------------------------------ |
| 338 | // Get a c-like string fron an aiString |
no test coverage detected