7 #ifndef BOOST_LOCALE_MESSAGE_HPP_INCLUDED 8 #define BOOST_LOCALE_MESSAGE_HPP_INCLUDED 10 #include <boost/locale/formatting.hpp> 17 # pragma warning(push) 18 # pragma warning(disable : 4275 4251 4231 4660) 41 template<
typename CharType>
42 struct base_message_format;
49 template<
typename CharType>
50 class BOOST_SYMBOL_VISIBLE
message_format :
public base_message_format<CharType>
80 virtual char_type
const *get(
int domain_id,char_type
const *context,char_type
const *
id)
const = 0;
94 virtual char_type
const *get(
int domain_id,char_type
const *context,char_type
const *single_id,
int n)
const = 0;
109 virtual char_type
const *convert(char_type
const *msg,string_type &buffer)
const = 0;
111 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) 112 std::locale::id& __get_id (
void)
const {
return id; }
115 virtual ~message_format() {}
121 inline bool is_us_ascii_char(
char c)
124 return 0<c && c<0x7F;
126 inline bool is_us_ascii_string(
char const *msg)
129 if(!is_us_ascii_char(*msg++))
135 template<
typename CharType>
136 struct string_cast_traits {
137 static CharType
const *cast(CharType
const *msg,std::basic_string<CharType> &)
144 struct string_cast_traits<char> {
145 static char const *cast(
char const *msg,std::string &buffer)
147 if(is_us_ascii_string(msg))
149 buffer.reserve(strlen(msg));
151 while((c=*msg++)!=0) {
152 if(is_us_ascii_char(c))
155 return buffer.c_str();
169 template<
typename CharType>
304 c_context_(other.c_context_),
305 c_plural_(other.c_plural_),
307 context_(other.context_),
308 plural_(other.plural_)
330 std::swap(n_,other.n_);
331 std::swap(c_id_,other.c_id_);
332 std::swap(c_context_,other.c_context_);
333 std::swap(c_plural_,other.c_plural_);
336 context_.swap(other.context_);
337 plural_.swap(other.plural_);
363 return str(locale,0);
372 if(std::has_facet<facet_type>(locale))
373 id=std::use_facet<facet_type>(locale).domain(domain_id);
374 return str(locale,
id);
384 if(std::has_facet<facet_type>(loc))
385 id=std::use_facet<facet_type>(loc).domain(domain_id);
397 if(ptr == buffer.c_str())
409 void write(std::basic_ostream<char_type> &out)
const 411 std::locale
const &loc = out.getloc();
414 out <<
write(loc,
id,buffer);
424 return plural_.c_str();
432 return context_.c_str();
437 return c_id_ ? c_id_ : id_.c_str();
443 static const char_type empty_string[1] = {0};
446 char_type const *context = this->context();
447 char_type const *plural = this->plural();
453 if(std::has_facet<facet_type>(loc))
454 facet = &std::use_facet<facet_type>(loc);
458 translated = facet->get(domain_id,context,
id);
461 translated = facet->get(domain_id,context,
id,n_);
466 char_type const *msg = plural ? ( n_ == 1 ? id : plural) :
id;
469 translated = facet->convert(msg,buffer);
472 translated = details::string_cast_traits<char_type>::cast(msg,buffer);
498 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T 504 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T 514 template<
typename CharType>
528 template<
typename CharType>
536 template<
typename CharType>
545 template<
typename CharType>
547 CharType
const *plural,
555 template<
typename CharType>
557 CharType
const *single,
558 CharType
const *plural,
567 template<
typename CharType>
576 template<
typename CharType>
578 std::basic_string<CharType>
const &msg)
585 template<
typename CharType>
587 std::basic_string<CharType>
const &single,
588 std::basic_string<CharType>
const &plural,
598 template<
typename CharType>
600 std::basic_string<CharType>
const &plural,
615 template<
typename CharType>
616 std::basic_string<CharType>
gettext(CharType
const *
id,
617 std::locale
const &loc=std::locale())
624 template<
typename CharType>
625 std::basic_string<CharType>
ngettext( CharType
const *s,
628 std::locale
const &loc=std::locale())
635 template<
typename CharType>
638 std::locale
const &loc=std::locale())
646 template<
typename CharType>
651 std::locale
const &loc=std::locale())
658 template<
typename CharType>
659 std::basic_string<CharType>
pgettext( CharType
const *context,
661 std::locale
const &loc=std::locale())
668 template<
typename CharType>
669 std::basic_string<CharType>
npgettext( CharType
const *context,
673 std::locale
const &loc=std::locale())
680 template<
typename CharType>
682 CharType
const *context,
684 std::locale
const &loc=std::locale())
691 template<
typename CharType>
693 CharType
const *context,
697 std::locale
const &loc=std::locale())
707 struct BOOST_LOCALE_DECL base_message_format<char> :
public std::locale::facet
709 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
712 static std::locale::id id;
716 struct BOOST_LOCALE_DECL base_message_format<wchar_t> :
public std::locale::facet
718 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
721 static std::locale::id id;
724 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T 727 struct BOOST_LOCALE_DECL base_message_format<char16_t> :
public std::locale::facet
729 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
732 static std::locale::id id;
737 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T 740 struct BOOST_LOCALE_DECL base_message_format<char32_t> :
public std::locale::facet
742 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
745 static std::locale::id id;
762 template<
typename CharType>
763 std::basic_ostream<CharType> &
operator<<(std::basic_ostream<CharType> &out, set_domain
const &dom)
765 int id = std::use_facet<message_format<CharType> >(out.getloc()).
domain(dom.domain_id);
783 #ifdef BOOST_LOCALE_DOXYGEN 790 details::set_domain tmp = {
id };
std::basic_string< CharType > ngettext(CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.hpp:625
message_format(size_t refs=0)
Definition: message.hpp:66
basic_message(char_type const *context, char_type const *id)
Definition: message.hpp:219
string_type str(std::string const &domain_id) const
Definition: message.hpp:380
basic_message(string_type const &id)
Definition: message.hpp:245
CharType char_type
The character this message object is used with.
Definition: message.hpp:173
basic_message(string_type const &context, string_type const &id)
Definition: message.hpp:272
std::basic_string< char_type > string_type
The string type this object can be used with.
Definition: message.hpp:174
void swap(basic_message &other)
Definition: message.hpp:328
basic_message(char_type const *id)
Definition: message.hpp:192
basic_message< wchar_t > wmessage
Definition: message.hpp:497
This class represents a message that can be converted to a specific locale message.
Definition: message.hpp:170
std::basic_string< CharType > npgettext(CharType const *context, CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.hpp:669
basic_message< char32_t > u32message
Definition: message.hpp:508
string_type str() const
Definition: message.hpp:352
basic_message const & operator=(basic_message const &other)
Definition: message.hpp:315
string_type str(std::locale const &loc, int id) const
Definition: message.hpp:393
std::basic_string< CharType > dnpgettext(char const *domain, CharType const *context, CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.hpp:692
std::ios_base & number(std::ios_base &ios)
Definition: formatting.hpp:292
CharType char_type
Definition: message.hpp:57
basic_message< char > message
Definition: message.hpp:493
basic_message(string_type const &single, string_type const &plural, int number)
Definition: message.hpp:259
static ios_info & get(std::ios_base &ios)
basic_message()
Definition: message.hpp:180
std::basic_string< CharType > dgettext(char const *domain, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:636
basic_message< CharType > translate(CharType const *msg)
Translate a message, msg is not copied.
Definition: message.hpp:529
unspecified_type domain(std::string const &id)
Definition: message.hpp:788
std::basic_string< CharType > pgettext(CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:659
basic_message(string_type const &context, string_type const &single, string_type const &plural, int number)
Definition: message.hpp:287
std::basic_string< CharType > dpgettext(char const *domain, CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:681
string_type str(std::locale const &locale, std::string const &domain_id) const
Definition: message.hpp:369
void write(std::basic_ostream< char_type > &out) const
Definition: message.hpp:409
basic_message< char16_t > u16message
Definition: message.hpp:502
std::basic_string< CharType > gettext(CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:616
basic_message(char_type const *single, char_type const *plural, int n)
Definition: message.hpp:206
std::basic_ostream< CharType > & operator<<(std::basic_ostream< CharType > &out, date_time const &t)
Definition: date_time.hpp:871
basic_message(char_type const *context, char_type const *single, char_type const *plural, int n)
Definition: message.hpp:233
std::basic_string< CharType > string_type
Definition: message.hpp:61
string_type str(std::locale const &locale) const
Definition: message.hpp:361
message_format< char_type > facet_type
The type of the facet the messages are fetched with.
Definition: message.hpp:175
std::basic_string< CharType > dngettext(char const *domain, CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.hpp:647
Domain code - for message formatting.
Definition: formatting.hpp:86
basic_message(basic_message const &other)
Definition: message.hpp:301