OpenAssetIO
An abstract API for generalising interactions between a host application and an asset management system
openassetio::v1::utils Namespace Reference

Classes

class  FileUrlPathConverter
 Utility class for converting between file system paths and file URLs. More...
 

Enumerations

enum  PathType : std::uint8_t { kSystem = 0, kPOSIX, kWindows }
 Indicator of platform type associate with a path. More...
 

Functions

OPENASSETIO_CORE_EXPORT openassetio::Str substitute (std::string_view input, const openassetio::InfoDictionary &substitutions)
 Substitute placeholders in a given string using the provided dictionary mapping of tokens to values. More...
 

Enumeration Type Documentation

enum PathType : std::uint8_t
strong

Indicator of platform type associate with a path.

Enumerator
kSystem 

Use the current system platform to determine path type.

kPOSIX 

Assume a POSIX path.

kWindows 

Assume a Windows path (including UNC).

Function Documentation

OPENASSETIO_CORE_EXPORT openassetio::Str openassetio::v1::utils::substitute ( std::string_view  input,
const openassetio::InfoDictionary &  substitutions 
)

Substitute placeholders in a given string using the provided dictionary mapping of tokens to values.

The input string can contain placeholders in the form of {key} where key is a key in the provided dictionary. The placeholder will be replaced by the corresponding value from the dictionary.

All placeholders must be valid keys in the dictionary. If a placeholder is not found in the dictionary, an exception will be thrown.

Integers can be zero-padded in the format string. For example, {key:03d} will replace the placeholder with the integer value of key from the dictionary, padded with zeros to a width of 3 digits. The format specifier follows libfmt / Python format string syntax.

Note that no format specifiers other than zero-padding are officially supported, though other specifiers may work. This is to keep the interop surface area as small as possible, e.g. to ease cross-language support.

Parameters
inputThe string in which substitutions are to be made.
substitutionsThe dictionary containing the keys to be replaced and their corresponding values.
Returns
The input string with all valid substitutions made.
Exceptions
errors.InputValidationExceptionif a substitution variable is not found in the dictionary.