|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68884 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-14 19:21:39
Author: danieljames
Date: 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
New Revision: 68884
URL: http://svn.boost.org/trac/boost/changeset/68884
Log:
Use the new value class for images.
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 78 +++++++++++++++++++++++----------------
branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 26 -------------
branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 6 --
branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 7 +--
branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp | 15 ++++---
5 files changed, 57 insertions(+), 75 deletions(-)
Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
@@ -500,29 +500,27 @@
}
}
- void attribute_action::operator()(iterator first, iterator last) const
+ void image_action::operator()(iterator, iterator) const
{
- file_position const pos = first.get_position();
+ if(!actions.output_pre(phrase)) return;
- if (!attributes.insert(
- attribute_map::value_type(attribute_name, std::string(first, last))
- ).second)
- {
- detail::outwarn(actions.filename, pos.line)
- << "Repeated attribute: " << detail::utf8(attribute_name) << ".\n";
- }
- }
+ typedef std::map<std::string, value> attribute_map;
+ attribute_map attributes;
- void image_action::operator()(iterator first, iterator) const
- {
- if(!actions.output_pre(phrase)) return;
+ value_consumer values = actions.values.get();
+ attributes["fileref"] = values.consume();
- if(image_fileref.find('\\') != std::string::npos)
+ BOOST_FOREACH(value pair_, values)
{
- detail::outwarn(actions.filename, first.get_position().line)
- << "Image path isn't portable: "
- << detail::utf8(image_fileref)
- << std::endl;
+ value_consumer pair = pair_;
+ value name = pair.consume();
+ value value = pair.consume();
+ assert(!pair.is());
+ if(!attributes.insert(std::make_pair(name.get_quickbook(), value)).second)
+ {
+ detail::outwarn(actions.filename, name.get_position().line)
+ << "Duplicate image attribute: " << name.get_quickbook() << std::endl;
+ }
}
// Find the file basename and extension.
@@ -530,6 +528,17 @@
// Not using Boost.Filesystem because I want to stay in UTF-8.
// Need to think about uri encoding.
+ std::string image_fileref = attributes["fileref"].get_quickbook();
+
+ if(image_fileref.find('\\') != std::string::npos)
+ {
+ detail::outwarn(actions.filename, attributes["fileref"].get_position().line)
+ << "Image path isn't portable: '"
+ << detail::utf8(image_fileref)
+ << "'"
+ << std::endl;
+ }
+
std::string::size_type pos;
std::string stem,extension;
@@ -551,12 +560,11 @@
// TODO: IMO if there isn't an alt tag, then the description should
// be empty or missing.
- attribute_map::iterator it = attributes.find("alt");
- std::string alt_text = it != attributes.end() ? it->second : stem;
+ attribute_map::iterator alt_pos = attributes.find("alt");
+ std::string alt_text = alt_pos != attributes.end() ?
+ alt_pos->second.get_quickbook() : stem;
attributes.erase("alt");
- attributes.insert(attribute_map::value_type("fileref", image_fileref));
-
if(extension == ".svg")
{
//
@@ -570,7 +578,9 @@
// a tiny box with scrollbars (Firefox), or else cropped to
// fit in a tiny box (IE7).
//
- attributes.insert(attribute_map::value_type("format", "SVG"));
+
+ attributes.insert(attribute_map::value_type("format", qbk_value("SVG")));
+
//
// Image paths are relative to the html subdirectory:
//
@@ -605,8 +615,10 @@
b = svg_text.find('\"', a + 1);
if(a != std::string::npos)
{
- attributes.insert(attribute_map::value_type("contentwidth",
- std::string(svg_text.begin() + a + 1, svg_text.begin() + b)));
+ attributes.insert(std::make_pair(
+ "contentwidth", qbk_value(std::string(
+ svg_text.begin() + a + 1, svg_text.begin() + b))
+ ));
}
a = svg_text.find("height");
a = svg_text.find('=', a);
@@ -614,8 +626,10 @@
b = svg_text.find('\"', a + 1);
if(a != std::string::npos)
{
- attributes.insert(attribute_map::value_type("contentdepth",
- std::string(svg_text.begin() + a + 1, svg_text.begin() + b)));
+ attributes.insert(std::make_pair(
+ "contentdepth", qbk_value(std::string(
+ svg_text.begin() + a + 1, svg_text.begin() + b))
+ ));
}
}
@@ -623,15 +637,13 @@
phrase << "<imageobject><imagedata";
- for(attribute_map::const_iterator
- attr_first = attributes.begin(), attr_last = attributes.end();
- attr_first != attr_last; ++attr_first)
+ BOOST_FOREACH(attribute_map::value_type const& attr, attributes)
{
- phrase << " " << attr_first->first << "=\"";
+ phrase << " " << attr.first << "=\"";
+ std::string value = attr.second.get_quickbook();
for(std::string::const_iterator
- first = attr_first->second.begin(),
- last = attr_first->second.end();
+ first = value.begin(), last = value.end();
first != last; ++first)
{
if (*first == '\\' && ++first == last) break;
Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
@@ -64,7 +64,6 @@
}
typedef cl::symbols<std::string> string_symbols;
- typedef std::map<std::string, std::string> attribute_map;
int load_snippets(std::string const& file, std::vector<template_symbol>& storage,
std::string const& extension, std::string const& doc_id);
@@ -511,44 +510,19 @@
quickbook::actions& actions;
};
- struct attribute_action
- {
- // Handle image attributes
-
- attribute_action(
- attribute_map& attributes
- , std::string& attribute_name
- , quickbook::actions& actions)
- : attributes(attributes)
- , attribute_name(attribute_name)
- , actions(actions) {}
-
- void operator()(iterator first, iterator last) const;
-
- attribute_map& attributes;
- std::string& attribute_name;
- quickbook::actions& actions;
- };
-
struct image_action
{
// Handles inline images
image_action(
collector& phrase
- , attribute_map& attributes
- , std::string& image_fileref
, quickbook::actions& actions)
: phrase(phrase)
- , attributes(attributes)
- , image_fileref(image_fileref)
, actions(actions) {}
void operator()(iterator first, iterator last) const;
collector& phrase;
- attribute_map& attributes;
- std::string& image_fileref;
quickbook::actions& actions;
};
Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
@@ -69,9 +69,6 @@
, template_escape(false)
, templates()
, error_count(0)
- , image_fileref()
- , attribute_name()
- , attributes()
, anchors()
, saved_anchors()
, no_eols(true)
@@ -119,8 +116,7 @@
, plain_char(phrase, *this)
, raw_char(phrase, *this)
, escape_unicode(phrase, *this)
- , attribute(attributes, attribute_name, *this)
- , image(phrase, attributes, image_fileref, *this)
+ , image(phrase, *this)
, cond_phrase_pre(condition, macro)
, scoped_cond_phrase(*this)
Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
@@ -12,6 +12,7 @@
#include "actions.hpp"
#include "scoped_parser.hpp"
+#include "values_parse.hpp"
#include <boost/tuple/tuple.hpp>
#include <boost/scoped_ptr.hpp>
@@ -44,6 +45,8 @@
typedef std::pair<char, int> mark_type;
static int const max_template_depth = 100;
+ value_parser values;
+
// header info
std::string doc_type;
docinfo_string doc_title;
@@ -118,9 +121,6 @@
template_args;
template_stack templates;
int error_count;
- std::string image_fileref;
- std::string attribute_name;
- attribute_map attributes;
string_list anchors;
string_list saved_anchors;
bool no_eols;
@@ -170,7 +170,6 @@
plain_char_action plain_char;
raw_char_action raw_char;
escape_unicode_action escape_unicode;
- attribute_action attribute;
image_action image;
cond_phrase_action_pre cond_phrase_pre;
scoped_parser<cond_phrase_push>
Modified: branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/phrase_element_grammar.cpp 2011-02-14 19:21:37 EST (Mon, 14 Feb 2011)
@@ -55,25 +55,26 @@
;
local.image =
- blank [cl::clear_a(actions.attributes)]
+ blank [actions.values.reset]
>> cl::if_p(qbk_since(105u)) [
(+(
*cl::space_p
>> +(cl::anychar_p - (cl::space_p | phrase_end | '['))
- )) [cl::assign_a(actions.image_fileref)]
+ )) [actions.values.entry]
>> hard_space
- >> *(
+ >> *actions.values.scoped[
'['
- >> (*(cl::alnum_p | '_')) [cl::assign_a(actions.attribute_name)]
+ >> (*(cl::alnum_p | '_'))
+ [actions.values.entry]
>> space
>> (*(cl::anychar_p - (phrase_end | '[')))
- [actions.attribute]
+ [actions.values.entry]
>> ']'
>> space
- )
+ ]
].else_p [
(*(cl::anychar_p - phrase_end))
- [cl::assign_a(actions.image_fileref)]
+ [actions.values.entry]
]
>> cl::eps_p(']') [actions.image]
;
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