Ticket #2867: format.2.patch

File format.2.patch, 3.6 KB (added by Joel Falcou <joel.falcou@…>, 13 years ago)

Method renaming

Line 
1Index: boost/format/format_class.hpp
2===================================================================
3--- boost/format/format_class.hpp (revision 51826)
4+++ boost/format/format_class.hpp (working copy)
5@@ -50,12 +50,22 @@
6 #endif
7 io::detail::locale_t getloc() const;
8
9+ // The total number of arguments expected to be passed to the format
10string.
11+ int expected_args() const
12+ { return num_args_; }
13+ // The number of arguments currently bound to the format string.
14+ int bound_args() const
15+ { return cur_arg_; }
16+ // The number of arguments still required to be passed to the format
17string.
18+ int remaining_args() const
19+ { return expected_args() - bound_args(); }
20+
21 basic_format& clear(); // empty all converted string buffers
22(except bound items)
23 basic_format& clear_binds(); // unbind all bound items, and call
24clear()
25 basic_format& parse(const string_type&); // resets buffers and parse a
26new format string
27
28 // ** formatted result ** //
29- size_type size() const; // sum of the current string pieces sizes
30+ size_type size() const; // The number of characters in the
31formatted result string.
32 string_type str() const; // final string
33
34 // ** arguments passing ** //
35@@ -127,7 +137,7 @@
36 std::vector<format_item_t> items_; // each '%..' directive leads to a
37format_item
38 std::vector<bool> bound_; // stores which arguments were bound. size()
39== 0 || num_args
40
41- int style_; // style of format-string : positional or
42not, etc
43+ int style_; // style of format-string : positional or
44not, etc
45 int cur_arg_; // keep track of wich argument is current
46 int num_args_; // number of expected arguments
47 mutable bool dumped_; // true only after call to str() or <<
48Index: libs/format/test/format_test3.cpp
49===================================================================
50--- libs/format/test/format_test3.cpp (revision 51826)
51+++ libs/format/test/format_test3.cpp (working copy)
52@@ -93,6 +93,31 @@
53 BOOST_ERROR("nesting did not work");
54 }
55
56+ // observers
57+ BOOST_CHECK_EQUAL(format("foo").expected_args(), 0);
58+ BOOST_CHECK_EQUAL(format("foo").bound_args(), 0);
59+ BOOST_CHECK_EQUAL(format("foo").remaining_args(), 0);
60+
61+ BOOST_CHECK_EQUAL(format("foo%s").expected_args(), 1);
62+ BOOST_CHECK_EQUAL(format("foo%s").bound_args(), 0);
63+ BOOST_CHECK_EQUAL(format("foo%s").remaining_args(), 1);
64+
65+ BOOST_CHECK_EQUAL((format("foo%s") % "bar").expected_args(), 1);
66+ BOOST_CHECK_EQUAL((format("foo%s") % "bar").bound_args(), 1);
67+ BOOST_CHECK_EQUAL((format("foo%s") % "bar").remaining_args(), 0);
68+
69+ BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").expected_args(),
702);
71+ BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").bound_args(), 2);
72+ BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").remaining_args(),
730);
74+
75+ BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").expected_args(),
762);
77+ BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").bound_args(), 1);
78+ BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").remaining_args(),
791);
80+
81+ BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" %
82"bar").expected_args(), 3);
83+ BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" %
84"bar").bound_args(), 2);
85+ BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" %
86"bar").remaining_args(), 1);
87+
88 // testcase for bug reported at
89 // http://lists.boost.org/boost-users/2006/05/19723.php
90 format f("%40t%1%");