Lines Matching refs:string
23 #include <string>
27 * Parameter name string supporting deferred formatting for array subscripts.
30 * a format string and a vector of index values, and performs string formatting when an accessor function is called to
31 * retrieve the name string. This class was primarily designed to be used with validation functions that receive a parameter name
32 * string and value as arguments, and print an error message that includes the parameter name when the value fails a validation
34 * formatted before each validation function is called, performing the string formatting even when the value passes validation
35 * and the string is not used:
39 * With the ParameterName class, a format string and a vector of format values are stored by the ParameterName object that is
40 * provided to the validation function. String formatting is then performed only when the validation function retrieves the
41 * name string from the ParameterName object:
46 /// Container for index values to be used with parameter name string formatting.
49 /// Format specifier for the parameter name string, to be replaced by an index value. The parameter name string must contain
51 const std::string IndexFormatSpecifier = "%i";
55 * Construct a ParameterName object from a string literal, without formatting.
57 * @param source Paramater name string without format specifiers.
59 * @pre The source string must not contain the %i format specifier.
64 * Construct a ParameterName object from a std::string object, without formatting.
66 * @param source Paramater name string without format specifiers.
68 * @pre The source string must not contain the %i format specifier.
70 ParameterName(const std::string &source) : source_(source) { assert(IsValid()); }
73 * Construct a ParameterName object from a std::string object, without formatting.
75 * @param source Paramater name string without format specifiers.
77 * @pre The source string must not contain the %i format specifier.
79 ParameterName(const std::string &&source) : source_(std::move(source)) { assert(IsValid()); }
82 * Construct a ParameterName object from a std::string object, with formatting.
84 * @param source Paramater name string with format specifiers.
87 * @pre The number of %i format specifiers contained by the source string must match the number of elements contained
90 ParameterName(const std::string &source, const IndexVector &args) : source_(source), args_(args) { assert(IsValid()); }
93 * Construct a ParameterName object from a std::string object, with formatting.
95 * @param source Paramater name string with format specifiers.
98 * @pre The number of %i format specifiers contained by the source string must match the number of elements contained
101 ParameterName(const std::string &&source, const IndexVector &&args) : source_(std::move(source)), args_(std::move(args)) {
105 /// Retrive the formatted name string.
106 std::string get_name() const { return (args_.empty()) ? source_ : Format(); }
109 /// Replace the %i format specifiers in the source string with the values from the index vector.
110 std::string Format() const {
111 std::string::size_type current = 0;
112 std::string::size_type last = 0;
117 if (current == std::string::npos) {
124 format << source_.substr(last, std::string::npos);
129 /// Check that the number of %i format specifiers in the source string matches the number of elements in the index vector.
133 std::string::size_type pos = source_.find(IndexFormatSpecifier);
135 while (pos != std::string::npos) {
144 std::string source_; ///< Format string.