Opened 16 years ago

Closed 5 years ago

#859 closed Bugs (fixed)

boost::format ignores a user defined locale

Reported by: nobody Owned by: James E. King, III
Milestone: Component: format
Version: Boost 1.34.0 Severity: Problem
Keywords: Cc: jonathan.jones@…

Description (last modified by René Rivera)

Altough someone can supply a user locale to boost::format, it isn't recognized.

const std::locale& userLocale = getUserLocale(); 
boost::format formatter (formatString, userLocale);

I could fix the problem in feed_args.hpp, function put, line 133 (boost 1.33.1):

133  basic_oaltstringstream<Ch, Tr, Alloc>  oss( &buf);
+    if (loc_p)
+    {
+      oss.imbue (*loc_p);
+    }
        

Change History (9)

comment:1 by Samuel Krempp, 15 years ago

Owner: changed from samuel_k to Samuel Krempp
Severity: Problem
Status: assignednew

comment:2 by René Rivera, 15 years ago

Component: Noneformat
Description: modified (diff)

comment:3 by Samuel Krempp, 13 years ago

Resolution: Noneinvalid
Status: newclosed

Do you have a sample program exhibiting an issue ?

The locale passed to boost::format constructor is not ignored, it is passed as "default" locale (i.e. last argument) to the put function by distribute : put<Ch, Tr, Alloc, T> (x, self.items_[i], self.items_[i].res_, self.buf_, boost::get_pointer(self.loc_) );

The put function itself relies on format_item's apply_on function to apply item's format state+locale (which will be self.loc_ unless an item's own locale was set in some way).

I will take a deeper look into format's locale handling - there is surely room for improvement here and there, and at least add a paragraph to the documentation with simple examples.

But user-defined locales are not "ignored", so closing the ticket as "invalid" unless sample complete program is supplied.

comment:4 by anonymous, 10 years ago

Resolution: invalid
Status: closedreopened

problem here isn't that locale is ignored problem that method os.fill that tries to use facet before imbue to the stream see actor for the stream_format_state

if(width_ != -1)

os.width(width_);

if(precision_ != -1)

os.precision(precision_);

if(fill_ != 0)

os.fill(fill_);

os.flags(flags_); os.clear(rdstate_); os.exceptions(exceptions_);

#if !defined(BOOST_NO_STD_LOCALE)

if(loc_)

os.imbue(loc_.get());

else if(loc_default)

os.imbue(*loc_default);

#else

(void) loc_default; keep compiler quiet if we don't support locales

#endif

imbue should be at very beginning of the actor, not at the very end

comment:5 by dmarkman@…, 10 years ago

we're getting segv for using boost::basic_format<char16_t> with appropriate locale with all appropriate facets because method os.fill uses std::ctype<char16_t> facet that wasn't ready

comment:6 by Jonathan Jones <jonathan.jones@…>, 10 years ago

Cc: jonathan.jones@… added

comment:7 by Chris Newbold, 10 years ago

We've applied the following patch locally, which appears to resolve the issues described above:

==== boost/boost/format/internals.hpp#4 (text) ====

***************
*** 105,110 ****
--- 105,118 ----
      void stream_format_state<Ch,Tr>:: apply_on (basic_ios & os,
                        boost::io::detail::locale_t * loc_default) const {
          // set the state of this stream according to our params
+ #if !defined(BOOST_NO_STD_LOCALE)
+         if(loc_)
+             os.imbue(loc_.get());
+         else if(loc_default)
+             os.imbue(*loc_default);
+ #else
+         (void) loc_default; // keep compiler quiet if we don't support locales
+ #endif        
          if(width_ != -1)
              os.width(width_);
          if(precision_ != -1)
***************
*** 114,127 ****
          os.flags(flags_);
          os.clear(rdstate_);
          os.exceptions(exceptions_);
- #if !defined(BOOST_NO_STD_LOCALE)
-         if(loc_)
-             os.imbue(loc_.get());
-         else if(loc_default)
-             os.imbue(*loc_default);
- #else
-         (void) loc_default; // keep compiler quiet if we don't support locales
- #endif        
      }
  
      template<class Ch, class Tr>
--- 122,127 ----

comment:8 by James E. King, III, 5 years ago

Owner: changed from Samuel Krempp to James E. King, III
Status: reopenednew
Version: NoneBoost 1.34.0

comment:9 by James E. King, III, 5 years ago

Resolution: fixed
Status: newclosed

This patch is present since 1.56.0.

Note: See TracTickets for help on using tickets.