8 #ifndef BOOST_LOCALE_MESSAGE_HPP_INCLUDED
9 #define BOOST_LOCALE_MESSAGE_HPP_INCLUDED
11 #include <boost/locale/config.hpp>
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
21 #include <boost/locale/formatting.hpp>
36 template<
typename CharType>
37 struct base_message_format:
public std::locale::facet
46 template<
typename CharType>
64 base_message_format<CharType>(refs)
109 #if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
110 std::locale::id& __get_id (
void)
const {
return id; }
122 inline bool is_us_ascii_char(
char c)
125 return 0<c && c<0x7F;
127 inline bool is_us_ascii_string(
char const *msg)
130 if(!is_us_ascii_char(*msg++))
136 template<
typename CharType>
137 struct string_cast_traits {
138 static CharType
const *cast(CharType
const *msg,std::basic_string<CharType> &)
145 struct string_cast_traits<char> {
146 static char const *cast(
char const *msg,std::string &buffer)
148 if(is_us_ascii_string(msg))
150 buffer.reserve(strlen(msg));
152 while((c=*msg++)!=0) {
153 if(is_us_ascii_char(c))
156 return buffer.c_str();
170 template<
typename CharType>
305 c_context_(other.c_context_),
306 c_plural_(other.c_plural_),
308 context_(other.context_),
309 plural_(other.plural_)
331 std::swap(n_,other.n_);
332 std::swap(c_id_,other.c_id_);
333 std::swap(c_context_,other.c_context_);
334 std::swap(c_plural_,other.c_plural_);
337 context_.swap(other.context_);
338 plural_.swap(other.plural_);
364 return str(locale,0);
373 if(std::has_facet<facet_type>(locale))
374 id=std::use_facet<facet_type>(locale).
domain(domain_id);
375 return str(locale,
id);
385 if(std::has_facet<facet_type>(loc))
386 id=std::use_facet<facet_type>(loc).
domain(domain_id);
398 if(ptr == buffer.c_str())
410 void write(std::basic_ostream<char_type> &out)
const
412 std::locale
const &loc = out.getloc();
415 out <<
write(loc,
id,buffer);
425 return plural_.c_str();
433 return context_.c_str();
438 return c_id_ ? c_id_ : id_.c_str();
444 static const char_type empty_string[1] = {0};
447 char_type const *context = this->context();
448 char_type const *plural = this->plural();
454 if(std::has_facet<facet_type>(loc))
455 facet = &std::use_facet<facet_type>(loc);
459 translated = facet->get(domain_id,context,
id);
462 translated = facet->get(domain_id,context,
id,n_);
467 char_type const *msg = plural ? ( n_ == 1 ?
id : plural) :
id;
470 translated = facet->convert(msg,buffer);
473 translated = details::string_cast_traits<char_type>::cast(msg,buffer);
499 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
505 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
515 template<
typename CharType>
529 template<
typename CharType>
537 template<
typename CharType>
546 template<
typename CharType>
548 CharType
const *plural,
556 template<
typename CharType>
558 CharType
const *single,
559 CharType
const *plural,
568 template<
typename CharType>
577 template<
typename CharType>
579 std::basic_string<CharType>
const &msg)
586 template<
typename CharType>
588 std::basic_string<CharType>
const &single,
589 std::basic_string<CharType>
const &plural,
599 template<
typename CharType>
601 std::basic_string<CharType>
const &plural,
616 template<
typename CharType>
617 std::basic_string<CharType>
gettext(CharType
const *
id,
618 std::locale
const &loc=std::locale())
625 template<
typename CharType>
626 std::basic_string<CharType>
ngettext( CharType
const *s,
629 std::locale
const &loc=std::locale())
636 template<
typename CharType>
639 std::locale
const &loc=std::locale())
647 template<
typename CharType>
648 std::basic_string<CharType>
dngettext(
char const *domain,
652 std::locale
const &loc=std::locale())
659 template<
typename CharType>
660 std::basic_string<CharType>
pgettext( CharType
const *context,
662 std::locale
const &loc=std::locale())
669 template<
typename CharType>
670 std::basic_string<CharType>
npgettext( CharType
const *context,
674 std::locale
const &loc=std::locale())
681 template<
typename CharType>
682 std::basic_string<CharType>
dpgettext(
char const *domain,
683 CharType
const *context,
685 std::locale
const &loc=std::locale())
692 template<
typename CharType>
694 CharType
const *context,
698 std::locale
const &loc=std::locale())
708 struct BOOST_LOCALE_DECL base_message_format<char> :
public std::locale::facet
710 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
713 static std::locale::id id;
717 struct BOOST_LOCALE_DECL base_message_format<wchar_t> :
public std::locale::facet
719 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
722 static std::locale::id id;
725 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
728 struct BOOST_LOCALE_DECL base_message_format<char16_t> :
public std::locale::facet
730 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
733 static std::locale::id id;
738 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
741 struct BOOST_LOCALE_DECL base_message_format<char32_t> :
public std::locale::facet
743 base_message_format(
size_t refs = 0) : std::locale::facet(refs)
746 static std::locale::id id;
761 std::string domain_id;
763 template<
typename CharType>
764 std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out, set_domain
const &dom)
766 int id = std::use_facet<message_format<CharType> >(out.getloc()).
domain(dom.domain_id);
784 #ifdef BOOST_LOCALE_DOXYGEN
791 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:626
message_format(size_t refs=0)
Definition: message.hpp:63
basic_message(char_type const *context, char_type const *id)
Definition: message.hpp:220
void write(std::basic_ostream< char_type > &out) const
Definition: message.hpp:410
basic_message(string_type const &id)
Definition: message.hpp:246
CharType char_type
The character this message object is used with.
Definition: message.hpp:174
basic_message(string_type const &context, string_type const &id)
Definition: message.hpp:273
std::basic_string< char_type > string_type
The string type this object can be used with.
Definition: message.hpp:175
void swap(basic_message &other)
Definition: message.hpp:329
string_type str(std::string const &domain_id) const
Definition: message.hpp:381
basic_message(char_type const *id)
Definition: message.hpp:193
string_type str() const
Definition: message.hpp:353
basic_message< wchar_t > wmessage
Definition: message.hpp:498
This class represents a message that can be converted to a specific locale message.
Definition: message.hpp:171
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:670
basic_message< char32_t > u32message
Definition: message.hpp:509
basic_message const & operator=(basic_message const &other)
Definition: message.hpp:316
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:693
std::ios_base & number(std::ios_base &ios)
Definition: formatting.hpp:292
string_type str(std::locale const &locale, std::string const &domain_id) const
Definition: message.hpp:370
CharType char_type
Definition: message.hpp:54
basic_message< char > message
Definition: message.hpp:494
basic_message(string_type const &single, string_type const &plural, int number)
Definition: message.hpp:260
string_type str(std::locale const &locale) const
Definition: message.hpp:362
static ios_info & get(std::ios_base &ios)
basic_message()
Definition: message.hpp:181
std::basic_string< CharType > dgettext(char const *domain, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:637
basic_message< CharType > translate(CharType const *msg)
Translate a message, msg is not copied.
Definition: message.hpp:530
unspecified_type domain(std::string const &id)
Definition: message.hpp:789
std::basic_string< CharType > pgettext(CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:660
basic_message(string_type const &context, string_type const &single, string_type const &plural, int number)
Definition: message.hpp:288
std::basic_string< CharType > dpgettext(char const *domain, CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:682
virtual int domain(std::string const &domain) const =0
basic_message< char16_t > u16message
Definition: message.hpp:503
std::basic_string< CharType > gettext(CharType const *id, std::locale const &loc=std::locale())
Definition: message.hpp:617
basic_message(char_type const *single, char_type const *plural, int n)
Definition: message.hpp:207
basic_message(char_type const *context, char_type const *single, char_type const *plural, int n)
Definition: message.hpp:234
std::basic_string< CharType > string_type
Definition: message.hpp:58
message_format< char_type > facet_type
The type of the facet the messages are fetched with.
Definition: message.hpp:176
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:648
string_type str(std::locale const &loc, int id) const
Definition: message.hpp:394
virtual char_type const * convert(char_type const *msg, string_type &buffer) const =0
basic_message(basic_message const &other)
Definition: message.hpp:302