34 #ifndef STRING_COMPOSE_H
35 #define STRING_COMPOSE_H
38 #include <boost/filesystem.hpp>
47 namespace StringPrivate
62 std::string str()
const;
72 typedef std::list<std::string> output_list;
77 typedef std::multimap<int, output_list::iterator> specification_map;
78 specification_map specs;
82 inline int char_to_int(
char c)
95 default:
return -1000;
99 inline bool is_number(
int n)
120 template <
typename T>
121 inline Composition &Composition::arg(
const T &obj)
123 os += dcp::locale_convert<std::string> (obj);
126 for (specification_map::const_iterator i = specs.lower_bound(arg_no), end = specs.upper_bound(arg_no); i != end; ++i) {
127 output_list::iterator pos = i->second;
130 output.insert(pos, os);
140 inline Composition::Composition(std::string fmt)
143 std::string::size_type b = 0, i = 0;
147 while (i < fmt.length()) {
148 if (fmt[i] ==
'%' && i + 1 < fmt.length()) {
149 if (fmt[i + 1] ==
'%') {
150 fmt.replace(i, 2,
"%");
153 else if (is_number(fmt[i + 1])) {
155 output.push_back(fmt.substr(b, i - b));
161 spec_no += char_to_int(fmt[i + n]);
164 }
while (i + n < fmt.length() && is_number(fmt[i + n]));
167 output_list::iterator pos = output.end();
170 specs.insert(specification_map::value_type(spec_no, pos));
184 output.push_back(fmt.substr(b, i - b));
187 inline std::string Composition::str()
const
192 for (output_list::const_iterator i = output.begin(), end = output.end();
206 template <
typename T1>
207 inline std::string compose(
const std::string &fmt,
const T1 &o1)
209 StringPrivate::Composition c(fmt);
214 template <
typename T1,
typename T2>
215 inline std::string compose(
const std::string &fmt,
216 const T1 &o1,
const T2 &o2)
218 StringPrivate::Composition c(fmt);
223 template <
typename T1,
typename T2,
typename T3>
224 inline std::string compose(
const std::string &fmt,
225 const T1 &o1,
const T2 &o2,
const T3 &o3)
227 StringPrivate::Composition c(fmt);
228 c.arg(o1).arg(o2).arg(o3);
232 template <
typename T1,
typename T2,
typename T3,
typename T4>
233 inline std::string compose(
const std::string &fmt,
234 const T1 &o1,
const T2 &o2,
const T3 &o3,
237 StringPrivate::Composition c(fmt);
238 c.arg(o1).arg(o2).arg(o3).arg(o4);
242 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
243 inline std::string compose(
const std::string &fmt,
244 const T1 &o1,
const T2 &o2,
const T3 &o3,
245 const T4 &o4,
const T5 &o5)
247 StringPrivate::Composition c(fmt);
248 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5);
252 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
254 inline std::string compose(
const std::string &fmt,
255 const T1 &o1,
const T2 &o2,
const T3 &o3,
256 const T4 &o4,
const T5 &o5,
const T6 &o6)
258 StringPrivate::Composition c(fmt);
259 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6);
263 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
264 typename T6,
typename T7>
265 inline std::string compose(
const std::string &fmt,
266 const T1 &o1,
const T2 &o2,
const T3 &o3,
267 const T4 &o4,
const T5 &o5,
const T6 &o6,
270 StringPrivate::Composition c(fmt);
271 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7);
275 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
276 typename T6,
typename T7,
typename T8>
277 inline std::string compose(
const std::string &fmt,
278 const T1 &o1,
const T2 &o2,
const T3 &o3,
279 const T4 &o4,
const T5 &o5,
const T6 &o6,
280 const T7 &o7,
const T8 &o8)
282 StringPrivate::Composition c(fmt);
283 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8);
287 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
288 typename T6,
typename T7,
typename T8,
typename T9>
289 inline std::string compose(
const std::string &fmt,
290 const T1 &o1,
const T2 &o2,
const T3 &o3,
291 const T4 &o4,
const T5 &o5,
const T6 &o6,
292 const T7 &o7,
const T8 &o8,
const T9 &o9)
294 StringPrivate::Composition c(fmt);
295 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9);
299 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
300 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
301 inline std::string compose(
const std::string &fmt,
302 const T1 &o1,
const T2 &o2,
const T3 &o3,
303 const T4 &o4,
const T5 &o5,
const T6 &o6,
304 const T7 &o7,
const T8 &o8,
const T9 &o9,
307 StringPrivate::Composition c(fmt);
308 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
313 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
314 typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
316 inline std::string compose(
const std::string &fmt,
317 const T1 &o1,
const T2 &o2,
const T3 &o3,
318 const T4 &o4,
const T5 &o5,
const T6 &o6,
319 const T7 &o7,
const T8 &o8,
const T9 &o9,
320 const T10 &o10,
const T11 &o11)
322 StringPrivate::Composition c(fmt);
323 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
328 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
329 typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
330 typename T11,
typename T12>
331 inline std::string compose(
const std::string &fmt,
332 const T1 &o1,
const T2 &o2,
const T3 &o3,
333 const T4 &o4,
const T5 &o5,
const T6 &o6,
334 const T7 &o7,
const T8 &o8,
const T9 &o9,
335 const T10 &o10,
const T11 &o11,
const T12 &o12)
337 StringPrivate::Composition c(fmt);
338 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
339 .arg(o10).arg(o11).arg(o12);
343 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
344 typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
345 typename T11,
typename T12,
typename T13>
346 inline std::string compose(
const std::string &fmt,
347 const T1 &o1,
const T2 &o2,
const T3 &o3,
348 const T4 &o4,
const T5 &o5,
const T6 &o6,
349 const T7 &o7,
const T8 &o8,
const T9 &o9,
350 const T10 &o10,
const T11 &o11,
const T12 &o12,
353 StringPrivate::Composition c(fmt);
354 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
355 .arg(o10).arg(o11).arg(o12).arg(o13);
359 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
360 typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
361 typename T11,
typename T12,
typename T13,
typename T14>
362 inline std::string compose(
const std::string &fmt,
363 const T1 &o1,
const T2 &o2,
const T3 &o3,
364 const T4 &o4,
const T5 &o5,
const T6 &o6,
365 const T7 &o7,
const T8 &o8,
const T9 &o9,
366 const T10 &o10,
const T11 &o11,
const T12 &o12,
367 const T13 &o13,
const T14 &o14)
369 StringPrivate::Composition c(fmt);
370 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
371 .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14);
375 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
376 typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
377 typename T11,
typename T12,
typename T13,
typename T14,
379 inline std::string compose(
const std::string &fmt,
380 const T1 &o1,
const T2 &o2,
const T3 &o3,
381 const T4 &o4,
const T5 &o5,
const T6 &o6,
382 const T7 &o7,
const T8 &o8,
const T9 &o9,
383 const T10 &o10,
const T11 &o11,
const T12 &o12,
384 const T13 &o13,
const T14 &o14,
const T15 &o15)
386 StringPrivate::Composition c(fmt);
387 c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9)
388 .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14).arg(o15);
Methods to convert to/from string using the current locale.
Namespace for everything in libdcp.