On Fri, Nov 10, 2006 at 02:37:23PM +0100, Enrico Forestieri wrote:
> On systems where sizeof(wchar_t) == 2, there are no predefined facets
> to output an integral type to a wide stream. The only problem that I
> encontered so far is that "View Source" doesn't work for a single
> paragraph, as outputting the paragraph number invalidates the stream
> and prevents further output.
>
> The attached patch solves this problem. I'll commit it later today if
> anyone doesn't suggest anything better or has objections.
I am going to shove in the attached. There's a small optimization with
respect to the previous version.
--
Enrico
Index: src/support/docstring.C
===================================================================
--- src/support/docstring.C (revisione 15838)
+++ src/support/docstring.C (copia locale)
@@ -14,6 +14,7 @@
#include "unicode.h"
#include <locale>
+#include <iostream>
#include <boost/assert.hpp>
@@ -388,14 +389,50 @@ protected:
};
-/// class to add our ascii_ctype_facet to the global locale
+/// Facet for converting numbers to ascii strings.
+class ascii_num_put_facet : public std::num_put<char,
std::basic_string<char>::iterator>
+{
+public:
+ ascii_num_put_facet() : std::num_put<char,
std::basic_string<char>::iterator>(1) {}
+};
+
+
+/// Facet for outputting numbers to odocstreams.
+/// Here we simply need defining the virtual do_put functions.
+class odocstream_num_put_facet : public std::num_put<lyx::char_type,
std::ostreambuf_iterator<lyx::char_type, std::char_traits<lyx::char_type> > >
+{
+ typedef std::ostreambuf_iterator<lyx::char_type,
std::char_traits<lyx::char_type> > iter_type;
+public:
+ odocstream_num_put_facet(size_t refs = 0) :
std::num_put<lyx::char_type, iter_type>(refs) {}
+
+protected:
+ iter_type
+ do_put(iter_type oit, std::ios_base & b, char_type fill, long v) const
+ {
+ std::string s;
+ // 64 is large enough
+ s.resize(64);
+ ascii_num_put_facet f;
+ std::string::const_iterator cit = s.begin();
+ std::string::const_iterator end =
+ f.put(s.begin(), b, fill < 0x80 ? fill : ' ', v);
+ for (; cit != end; ++cit, ++oit)
+ *oit = *cit;
+
+ return oit;
+ }
+};
+
+
+/// class to add our facets to the global locale
class locale_initializer {
public:
locale_initializer()
{
std::locale global;
- std::locale const loc(global, new ascii_ctype_facet);
- std::locale::global(loc);
+ std::locale const loc1(global, new ascii_ctype_facet);
+ std::locale const loc2(loc1, new odocstream_num_put_facet);
+ std::locale::global(loc2);
}
};