示例#1
0
void LocaleUtils::CLocaleScope::set(std::ios_base &baseStream) {
	assert(orgLocale_ == NULL);

	orgLocale_ = new (static_cast<void*>(&orgLocaleStorage_)) std::locale(
			baseStream.imbue(getCLocale()));
	baseStream_ = &baseStream;
}
示例#2
0
    InItrT get(InItrT& from,
               InItrT& to,
               std::ios_base& a_ios,
               duration_type& dd) const
    {
        // skip leading whitespace
        while(std::isspace(*from) && from != to) {
            ++from;
        }

        /* num_get.get() will always consume the first character if it
         * is a sign indicator (+/-). Special value strings may begin
         * with one of these signs so we'll need a copy of it
         * in case num_get.get() fails. */
        char_type c = '\0';
        // TODO Are these characters somewhere in the locale?
        if(*from == '-' || *from == '+') {
            c = *from;
        }
        typedef std::num_get<CharT, InItrT> num_get;
        typename duration_type::duration_rep_type val = 0;
        std::ios_base::iostate err = std::ios_base::goodbit;

        if (std::has_facet<num_get>(a_ios.getloc())) {
            from = std::use_facet<num_get>(a_ios.getloc()).get(from, to, a_ios, err, val);
        }
        else {
            num_get* ng = new num_get();
            std::locale l = std::locale(a_ios.getloc(), ng);
            a_ios.imbue(l);
            from = ng->get(from, to, a_ios, err, val);
        }
        if(err & std::ios_base::failbit) {
            typedef typename special_values_parser_type::match_results match_results;
            match_results mr;
            if(c == '-' || c == '+') { // was the first character consumed?
                mr.cache += c;
            }
            m_sv_parser.match(from, to, mr);
            if(mr.current_match == match_results::PARSE_ERROR) {
                boost::throw_exception(std::ios_base::failure("Parse failed. No match found for '" + mr.cache + "'"));
                BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return from); // should never reach
            }
            dd = duration_type(static_cast<special_values>(mr.current_match));
        }
void PdfLocaleImbue(std::ios_base& s)
{
#if USE_CXX_LOCALE
    static const std::locale cachedLocale( PdfIOLocale );
    try {
    	s.imbue( cachedLocale );
    } catch (const std::runtime_error & e) {
        std::ostringstream s;
        s << "Failed to set safe locale on stream being used for PDF I/O.";
        s << "Locale set was: \"" << PdfIOLocale << "\".";
        s << "Error reported by STL std::locale: \"" << e.what() << "\"";
        // The info string is copied by PdfError so we're ok to just:
        PODOFO_RAISE_ERROR_INFO(
            ePdfError_InvalidDeviceOperation,
            s.str().c_str()
            );
    }
#endif
}
示例#4
0
    OutItrT put(OutItrT next,
                std::ios_base& a_ios,
                char_type fill_char,
                const duration_type& dd) const
    {
      if (dd.is_special()) {
        return do_put_special(next, a_ios, fill_char, dd.get_rep().as_special());
      }

      typedef std::num_put<CharT, OutItrT> num_put;
      if (std::has_facet<num_put>(a_ios.getloc())) {
        return std::use_facet<num_put>(a_ios.getloc()).put(next, a_ios, fill_char, dd.get_rep().as_number());
      }
      else {
        num_put* f = new num_put();
        std::locale l = std::locale(a_ios.getloc(), f);
        a_ios.imbue(l);
        return f->put(next, a_ios, fill_char, dd.get_rep().as_number());
      }

    }