8 #ifndef BOOSTER_LOCALE_MESSAGE_H_INCLUDED 9 #define BOOSTER_LOCALE_MESSAGE_H_INCLUDED 11 #include <booster/config.h> 13 # pragma warning(push) 14 # pragma warning(disable : 4275 4251 4231 4660) 20 #include <booster/auto_ptr_inc.h> 21 #include <booster/locale/formatting.h> 36 template<
typename CharType>
37 struct base_message_format:
public std::locale::facet
46 template<
typename CharType>
64 base_message_format<CharType>(refs)
78 virtual char_type
const *
get(
int domain_id,char_type
const *context,char_type
const *id)
const = 0;
92 virtual char_type
const *
get(
int domain_id,char_type
const *context,char_type
const *single_id,
int n)
const = 0;
107 virtual char_type
const *convert(char_type
const *msg,string_type &buffer)
const = 0;
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>
207 explicit basic_message(char_type
const *single,char_type
const *plural,
int n) :
234 explicit basic_message(char_type
const *context,char_type
const *single,char_type
const *plural,
int n) :
288 explicit basic_message(string_type
const &context,string_type
const &single,string_type
const &plural,
int number) :
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_);
345 operator string_type ()
const 364 return str(locale,0);
370 string_type
str(std::locale
const &
locale,std::string
const &domain_id)
const 373 if(std::has_facet<facet_type>(locale))
374 id=std::use_facet<facet_type>(locale).
domain(domain_id);
375 return str(locale,
id);
381 string_type
str(std::string
const &domain_id)
const 385 if(std::has_facet<facet_type>(loc))
386 id=std::use_facet<facet_type>(loc).
domain(domain_id);
394 string_type
str(std::locale
const &loc,
int id)
const 397 char_type
const *ptr = write(loc,
id,buffer);
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);
419 char_type
const *plural()
const 425 return plural_.c_str();
427 char_type
const *context()
const 433 return context_.c_str();
436 char_type
const *id()
const 438 return c_id_ ? c_id_ : id_.c_str();
441 char_type
const *write(std::locale
const &loc,
int domain_id,string_type &buffer)
const 443 char_type
const *translated = 0;
444 static const char_type empty_string[1] = {0};
446 char_type
const *
id = this->id();
447 char_type
const *context = this->context();
448 char_type
const *plural = this->plural();
453 facet_type
const *facet = 0;
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);
482 char_type
const *c_id_;
483 char_type
const *c_context_;
484 char_type
const *c_plural_;
486 string_type context_;
499 #ifdef BOOSTER_HAS_CHAR16_T 505 #ifdef BOOSTER_HAS_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 BOOSTER_API 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 BOOSTER_API 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 BOOSTER_HAS_CHAR16_T 728 struct BOOSTER_API 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 BOOSTER_HAS_CHAR32_T 741 struct BOOSTER_API 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 BOOSTER_LOCALE_DOXYGEN 791 details::set_domain tmp = {
id };
void swap(basic_message &other)
Definition: message.h:329
basic_message(basic_message const &other)
Definition: message.h:302
std::basic_string< CharType > dgettext(char const *domain, CharType const *id, std::locale const &loc=std::locale())
Definition: message.h:637
message_format(size_t refs=0)
Definition: message.h:63
string_type str(std::string const &domain_id) const
Definition: message.h:381
basic_message()
Definition: message.h:181
CharType char_type
The character this message object is used with.
Definition: message.h:174
basic_message(string_type const &context, string_type const &single, string_type const &plural, int number)
Definition: message.h:288
details::set_domain domain(std::string const &id)
Definition: message.h:789
std::basic_string< CharType > dpgettext(char const *domain, CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.h:682
std::basic_string< CharType > pgettext(CharType const *context, CharType const *id, std::locale const &loc=std::locale())
Definition: message.h:660
message_format< char_type > facet_type
The type of the facet the messages are fetched with.
Definition: message.h:176
CharType char_type
Definition: message.h:54
basic_message< CharType > translate(CharType const *msg)
Translate a message, msg is not copied.
Definition: message.h:530
void write(std::basic_ostream< char_type > &out) const
Definition: message.h:410
static ios_info & get(std::ios_base &ios)
std::basic_string< CharType > gettext(CharType const *id, std::locale const &loc=std::locale())
Definition: message.h:617
string_type str(std::locale const &locale, std::string const &domain_id) const
Definition: message.h:370
std::basic_string< CharType > dngettext(char const *domain, CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.h:648
string_type str(std::locale const &loc, int id) const
Definition: message.h:394
std::basic_string< CharType > ngettext(CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.h:626
virtual char_type const * get(int domain_id, char_type const *context, char_type const *id) const =0
string_type str(std::locale const &locale) const
Definition: message.h:362
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
basic_message(char_type const *context, char_type const *single, char_type const *plural, int n)
Definition: message.h:234
virtual char_type const * convert(char_type const *msg, string_type &buffer) const =0
basic_message const & operator=(basic_message const &other)
Definition: message.h:316
basic_message(string_type const &single, string_type const &plural, int number)
Definition: message.h:260
basic_message(char_type const *id)
Definition: message.h:193
basic_message< wchar_t > wmessage
Definition: message.h:498
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.h:693
basic_message< char > message
Definition: message.h:494
std::ios_base & number(std::ios_base &ios)
Definition: formatting.h:292
basic_message(string_type const &id)
Definition: message.h:246
This class represents a message that can be converted to a specific locale message.
Definition: message.h:171
basic_message(char_type const *context, char_type const *id)
Definition: message.h:220
basic_message(string_type const &context, string_type const &id)
Definition: message.h:273
std::basic_string< char_type > string_type
The string type this object can be used with.
Definition: message.h:175
std::basic_string< CharType > string_type
Definition: message.h:58
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
std::basic_string< CharType > npgettext(CharType const *context, CharType const *s, CharType const *p, int n, std::locale const &loc=std::locale())
Definition: message.h:670
string_type str() const
Definition: message.h:353
basic_message(char_type const *single, char_type const *plural, int n)
Definition: message.h:207