X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fcompose.hpp;h=479493f1461e5e7b0b9ab012eed013bfb96acc35;hp=aa67b5a1fd8bc9f1027ab272b20c93ff744d8732;hb=2d4e8c5f69cc694625ad95dcee554499605f823b;hpb=8c7a308c03e4b4196b4e2379a26d432b100ae2b1 diff --git a/src/lib/compose.hpp b/src/lib/compose.hpp index aa67b5a1f..479493f14 100644 --- a/src/lib/compose.hpp +++ b/src/lib/compose.hpp @@ -1,4 +1,5 @@ -/* Defines String::compose(fmt, arg...) for easy, i18n-friendly +/* -*- c-basic-offset: 2 -*- + * Defines String::compose(fmt, arg...) for easy, i18n-friendly * composition of strings. * * Version 1.0. @@ -30,13 +31,16 @@ // more details. // -#ifndef STRING_COMPOSE_H -#define STRING_COMPOSE_H +#ifndef DCPOMATIC_STRING_COMPOSE_H +#define DCPOMATIC_STRING_COMPOSE_H +#include +#include #include #include -#include // for multimap -#include "safe_stringstream.h" +#include +#include +#include namespace StringPrivate { @@ -56,7 +60,7 @@ namespace StringPrivate std::string str() const; private: - SafeStringStream os; + std::string os; int arg_no; // we store the output as a list - when the output string is requested, the @@ -104,35 +108,30 @@ namespace StringPrivate case '8': case '9': return true; - + default: return false; } } - // implementation of class Composition template inline Composition &Composition::arg(const T &obj) { - os << obj; + os += dcp::locale_convert(obj); - std::string rep = os.str(); - - if (!rep.empty()) { // manipulators don't produce output - for (specification_map::const_iterator i = specs.lower_bound(arg_no), - end = specs.upper_bound(arg_no); i != end; ++i) { + if (!os.empty()) { // manipulators don't produce output + for (specification_map::const_iterator i = specs.lower_bound(arg_no), end = specs.upper_bound(arg_no); i != end; ++i) { output_list::iterator pos = i->second; ++pos; - - output.insert(pos, rep); + + output.insert(pos, os); } - - os.str(std::string()); - //os.clear(); + + os = ""; ++arg_no; } - + return *this; } @@ -140,7 +139,7 @@ namespace StringPrivate : arg_no(1) { std::string::size_type b = 0, i = 0; - + // fill in output with the strings between the %1 %2 %3 etc. and // fill in specs with the positions while (i < fmt.length()) { @@ -152,7 +151,7 @@ namespace StringPrivate else if (is_number(fmt[i + 1])) { // aha! a spec! // save string output.push_back(fmt.substr(b, i - b)); - + int n = 1; // number of digits int spec_no = 0; @@ -165,9 +164,9 @@ namespace StringPrivate spec_no /= 10; output_list::iterator pos = output.end(); --pos; // safe since we have just inserted a string> - + specs.insert(specification_map::value_type(spec_no, pos)); - + // jump over spec string i += n; b = i; @@ -178,7 +177,7 @@ namespace StringPrivate else ++i; } - + if (i - b > 0) // add the rest of the string output.push_back(fmt.substr(b, i - b)); } @@ -187,17 +186,17 @@ namespace StringPrivate { // assemble string std::string str; - + for (output_list::const_iterator i = output.begin(), end = output.end(); i != end; ++i) str += *i; - + return str; } } // now for the real thing(s) -namespace String +namespace String { // a series of functions which accept a format string on the form "text %1 // more %2 less %3" and a number of templated parameters and spits out the @@ -308,7 +307,7 @@ namespace String .arg(o10); return c.str(); } - + template