|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69317 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-27 05:08:55
Author: danieljames
Date: 2011-02-27 05:08:47 EST (Sun, 27 Feb 2011)
New Revision: 69317
URL: http://svn.boost.org/trac/boost/changeset/69317
Log:
Decouple post_process.
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/post_process.cpp | 41 +++++++++------------------------------
branches/quickbook-filenames/tools/quickbook/src/post_process.hpp | 12 ++++++++--
branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp | 14 ++++++++++++
3 files changed, 32 insertions(+), 35 deletions(-)
Modified: branches/quickbook-filenames/tools/quickbook/src/post_process.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/post_process.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/post_process.cpp 2011-02-27 05:08:47 EST (Sun, 27 Feb 2011)
@@ -7,7 +7,6 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include "post_process.hpp"
-#include "input_path.hpp"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/bind.hpp>
#include <set>
@@ -419,9 +418,8 @@
int indent;
};
- int post_process(
+ std::string post_process(
std::string const& in
- , std::ostream& out
, int indent
, int linewidth)
{
@@ -430,36 +428,17 @@
if (linewidth == -1)
linewidth = 80; // set default to 80
- try
+ std::string tidy;
+ tidy_compiler state(tidy, linewidth);
+ tidy_grammar g(state, indent);
+ cl::parse_info<iter_type> r = parse(in.begin(), in.end(), g, cl::space_p);
+ if (r.full)
{
- std::string tidy;
- tidy_compiler state(tidy, linewidth);
- tidy_grammar g(state, indent);
- cl::parse_info<iter_type> r = parse(in.begin(), in.end(), g, cl::space_p);
- if (r.full)
- {
- out << tidy;
- return 0;
- }
- else
- {
- // fallback!
- ::quickbook::detail::outerr()
- << "Warning: Post Processing Failed."
- << std::endl;
- out << in;
- return 1;
- }
+ return tidy;
}
-
- catch(...)
- {
- // fallback!
- ::quickbook::detail::outerr()
- << "Post Processing Failed."
- << std::endl;
- out << in;
- return 1;
+ else
+ {
+ throw quickbook::post_process_failure("Post Processing Failed.");
}
}
}
Modified: branches/quickbook-filenames/tools/quickbook/src/post_process.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/post_process.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/post_process.hpp 2011-02-27 05:08:47 EST (Sun, 27 Feb 2011)
@@ -9,16 +9,22 @@
#if !defined(BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP)
#define BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP
-#include <iostream>
#include <string>
+#include <stdexcept>
namespace quickbook
{
- int post_process(
+ std::string post_process(
std::string const& in
- , std::ostream& out
, int indent
, int linewidth);
+
+ class post_process_failure : std::runtime_error
+ {
+ public:
+ post_process_failure(std::string const& error)
+ : std::runtime_error(error) {}
+ };
}
#endif // BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP
Modified: branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp 2011-02-27 05:08:47 EST (Sun, 27 Feb 2011)
@@ -149,7 +149,19 @@
if (pretty_print)
{
- result = post_process(buffer.str(), fileout, indent, linewidth);
+ try
+ {
+ fileout << post_process(buffer.str(), indent, linewidth);
+ }
+ catch (quickbook::post_process_failure&)
+ {
+ // fallback!
+ ::quickbook::detail::outerr()
+ << "Post Processing Failed."
+ << std::endl;
+ fileout << buffer.str();
+ return 1;
+ }
}
else
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk