* src/misc/escape.hh (operator<<(std::ostream&, const escape&)):
Here.
---
ChangeLog | 7 +++++++
src/misc/escape.hh | 24 +++++++++++++++++++-----
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 448a49f..ca9dfda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-05-23 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Do not use locale in misc::escape.
+
+ * src/misc/escape.hh (operator<<(std::ostream&, const escape&)):
+ Here.
+
2012-05-22 Roland Levillain <roland(a)lrde.epita.fr>
Fix the handling of `.half' assembler directives.
diff --git a/src/misc/escape.hh b/src/misc/escape.hh
index cfa61f2..5ca2ffb 100644
--- a/src/misc/escape.hh
+++ b/src/misc/escape.hh
@@ -1,7 +1,7 @@
//
// escape.hh: escaping special characters for output
-// Copyright (C) 2003, 2004 Akim Demaille <akim(a)epita.fr> and
-// Benoit Perrot <benoit(a)lrde.epita.fr>
+// Copyright (C) 2003, 2004, 2012 Akim Demaille <akim(a)epita.fr> and
+// Benoit Perrot <benoit(a)lrde.epita.fr>
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -24,7 +24,6 @@
# include <iostream>
# include <string>
# include <cctype>
-# include <locale>
class escape
{
@@ -39,7 +38,22 @@ public:
inline std::ostream&
operator<<(std::ostream& o, const escape& e)
{
- static std::locale locale ("");
+ /* For some reason, when we use std::locale on Mac OS X, the
+ following exception may be thrown:
+
+ terminate called after throwing an instance of 'std::runtime_error'
+ what(): locale::facet::_S_create_c_locale name not valid
+
+ A workaround is to unset the environment variable `LANG' prior to
+ using std::locale, but this is cumbersome.
+
+ So we use the C locale-agnostic version of isprint() from header
+ `cctype', instead of C++ isprint() from header `locale' taking a
+ locale as second argument.
+
+ See also
+
http://stackoverflow.com/questions/1745045/stdlocale-breakage-on-macos-10-6…
+ on this topic. */
std::ios_base::fmtflags flags = o.flags (std::ios_base::hex);
for (std::string::const_iterator p = e.s_.begin (); p != e.s_.end (); ++p)
switch (*p)
@@ -54,7 +68,7 @@ operator<<(std::ostream& o, const escape& e)
case '\\': o << "\\\\"; break;
case '\"': o << "\\\""; break;
default:
- if (std::isprint (*p, locale))
+ if (std::isprint (*p))
o << *p;
else
o << "\\x"
--
1.7.2.5