|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68396 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-01-23 11:48:34
Author: danieljames
Date: 2011-01-23 11:48:27 EST (Sun, 23 Jan 2011)
New Revision: 68396
URL: http://svn.boost.org/trac/boost/changeset/68396
Log:
Use a function to convert paths to and from utf-8.
This will eventually try to cope with unicode characters. Not sure if
it'll ever be truely cross platform.
Text files modified:
branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 54 ++++++++++++++++++++++++++++-----------
branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 3 +
branches/quickbook-filenames/tools/quickbook/src/input_path.cpp | 16 +++++++++++
branches/quickbook-filenames/tools/quickbook/src/input_path.hpp | 5 +++
4 files changed, 62 insertions(+), 16 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-01-23 11:48:27 EST (Sun, 23 Jan 2011)
@@ -20,6 +20,7 @@
#include "markups.hpp"
#include "actions_class.hpp"
#include "grammar.hpp"
+#include "input_path.hpp"
namespace quickbook
{
@@ -506,17 +507,38 @@
{
if(!actions.output_pre(phrase)) return;
- fs::path const img_path(image_fileref);
-
+ // Find the file basename and extension.
+ //
+ // Not using Boost.Filesystem because I want to stay in UTF-8.
+ // Need to think about uri encoding.
+
+ std::string::size_type pos;
+ std::string stem,extension;
+
+ pos = image_fileref.rfind('/');
+ stem = pos == std::string::npos ?
+ image_fileref :
+ image_fileref.substr(pos + 1);
+
+ pos = stem.rfind('.');
+ if (pos != std::string::npos)
+ {
+ extension = stem.substr(pos + 1);
+ stem = stem.substr(0, pos);
+ }
+
+ // Extract the alt tag, to use as a text description.
+ // Or if there isn't one, use the stem of the file name.
+ // 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 :
- img_path.stem().generic_string();
+ std::string alt_text = it != attributes.end() ? it->second : stem;
attributes.erase("alt");
attributes.insert(attribute_map::value_type("fileref", image_fileref));
- if(img_path.extension() == ".svg")
+ if(extension == ".svg")
{
//
// SVG's need special handling:
@@ -533,11 +555,12 @@
//
// Image paths are relative to the html subdirectory:
//
- fs::path img;
- if(img_path.root_path().empty())
- img = "html" / img_path; // relative path
- else
- img = img_path; // absolute path
+ // TODO: This seems wrong to me.
+ //
+ fs::path img = detail::generic_to_path(image_fileref);
+ if(img.root_path().empty())
+ img = "html" / img; // relative path
+
//
// Now load the SVG file:
//
@@ -601,8 +624,8 @@
phrase << "></imagedata></imageobject>";
- // Also add a textobject -- use the basename of the image file.
- // This will mean we get "alt" attributes of the HTML img.
+ // Add a textobject containing the alt tag from earlier.
+ // This will be used for the alt tag in html.
phrase << "<textobject><phrase>";
detail::print_string(alt_text, phrase.get());
phrase << "</phrase></textobject>";
@@ -1301,7 +1324,7 @@
{
// Given a source file and the current filename, calculate the
// path to the source file relative to the output directory.
- fs::path path(std::string(first, last));
+ fs::path path = detail::generic_to_path(std::string(first, last));
if (!path.is_complete())
{
fs::path infile = fs::absolute(actions.filename).normalize();
@@ -1420,7 +1443,8 @@
}
// update the __FILENAME__ macro
- *boost::spirit::classic::find(actions.macro, "__FILENAME__") = actions.filename.generic_string();
+ *boost::spirit::classic::find(actions.macro, "__FILENAME__")
+ = detail::path_to_generic(actions.filename);
// parse the file
quickbook::parse_file(actions.filename.string().c_str(), actions, true);
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-01-23 11:48:27 EST (Sun, 23 Jan 2011)
@@ -12,6 +12,7 @@
#include "markups.hpp"
#include "quickbook.hpp"
#include "grammar.hpp"
+#include "input_path.hpp"
#if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
#pragma warning(disable:4355)
@@ -207,7 +208,7 @@
// turn off __FILENAME__ macro on debug mode = true
std::string filename_str = debug_mode ?
std::string("NO_FILENAME_MACRO_GENERATED_IN_DEBUG_MODE") :
- filename.generic_string();
+ detail::path_to_generic(filename);
// add the predefined macros
macro.add
Modified: branches/quickbook-filenames/tools/quickbook/src/input_path.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/input_path.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/input_path.cpp 2011-01-23 11:48:27 EST (Sun, 23 Jan 2011)
@@ -9,6 +9,22 @@
#include <boost/program_options.hpp>
#include "input_path.hpp"
+namespace quickbook {
+namespace detail {
+ // TODO: These don't work for unicode strings on windows.
+
+ fs::path generic_to_path(std::string const& x)
+ {
+ return fs::path(x);
+ }
+
+ std::string path_to_generic(fs::path const& x)
+ {
+ return x.generic_string();
+ }
+}
+}
+
#if !(defined(__cygwin__) || defined(__CYGWIN__))
// Everything but cygwin
Modified: branches/quickbook-filenames/tools/quickbook/src/input_path.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/input_path.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/input_path.hpp 2011-01-23 11:48:27 EST (Sun, 23 Jan 2011)
@@ -22,6 +22,11 @@
// our internal path type. Mainly used to convert cygwin paths, but
// might be useful elsewhere.
fs::path native_to_path(fs::path::string_type const&);
+
+ // Conversion of filenames to and from genertic utf-8 paths
+ // (such as those used in quickbook and the generated boostbook)
+ fs::path generic_to_path(std::string const&);
+ std::string path_to_generic(fs::path const&);
}
}
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