//------------------------------------------------------------ //! Read a symbol's value as a string. Value will be formatted according to designated format. VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, UInt8** valueString) { TypeManagerScope scope(tm); if (typeRef == nullptr || !typeRef->IsValid()) return kEggShellResult_InvalidTypeRef; static StringRef returnBuffer = nullptr; if (returnBuffer == nullptr) { // Allocate a string the first time it is used. // After that it will be resized as needed. STACK_VAR(String, tempReturn); returnBuffer = tempReturn.DetachValue(); } else { returnBuffer->Resize1D(0); } if (returnBuffer) { SubString formatss(format); TDViaFormatter formatter(returnBuffer, true, 0, &formatss, kJSONEncodingEggShell); formatter.FormatData(typeRef, pData); // Add an explicit null terminator so it looks like a C string. returnBuffer->Append((Utf8Char)'\0'); *valueString = returnBuffer->Begin(); return kEggShellResult_Success; } return kEggShellResult_UnableToCreateReturnBuffer; }
void CopyArrayTypeNameStringToBuffer(StringRef arrayTypeNameBuffer, SubString arrayTypeName) { arrayTypeNameBuffer->Append(arrayTypeName.Length(), static_cast<const Utf8Char*>(arrayTypeName.Begin())); arrayTypeNameBuffer->Append((Utf8Char)'\0'); }