MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / ComposeArrayItemPath

Method ComposeArrayItemPath

xmpsdk/src/XMPUtils.cpp:699–735  ·  view source on GitHub ↗

class static */

Source from the content-addressed store, hash-verified

697// Return "arrayName[index]".
698
699/* class static */ void
700XMPUtils::ComposeArrayItemPath ( XMP_StringPtr schemaNS,
701 XMP_StringPtr arrayName,
702 XMP_Index itemIndex,
703 XMP_StringPtr * fullPath,
704 XMP_StringLen * pathSize )
705{
706 XMP_Assert ( schemaNS != 0 ); // Enforced by wrapper.
707 XMP_Assert ( *arrayName != 0 ); // Enforced by wrapper.
708 XMP_Assert ( (fullPath != 0) && (pathSize != 0) ); // Enforced by wrapper.
709
710 XMP_ExpandedXPath expPath; // Just for side effects to check namespace and basic path.
711 ExpandXPath ( schemaNS, arrayName, &expPath );
712
713 if ( (itemIndex < 0) && (itemIndex != kXMP_ArrayLastItem) ) XMP_Throw ( "Array index out of bounds", kXMPErr_BadParam );
714
715 XMP_StringLen reserveLen = strlen(arrayName) + 2 + 32; // Room plus padding.
716
717 sComposedPath->erase();
718 sComposedPath->reserve ( reserveLen );
719 sComposedPath->append ( reserveLen, ' ' );
720
721 if ( itemIndex != kXMP_ArrayLastItem ) {
722 // AUDIT: Using string->size() for the snprintf length is safe.
723 snprintf ( const_cast<char*>(sComposedPath->c_str()), sComposedPath->size(), "%s[%d]", arrayName, static_cast<int>(itemIndex) );
724 } else {
725 *sComposedPath = arrayName;
726 *sComposedPath += "[last()] ";
727 (*sComposedPath)[sComposedPath->size()-1] = 0; // ! Final null is for the strlen at exit.
728 }
729
730 *fullPath = sComposedPath->c_str();
731 *pathSize = strlen ( *fullPath ); // ! Don't use sComposedPath->size()!
732
733 XMP_Enforce ( *pathSize < sComposedPath->size() ); // Rather late, but complain about buffer overflow.
734
735} // ComposeArrayItemPath
736
737
738// -------------------------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 5

ExpandXPathFunction · 0.85
reserveMethod · 0.80
c_strMethod · 0.80
eraseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected