| boundary.h | | boundary.h | |
| | | | |
| skipping to change at line 24 | | skipping to change at line 24 | |
| # pragma warning(push) | | # pragma warning(push) | |
| # pragma warning(disable : 4275 4251 4231 4660) | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #endif | | #endif | |
| #include <string> | | #include <string> | |
| #include <locale> | | #include <locale> | |
| #include <vector> | | #include <vector> | |
| #include <iterator> | | #include <iterator> | |
| #include <algorithm> | | #include <algorithm> | |
| #include <typeinfo> | | #include <typeinfo> | |
| #include <iterator> | | #include <iterator> | |
|
| #include <stdexcept> | | #include <booster/backtrace.h> | |
| | | | |
| namespace booster { | | namespace booster { | |
| | | | |
| namespace locale { | | namespace locale { | |
| | | | |
| /// | | /// | |
| /// \brief This namespae contains all operations required for bound
ary analysis of text | | /// \brief This namespae contains all operations required for bound
ary analysis of text | |
| /// | | /// | |
| namespace boundary { | | namespace boundary { | |
| /// | | /// | |
| | | | |
| skipping to change at line 111 | | skipping to change at line 111 | |
| { | | { | |
| switch(t) { | | switch(t) { | |
| case character: return character_mask; | | case character: return character_mask; | |
| case word: return word_mask; | | case word: return word_mask; | |
| case sentence: return sentence_mask; | | case sentence: return sentence_mask; | |
| case line: return line_mask; | | case line: return line_mask; | |
| default: return 0; | | default: return 0; | |
| } | | } | |
| } | | } | |
| | | | |
|
| /// \cond INTERNAL | | /// | |
| namespace impl { | | /// This structure is used for representing boundary point | |
| | | /// that follows the offset. | |
| struct break_info { | | /// | |
| | | struct break_info { | |
| | | | |
|
| break_info() : | | /// | |
| offset(0), | | /// Create empty break point at beginning | |
| mark(0) | | /// | |
| { | | break_info() : | |
| } | | offset(0), | |
| break_info(unsigned v) : | | mark(0) | |
| offset(v), | | { | |
| mark(0) | | } | |
| { | | /// | |
| } | | /// Create empty break point at offset v. | |
| | | /// it is useful for order comparison with other points. | |
| | | /// | |
| | | break_info(unsigned v) : | |
| | | offset(v), | |
| | | mark(0) | |
| | | { | |
| | | } | |
| | | | |
|
| uint32_t offset; | | /// | |
| uint32_t mark; | | /// Offset from the begging of the text where a break occur | |
| | | s. | |
| | | /// | |
| | | uint32_t offset; | |
| | | /// | |
| | | /// The identification of this break point according to | |
| | | /// various break types | |
| | | /// | |
| | | uint32_t mark; | |
| | | | |
|
| bool operator<(break_info const &other) const | | /// | |
| { | | /// Compare two break points' offset. Allows to search with | |
| return offset < other.offset; | | /// standard algorithms over the index. | |
| } | | /// | |
| }; | | bool operator<(break_info const &other) const | |
| | | { | |
| | | return offset < other.offset; | |
| | | } | |
| | | }; | |
| | | | |
|
| typedef std::vector<break_info> index_type; | | /// | |
| | | /// This type holds the alalisys of the text - all its break po | |
| | | ints | |
| | | /// with marks | |
| | | /// | |
| | | typedef std::vector<break_info> index_type; | |
| | | | |
|
| template<typename CharType> | | template<typename CharType> | |
| index_type map(boundary_type t,CharType const *begin,CharTy | | class boundary_indexing; | |
| pe const *end,std::locale const &loc=std::locale()); | | | |
| | | | |
|
| template<typename CharType> | | /// | |
| static index_type map( | | /// The facet that allows us to create an index for boundary an | |
| boundary_type t, | | alisys | |
| std::basic_string<CharType> const &str, | | /// of the text. | |
| std::locale const &loc=std::locale()) | | /// | |
| | | template<> | |
| | | class BOOSTER_API boundary_indexing<char> : public std::locale: | |
| | | :facet { | |
| | | public: | |
| | | /// | |
| | | /// Default constructor typical for facets | |
| | | /// | |
| | | boundary_indexing(size_t refs=0) : std::locale::facet(refs) | |
| { | | { | |
|
| return booster::locale::boundary::impl::map<CharType>(t
,str.data(),str.data()+str.size(),loc); | | | |
| } | | } | |
|
| | | /// | |
| | | /// Create index for boundary type \a t for text in range [ | |
| | | begin,end) | |
| | | /// | |
| | | virtual index_type map(boundary_type t,char const *begin,ch | |
| | | ar const *end) const = 0; | |
| | | /// Identification of this facet | |
| | | static std::locale::id id; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| | | #endif | |
| | | }; | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API index_type | | /// The facet that allows us to create an index for boundary an | |
| map(boundary_type t,char const *begin,char const *end,std:: | | alisys | |
| locale const &loc); | | /// of the text. | |
| | | /// | |
| | | template<> | |
| | | class BOOSTER_API boundary_indexing<wchar_t> : public std::loca | |
| | | le::facet { | |
| | | public: | |
| | | /// | |
| | | /// Default constructor typical for facets | |
| | | /// | |
| | | boundary_indexing(size_t refs=0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | /// | |
| | | /// Create index for boundary type \a t for text in range [ | |
| | | begin,end) | |
| | | /// | |
| | | virtual index_type map(boundary_type t,wchar_t const *begin | |
| | | ,wchar_t const *end) const = 0; | |
| | | | |
|
| #ifndef BOOSTER_NO_STD_WSTRING | | /// Identification of this facet | |
| template<> | | static std::locale::id id; | |
| BOOSTER_API index_type | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| map(boundary_type t,wchar_t const *begin,wchar_t const *end | | std::locale::id& __get_id (void) const { return id; } | |
| ,std::locale const &loc); | | | |
| #endif | | #endif | |
|
| | | }; | |
| | | | |
|
| #ifdef BOOSTER_HAS_CHAR16_T | | #ifdef BOOSTER_HAS_CHAR16_T | |
| template<> | | template<> | |
| BOOSTER_API index_type | | class BOOSTER_API boundary_indexing<char16_t> : public std::loc | |
| map(boundary_type t,char16_t const *begin,char16_t const *e | | ale::facet { | |
| nd,std::locale const &loc); | | public: | |
| | | boundary_indexing(size_t refs=0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | virtual index_type map(boundary_type t,char16_t const *begi | |
| | | n,char16_t const *end) const = 0; | |
| | | static std::locale::id id; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| #endif | | #endif | |
|
| | | }; | |
| | | #endif | |
| | | | |
|
| #ifdef BOOSTER_HAS_CHAR32_T | | #ifdef BOOSTER_HAS_CHAR32_T | |
| template<> | | template<> | |
| BOOSTER_API index_type | | class BOOSTER_API boundary_indexing<char32_t> : public std::loc | |
| map(boundary_type t,char32_t const *begin,char32_t const *e | | ale::facet { | |
| nd,std::locale const &loc); | | public: | |
| | | boundary_indexing(size_t refs=0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | virtual index_type map(boundary_type t,char32_t const *begi | |
| | | n,char32_t const *end) const = 0; | |
| | | static std::locale::id id; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| #endif | | #endif | |
|
| } // impl | | }; | |
| | | #endif | |
| | | | |
| | | /// \cond INTERNAL | |
| | | | |
| namespace details { | | namespace details { | |
| | | | |
| template<typename IteratorType,typename CategoryType = type
name std::iterator_traits<IteratorType>::iterator_category> | | template<typename IteratorType,typename CategoryType = type
name std::iterator_traits<IteratorType>::iterator_category> | |
| struct mapping_traits { | | struct mapping_traits { | |
| typedef typename std::iterator_traits<IteratorType>::va
lue_type char_type; | | typedef typename std::iterator_traits<IteratorType>::va
lue_type char_type; | |
|
| static impl::index_type map(boundary_type t,IteratorTyp
e b,IteratorType e,std::locale const &l) | | static index_type map(boundary_type t,IteratorType b,It
eratorType e,std::locale const &l) | |
| { | | { | |
| std::basic_string<char_type> str(b,e); | | std::basic_string<char_type> str(b,e); | |
|
| return impl::map(t,str,l); | | return std::use_facet<boundary_indexing<char_type>
>(l).map(t,str.c_str(),str.c_str()+str.size()); | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename IteratorType> | | template<typename IteratorType> | |
| struct mapping_traits<IteratorType,std::random_access_itera
tor_tag> { | | struct mapping_traits<IteratorType,std::random_access_itera
tor_tag> { | |
| typedef typename std::iterator_traits<IteratorType>::va
lue_type char_type; | | typedef typename std::iterator_traits<IteratorType>::va
lue_type char_type; | |
| | | | |
|
| static impl::index_type map(boundary_type t,IteratorTyp
e b,IteratorType e,std::locale const &l) | | static index_type map(boundary_type t,IteratorType b,It
eratorType e,std::locale const &l) | |
| { | | { | |
|
| impl::index_type result; | | index_type result; | |
| // | | // | |
| // Optimize for most common cases | | // Optimize for most common cases | |
| // | | // | |
| // C++0x requires that string is continious in memo
ry and all string implementations | | // C++0x requires that string is continious in memo
ry and all string implementations | |
| // do this because of c_str() support. | | // do this because of c_str() support. | |
| // | | // | |
| | | | |
| if( | | if( | |
| ( | | ( | |
| typeid(IteratorType) == typeid(typename std
::basic_string<char_type>::iterator) | | typeid(IteratorType) == typeid(typename std
::basic_string<char_type>::iterator) | |
| | | | |
| skipping to change at line 214 | | skipping to change at line 286 | |
| || typeid(IteratorType) == typeid(typename
std::vector<char_type>::const_iterator) | | || typeid(IteratorType) == typeid(typename
std::vector<char_type>::const_iterator) | |
| || typeid(IteratorType) == typeid(char_type
*) | | || typeid(IteratorType) == typeid(char_type
*) | |
| || typeid(IteratorType) == typeid(char_type
const *) | | || typeid(IteratorType) == typeid(char_type
const *) | |
| ) | | ) | |
| && | | && | |
| b!=e | | b!=e | |
| ) | | ) | |
| { | | { | |
| char_type const *begin = &*b; | | char_type const *begin = &*b; | |
| char_type const *end = begin + (e-b); | | char_type const *end = begin + (e-b); | |
|
| impl::index_type tmp=impl::map(t,begin,end,l); | | index_type tmp=std::use_facet<boundary_indexing
<char_type> >(l).map(t,begin,end); | |
| result.swap(tmp); | | result.swap(tmp); | |
| } | | } | |
| else{ | | else{ | |
| std::basic_string<char_type> str(b,e); | | std::basic_string<char_type> str(b,e); | |
|
| impl::index_type tmp=impl::map(t,str,l); | | index_type tmp = std::use_facet<boundary_indexi
ng<char_type> >(l).map(t,str.c_str(),str.c_str()+str.size()); | |
| result.swap(tmp); | | result.swap(tmp); | |
| } | | } | |
| return result; | | return result; | |
| } | | } | |
| }; | | }; | |
| | | | |
| } // details | | } // details | |
| | | | |
| /// \endcond | | /// \endcond | |
| | | | |
| | | | |
| skipping to change at line 399 | | skipping to change at line 471 | |
| /// Get \a end iterator used when object was created | | /// Get \a end iterator used when object was created | |
| /// | | /// | |
| RangeIterator end() const | | RangeIterator end() const | |
| { | | { | |
| return RangeIterator(*this,false,mask_); | | return RangeIterator(*this,false,mask_); | |
| } | | } | |
| | | | |
| private: | | private: | |
| void create_mapping(boundary_type type,base_iterator begin,
base_iterator end,std::locale const &loc,unsigned mask) | | void create_mapping(boundary_type type,base_iterator begin,
base_iterator end,std::locale const &loc,unsigned mask) | |
| { | | { | |
|
| impl::index_type idx=details::mapping_traits<base_itera
tor>::map(type,begin,end,loc); | | index_type idx=details::mapping_traits<base_iterator>::
map(type,begin,end,loc); | |
| index_.swap(idx); | | index_.swap(idx); | |
| begin_ = begin; | | begin_ = begin; | |
| end_ = end; | | end_ = end; | |
| mask_=mask; | | mask_=mask; | |
| } | | } | |
| template<typename I> | | template<typename I> | |
| friend class break_iterator; | | friend class break_iterator; | |
| template<typename I,typename V> | | template<typename I,typename V> | |
| friend class token_iterator; | | friend class token_iterator; | |
| template<typename I> | | template<typename I> | |
| friend class mapping; | | friend class mapping; | |
| | | | |
| base_iterator begin_,end_; | | base_iterator begin_,end_; | |
|
| impl::index_type index_; | | index_type index_; | |
| unsigned mask_; | | unsigned mask_; | |
| }; | | }; | |
| | | | |
| /// | | /// | |
| /// \brief token_iterator is an iterator that returns text chun
ks between boundary positions | | /// \brief token_iterator is an iterator that returns text chun
ks between boundary positions | |
| /// | | /// | |
| /// Token iterator may behave in two different ways: select spe
cific tokens in only tide way and | | /// Token iterator may behave in two different ways: select spe
cific tokens in only tide way and | |
| /// select them widely. For tide selection (default) it would n
ot return text chunks that | | /// select them widely. For tide selection (default) it would n
ot return text chunks that | |
| /// do not fit the selection mask. For example, for word iterat
ion with mask "word_letters" | | /// do not fit the selection mask. For example, for word iterat
ion with mask "word_letters" | |
| /// for text "I met him at 7" it would return "I", "met", "him"
, "at" ignoring white spaces | | /// for text "I met him at 7" it would return "I", "met", "him"
, "at" ignoring white spaces | |
| | | | |
| skipping to change at line 477 | | skipping to change at line 549 | |
| /// - "to| be or ", would point to "be", | | /// - "to| be or ", would point to "be", | |
| /// - "t|o be or ", would point to "to", | | /// - "t|o be or ", would point to "to", | |
| /// - "to be or| ", would point to end. | | /// - "to be or| ", would point to end. | |
| /// | | /// | |
| /// \a p - should be in range of the original mapping. | | /// \a p - should be in range of the original mapping. | |
| /// | | /// | |
| | | | |
| token_iterator const &operator=(IteratorType p) | | token_iterator const &operator=(IteratorType p) | |
| { | | { | |
| unsigned dist=std::distance(map_->begin_,p); | | unsigned dist=std::distance(map_->begin_,p); | |
|
| impl::index_type::const_iterator b=map_->index_.begin() | | index_type::const_iterator b=map_->index_.begin(),e=map | |
| ,e=map_->index_.end(); | | _->index_.end(); | |
| impl::index_type::const_iterator | | index_type::const_iterator | |
| bound=std::upper_bound(b,e,impl::break_info(dist)); | | bound=std::upper_bound(b,e,break_info(dist)); | |
| while(bound != e && (bound->mark & mask_)==0) | | while(bound != e && (bound->mark & mask_)==0) | |
| bound++; | | bound++; | |
| offset_ = bound - b; | | offset_ = bound - b; | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Create token iterator for mapping \a map with location
at begin or end according to value of flag \a begin, | | /// Create token iterator for mapping \a map with location
at begin or end according to value of flag \a begin, | |
| /// and a mask \a mask | | /// and a mask \a mask | |
| /// | | /// | |
| | | | |
| skipping to change at line 531 | | skipping to change at line 603 | |
| map_ = other.map_; | | map_ = other.map_; | |
| offset_ = other.offset_; | | offset_ = other.offset_; | |
| mask_=other.mask_; | | mask_=other.mask_; | |
| full_select_ = other.full_select_; | | full_select_ = other.full_select_; | |
| } | | } | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Return the token the iterator points it. Iterator must
not point to the | | /// Return the token the iterator points it. Iterator must
not point to the | |
|
| /// end of the range. Throws std::out_of_range exception | | /// end of the range. Throws booster::out_of_range exceptio
n | |
| /// | | /// | |
| /// Note, returned value is not lvalue, you can't use this
iterator to assign new values to text. | | /// Note, returned value is not lvalue, you can't use this
iterator to assign new values to text. | |
| /// | | /// | |
| ValueType operator*() const | | ValueType operator*() const | |
| { | | { | |
| if(offset_ < 1 || offset_ >= map_->index_.size()) | | if(offset_ < 1 || offset_ >= map_->index_.size()) | |
|
| throw std::out_of_range("Invalid token iterator loc
ation"); | | throw booster::out_of_range("Invalid token iterator
location"); | |
| unsigned pos=offset_-1; | | unsigned pos=offset_-1; | |
| if(full_select_) | | if(full_select_) | |
| while(!valid_offset(pos)) | | while(!valid_offset(pos)) | |
| pos--; | | pos--; | |
| base_iterator b=map_->begin_; | | base_iterator b=map_->begin_; | |
| unsigned b_off = map_->index_[pos].offset; | | unsigned b_off = map_->index_[pos].offset; | |
| std::advance(b,b_off); | | std::advance(b,b_off); | |
| base_iterator e=b; | | base_iterator e=b; | |
| unsigned e_off = map_->index_[offset_].offset; | | unsigned e_off = map_->index_[offset_].offset; | |
| std::advance(e,e_off-b_off); | | std::advance(e,e_off-b_off); | |
| | | | |
| skipping to change at line 795 | | skipping to change at line 867 | |
| /// \a p - should be in range of the original mapping. | | /// \a p - should be in range of the original mapping. | |
| /// | | /// | |
| break_iterator const &operator=(base_iterator p) | | break_iterator const &operator=(base_iterator p) | |
| { | | { | |
| at_least(p); | | at_least(p); | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Return the underlying iterator that break_iterator poin
ts it. Iterator must not point to the | | /// Return the underlying iterator that break_iterator poin
ts it. Iterator must not point to the | |
|
| /// end of the range, otherwise throws std::out_of_range ex
ception | | /// end of the range, otherwise throws booster::out_of_rang
e exception | |
| /// | | /// | |
| /// Note, returned value is not lvalue, you can't use this
iterator to change underlying iterators. | | /// Note, returned value is not lvalue, you can't use this
iterator to change underlying iterators. | |
| /// | | /// | |
| base_iterator operator*() const | | base_iterator operator*() const | |
| { | | { | |
| if(offset_ >=map_->index_.size()) | | if(offset_ >=map_->index_.size()) | |
|
| throw std::out_of_range("Invalid position of break
iterator"); | | throw booster::out_of_range("Invalid position of br
eak iterator"); | |
| base_iterator p = map_->begin_; | | base_iterator p = map_->begin_; | |
| std::advance(p, map_->index_[offset_].offset); | | std::advance(p, map_->index_[offset_].offset); | |
| return p; | | return p; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Increment operator | | /// Increment operator | |
| /// | | /// | |
| break_iterator &operator++() | | break_iterator &operator++() | |
| { | | { | |
| | | | |
| skipping to change at line 880 | | skipping to change at line 952 | |
| offset_ --; | | offset_ --; | |
| if(valid_offset(offset_)) | | if(valid_offset(offset_)) | |
| break; | | break; | |
| } | | } | |
| } | | } | |
| | | | |
| void at_least(IteratorType p) | | void at_least(IteratorType p) | |
| { | | { | |
| unsigned diff = std::distance(map_->begin_,p); | | unsigned diff = std::distance(map_->begin_,p); | |
| | | | |
|
| impl::index_type::const_iterator b=map_->index_.begin() | | index_type::const_iterator b=map_->index_.begin(); | |
| ; | | index_type::const_iterator e=map_->index_.end(); | |
| impl::index_type::const_iterator e=map_->index_.end(); | | index_type::const_iterator ptr = std::lower_bound(b,e,b | |
| impl::index_type::const_iterator ptr = std::lower_bound | | reak_info(diff)); | |
| (b,e,impl::break_info(diff)); | | | |
| | | | |
| if(ptr==map_->index_.end()) | | if(ptr==map_->index_.end()) | |
| offset_=map_->index_.size()-1; | | offset_=map_->index_.size()-1; | |
| else | | else | |
| offset_=ptr - map_->index_.begin(); | | offset_=ptr - map_->index_.begin(); | |
| | | | |
| while(!valid_offset(offset_)) | | while(!valid_offset(offset_)) | |
| offset_ ++; | | offset_ ++; | |
| } | | } | |
| | | | |
| | | | |
End of changes. 31 change blocks. |
| 73 lines changed or deleted | | 153 lines changed or added | |
|
| conversion.h | | conversion.h | |
| | | | |
| skipping to change at line 28 | | skipping to change at line 28 | |
| namespace booster { | | namespace booster { | |
| namespace locale { | | namespace locale { | |
| | | | |
| /// | | /// | |
| /// \defgroup convert Text Conversions | | /// \defgroup convert Text Conversions | |
| /// | | /// | |
| /// This module provides various function for string manipulation
like Unicode normalization, case conversion etc. | | /// This module provides various function for string manipulation
like Unicode normalization, case conversion etc. | |
| /// @{ | | /// @{ | |
| /// | | /// | |
| | | | |
|
| /// \cond INTERNAL | | /// | |
| namespace impl { | | /// This class provides base flags for text manipulation, it is use | |
| | | d as base for converter facet. | |
| | | /// | |
| | | class converter_base { | |
| | | public: | |
| | | /// | |
| | | /// The flag used for facet - the type of operation to perform | |
| | | /// | |
| typedef enum { | | typedef enum { | |
|
| normalization, | | normalization, ///< Apply Unicode normalization on the tex | |
| upper_case, | | t | |
| lower_case, | | upper_case, ///< Convert text to upper case | |
| case_folding, | | lower_case, ///< Convert text to lower case | |
| title_case | | case_folding, ///< Fold case in the text | |
| | | title_case ///< Convert text to title case | |
| } conversion_type; | | } conversion_type; | |
|
| | | }; | |
| | | | |
|
| BOOSTER_API std::string convert(conversion_type how,char const | | template<typename CharType> | |
| *begin,char const *end,int flags,std::locale const *loc=0); | | class converter; | |
| #ifndef BOOSTER_NO_STD_WSTRING | | | |
| BOOSTER_API std::wstring convert(conversion_type how,wchar_t co | | | |
| nst *begin,wchar_t const *end,int flags,std::locale const *loc=0); | | | |
| #endif | | | |
| #ifdef BOOSTER_HAS_CHAR16_T | | | |
| BOOSTER_API std::u16string convert(conversion_type how,char16_t | | | |
| const *begin,char16_t const *end,int flags,std::locale const *loc=0); | | | |
| #endif | | | |
| #ifdef BOOSTER_HAS_CHAR32_T | | | |
| BOOSTER_API std::u32string convert(conversion_type how,char32_t | | | |
| const *begin,char32_t const *end,int flags,std::locale const *loc=0); | | | |
| #endif | | | |
| | | | |
|
| } // impl | | /// | |
| /// \endcond | | /// The facet that implements text manipulation | |
| | | /// | |
| | | template<> | |
| | | class BOOSTER_API converter<char> : public converter_base, public s | |
| | | td::locale::facet { | |
| | | public: | |
| | | /// Locale identification | |
| | | static std::locale::id id; | |
| | | | |
| | | /// Standard constructor | |
| | | converter(size_t refs = 0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | /// | |
| | | /// Convert text in range [\a begin, \a end) according to conve | |
| | | rsion method \a how. Parameter | |
| | | /// \a flags is used for specification of normalization method | |
| | | like nfd, nfc etc. | |
| | | /// | |
| | | virtual std::string convert(conversion_type how,char const *beg | |
| | | in,char const *end,int flags = 0) const = 0; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| | | #endif | |
| | | }; | |
| | | | |
| | | /// | |
| | | /// The facet that implements text manipulation | |
| | | /// | |
| | | template<> | |
| | | class BOOSTER_API converter<wchar_t> : public converter_base, publi | |
| | | c std::locale::facet { | |
| | | public: | |
| | | /// Locale identification | |
| | | static std::locale::id id; | |
| | | /// Standard constructor | |
| | | converter(size_t refs = 0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | /// | |
| | | /// Convert text in range [\a begin, \a end) according to conve | |
| | | rsion method \a how. Parameter | |
| | | /// \a flags is used for specification of normalization method | |
| | | like nfd, nfc etc. | |
| | | /// | |
| | | virtual std::wstring convert(conversion_type how,wchar_t const | |
| | | *begin,wchar_t const *end,int flags = 0) const = 0; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| | | #endif | |
| | | }; | |
| | | | |
| | | #ifdef BOOSTER_HAS_CHAR16_T | |
| | | template<> | |
| | | class BOOSTER_API converter<char16_t> : public converter_base, publ | |
| | | ic std::locale::facet { | |
| | | public: | |
| | | static std::locale::id id; | |
| | | converter(size_t refs = 0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | virtual std::u16string convert(conversion_type how,char16_t con | |
| | | st *begin,char16_t const *end,int flags = 0) const = 0; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| | | #endif | |
| | | }; | |
| | | #endif | |
| | | | |
| | | #ifdef BOOSTER_HAS_CHAR32_T | |
| | | template<> | |
| | | class BOOSTER_API converter<char32_t> : public converter_base, publ | |
| | | ic std::locale::facet { | |
| | | public: | |
| | | static std::locale::id id; | |
| | | converter(size_t refs = 0) : std::locale::facet(refs) | |
| | | { | |
| | | } | |
| | | virtual std::u32string convert(conversion_type how,char32_t con | |
| | | st *begin,char32_t const *end,int flags = 0) const = 0; | |
| | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| | | std::locale::id& __get_id (void) const { return id; } | |
| | | #endif | |
| | | }; | |
| | | #endif | |
| | | | |
| /// | | /// | |
| /// Type of normalization | | /// Type of normalization | |
| /// | | /// | |
| | | | |
| typedef enum { | | typedef enum { | |
| norm_nfd, ///< Canonical decomposition | | norm_nfd, ///< Canonical decomposition | |
| norm_nfc, ///< Canonical decomposition followed by canonical
composition | | norm_nfc, ///< Canonical decomposition followed by canonical
composition | |
| norm_nfkd, ///< Compatibility decomposition | | norm_nfkd, ///< Compatibility decomposition | |
| norm_nfkc, ///< Compatibility decomposition followed by canoni
cal composition. | | norm_nfkc, ///< Compatibility decomposition followed by canoni
cal composition. | |
| | | | |
| skipping to change at line 72 | | skipping to change at line 143 | |
| } norm_type; | | } norm_type; | |
| | | | |
| /// | | /// | |
| /// Normalize Unicode string \a str according to normalization mode
\a n | | /// Normalize Unicode string \a str according to normalization mode
\a n | |
| /// | | /// | |
| /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | | /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | |
| /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | | /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | |
| /// of Unicode character set. | | /// of Unicode character set. | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
|
| std::basic_string<CharType> normalize(std::basic_string<CharType> c
onst &str,norm_type n=norm_default) | | std::basic_string<CharType> normalize(std::basic_string<CharType> c
onst &str,norm_type n=norm_default,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::normalization,str.data(),str.data()
+ str.size(),n); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::normalization,str.data(),str.data() + str.size(),n); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Normalize NUL terminated Unicode string \a str according to nor
malization mode \a n | | /// Normalize NUL terminated Unicode string \a str according to nor
malization mode \a n | |
| /// | | /// | |
| /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | | /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | |
| /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | | /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | |
| /// of Unicode character set. | | /// of Unicode character set. | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
|
| std::basic_string<CharType> normalize(CharType const *str,norm_type
n=norm_default) | | std::basic_string<CharType> normalize(CharType const *str,norm_type
n=norm_default,std::locale const &loc=std::locale()) | |
| { | | { | |
| CharType const *end=str; | | CharType const *end=str; | |
| while(*end) | | while(*end) | |
| end++; | | end++; | |
|
| return impl::convert(impl::normalization,str,end,n); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::normalization,str,end,n); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Normalize Unicode string in range [begin,end) according to norm
alization mode \a n | | /// Normalize Unicode string in range [begin,end) according to norm
alization mode \a n | |
| /// | | /// | |
| /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | | /// Note: This function receives only Unicode strings, i.e.: UTF-8,
UTF-16 or UTF-32. It does not takes | |
| /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | | /// in account the locale encoding, because Unicode decomposition a
nd composition are meaningless outside | |
| /// of Unicode character set. | | /// of Unicode character set. | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
|
| std::basic_string<CharType> normalize(CharType const *begin,CharTyp
e const *end,norm_type n=norm_default) | | std::basic_string<CharType> normalize(CharType const *begin,CharTyp
e const *end,norm_type n=norm_default,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::normalization,begin,end,n); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::normalization,begin,end,n); | |
| } | | } | |
| | | | |
| /////////////////////////////////////////////////// | | /////////////////////////////////////////////////// | |
| | | | |
| /// | | /// | |
| /// Convert a string \a str to upper case according to locale \a lo
c | | /// Convert a string \a str to upper case according to locale \a lo
c | |
| /// | | /// | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_upper(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_upper(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::upper_case,str.data(),str.data()+str
.size(),0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::upper_case,str.data(),str.data()+str.size()); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a NUL terminated string \a str to upper case according
to locale \a loc | | /// Convert a NUL terminated string \a str to upper case according
to locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_upper(CharType const *str,std::local
e const &loc=std::locale()) | | std::basic_string<CharType> to_upper(CharType const *str,std::local
e const &loc=std::locale()) | |
| { | | { | |
| CharType const *end=str; | | CharType const *end=str; | |
| while(*end) | | while(*end) | |
| end++; | | end++; | |
|
| return impl::convert(impl::upper_case,str,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::upper_case,str,end); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a string in range [begin,end) to upper case according t
o locale \a loc | | /// Convert a string in range [begin,end) to upper case according t
o locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_upper(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_upper(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::upper_case,begin,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::upper_case,begin,end); | |
| } | | } | |
| | | | |
| /////////////////////////////////////////////////// | | /////////////////////////////////////////////////// | |
| | | | |
| /// | | /// | |
| /// Convert a string \a str to lower case according to locale \a lo
c | | /// Convert a string \a str to lower case according to locale \a lo
c | |
| /// | | /// | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_lower(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_lower(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::lower_case,str.data(),str.data()+str
.size(),0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::lower_case,str.data(),str.data()+str.size()); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a NUL terminated string \a str to lower case according
to locale \a loc | | /// Convert a NUL terminated string \a str to lower case according
to locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_lower(CharType const *str,std::local
e const &loc=std::locale()) | | std::basic_string<CharType> to_lower(CharType const *str,std::local
e const &loc=std::locale()) | |
| { | | { | |
| CharType const *end=str; | | CharType const *end=str; | |
| while(*end) | | while(*end) | |
| end++; | | end++; | |
|
| return impl::convert(impl::lower_case,str,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::lower_case,str,end); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a string in range [begin,end) to lower case according t
o locale \a loc | | /// Convert a string in range [begin,end) to lower case according t
o locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_lower(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_lower(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::lower_case,begin,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::lower_case,begin,end); | |
| } | | } | |
| /////////////////////////////////////////////////// | | /////////////////////////////////////////////////// | |
| | | | |
| /// | | /// | |
| /// Convert a string \a str to title case according to locale \a lo
c | | /// Convert a string \a str to title case according to locale \a lo
c | |
| /// | | /// | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_title(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_title(std::basic_string<CharType> co
nst &str,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::title_case,str.data(),str.data()+str
.size(),0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::title_case,str.data(),str.data()+str.size()); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a NUL terminated string \a str to title case according
to locale \a loc | | /// Convert a NUL terminated string \a str to title case according
to locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_title(CharType const *str,std::local
e const &loc=std::locale()) | | std::basic_string<CharType> to_title(CharType const *str,std::local
e const &loc=std::locale()) | |
| { | | { | |
| CharType const *end=str; | | CharType const *end=str; | |
| while(*end) | | while(*end) | |
| end++; | | end++; | |
|
| return impl::convert(impl::title_case,str,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::title_case,str,end); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Convert a string in range [begin,end) to title case according t
o locale \a loc | | /// Convert a string in range [begin,end) to title case according t
o locale \a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> to_title(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | | std::basic_string<CharType> to_title(CharType const *begin,CharType
const *end,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::title_case,begin,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::title_case,begin,end); | |
| } | | } | |
| | | | |
| /////////////////////////////////////////////////// | | /////////////////////////////////////////////////// | |
| | | | |
| /// | | /// | |
| /// Fold case of a string \a str according to locale \a loc | | /// Fold case of a string \a str according to locale \a loc | |
| /// | | /// | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> fold_case(std::basic_string<CharType> c
onst &str,std::locale const &loc=std::locale()) | | std::basic_string<CharType> fold_case(std::basic_string<CharType> c
onst &str,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::case_folding,str.data(),str.data()+s
tr.size(),0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::case_folding,str.data(),str.data()+str.size()); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Fold case of a NUL terminated string \a str according to locale
\a loc | | /// Fold case of a NUL terminated string \a str according to locale
\a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> fold_case(CharType const *str,std::loca
le const &loc=std::locale()) | | std::basic_string<CharType> fold_case(CharType const *str,std::loca
le const &loc=std::locale()) | |
| { | | { | |
| CharType const *end=str; | | CharType const *end=str; | |
| while(*end) | | while(*end) | |
| end++; | | end++; | |
|
| return impl::convert(impl::case_folding,str,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::case_folding,str,end); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Fold case of a string in range [begin,end) according to locale
\a loc | | /// Fold case of a string in range [begin,end) according to locale
\a loc | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_string<CharType> fold_case(CharType const *begin,CharTyp
e const *end,std::locale const &loc=std::locale()) | | std::basic_string<CharType> fold_case(CharType const *begin,CharTyp
e const *end,std::locale const &loc=std::locale()) | |
| { | | { | |
|
| return impl::convert(impl::case_folding,begin,end,0,&loc); | | return std::use_facet<converter<CharType> >(loc).convert(conver
ter_base::case_folding,begin,end); | |
| } | | } | |
| | | | |
| /// | | /// | |
| ///@} | | ///@} | |
| /// | | /// | |
| } // locale | | } // locale | |
| | | | |
| } // boost | | } // boost | |
| | | | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| | | | |
End of changes. 23 change blocks. |
| 41 lines changed or deleted | | 122 lines changed or added | |
|
| date_time.h | | date_time.h | |
| | | | |
| skipping to change at line 17 | | skipping to change at line 17 | |
| // | | // | |
| #ifndef BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | | #ifndef BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | |
| #define BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | | #define BOOSTER_LOCALE_DATE_TIME_H_INCLUDED | |
| | | | |
| #include <booster/config.h> | | #include <booster/config.h> | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| # pragma warning(push) | | # pragma warning(push) | |
| # pragma warning(disable : 4275 4251 4231 4660) | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #endif | | #endif | |
| | | | |
|
| #include <booster/locale/time_zone.h> | | #include <booster/locale/hold_ptr.h> | |
| | | #include <booster/locale/date_time_facet.h> | |
| #include <locale> | | #include <locale> | |
| #include <vector> | | #include <vector> | |
|
| #include <stdexcept> | | #include <booster/backtrace.h> | |
| | | | |
| namespace booster { | | namespace booster { | |
| namespace locale { | | namespace locale { | |
| /// | | /// | |
| /// \defgroup date_time Date, Time, Timezone and Calendar manipulat
ions | | /// \defgroup date_time Date, Time, Timezone and Calendar manipulat
ions | |
| /// | | /// | |
| /// This module provides various calendar, timezone and date time s
ervices | | /// This module provides various calendar, timezone and date time s
ervices | |
| /// | | /// | |
| /// @{ | | /// @{ | |
| | | | |
| /// | | /// | |
| /// \brief This error is thrown in case of invalid state that occur
red | | /// \brief This error is thrown in case of invalid state that occur
red | |
| /// | | /// | |
|
| class date_time_error : public std::runtime_error { | | class date_time_error : public booster::runtime_error { | |
| public: | | public: | |
| /// | | /// | |
| /// Constructor of date_time_error class | | /// Constructor of date_time_error class | |
| /// | | /// | |
|
| date_time_error(std::string const &e) : std::runtime_error(e) {
} | | date_time_error(std::string const &e) : booster::runtime_error(
e) {} | |
| }; | | }; | |
| | | | |
| /// | | /// | |
|
| /// \brief Namespace that contains a enum that defines various peri | | | |
| ods like years, days | | | |
| /// | | | |
| namespace period { | | | |
| /// | | | |
| /// | | | |
| /// This enum provides the list of various time periods that ca | | | |
| n be used for manipulation over date and time | | | |
| /// Operators like +, - * defined for these period allowing to | | | |
| perform easy calculations over them | | | |
| /// | | | |
| typedef enum { | | | |
| invalid, ///< Special invalid value, sho | | | |
| uld not be used directs | | | |
| era, ///< Era i.e. AC, BC in Gregori | | | |
| an and Julian calendar, range [0,1] | | | |
| year, ///< Year, it is calendar speci | | | |
| fic | | | |
| extended_year, ///< Extended year for Gregoria | | | |
| n/Julian calendars, where 1 BC == 0, 2 BC == -1. | | | |
| month, ///< The month of year, calenda | | | |
| r specific, in Gregorian [0..11] | | | |
| day, ///< The day of month, calendar | | | |
| specific, in Gregorian [1..31] | | | |
| day_of_year, ///< The number of day in year, | | | |
| starting from 1 | | | |
| day_of_week, ///< Day of week, starting from | | | |
| Sunday, [1..7] | | | |
| day_of_week_in_month, ///< Original number of the day | | | |
| of the week in month. | | | |
| day_of_week_local, ///< Local day of week, for exa | | | |
| mple in France Monday is 1, in US Sunday is 1, [1..7] | | | |
| hour, ///< 24 clock hour [0..23] | | | |
| hour_12, ///< 12 clock hour [0..11] | | | |
| am_pm, ///< am or pm marker, [0..1] | | | |
| minute, ///< minute [0..59] | | | |
| second, ///< second [0..59] | | | |
| week_of_year, ///< The week number in the yea | | | |
| r | | | |
| week_of_month, ///< The week number withing cu | | | |
| rrent month | | | |
| } period_type; | | | |
| } // period | | | |
| | | | |
| /// | | | |
| /// \brief This structure provides a pair period_type and amount. | | /// \brief This structure provides a pair period_type and amount. | |
| /// | | /// | |
| /// Usually obtained as product of period_type and integer. | | /// Usually obtained as product of period_type and integer. | |
| /// For example day*3 == date_time_period(day,3) | | /// For example day*3 == date_time_period(day,3) | |
| /// | | /// | |
| struct date_time_period | | struct date_time_period | |
| { | | { | |
| period::period_type type; ///< The type of period, i.e. era,
year, day etc. | | period::period_type type; ///< The type of period, i.e. era,
year, day etc. | |
| int value; ///< The value the actual number of
\a periods | | int value; ///< The value the actual number of
\a periods | |
| /// | | /// | |
| | | | |
| skipping to change at line 517 | | skipping to change at line 488 | |
| if(basic_[3].type == period::invalid) | | if(basic_[3].type == period::invalid) | |
| return 3; | | return 3; | |
| return 4+periods_.size(); | | return 4+periods_.size(); | |
| } | | } | |
| /// | | /// | |
| /// Get item at position \a n the set, n should be in range [0,
size) | | /// Get item at position \a n the set, n should be in range [0,
size) | |
| /// | | /// | |
| date_time_period const &operator[](unsigned n) const | | date_time_period const &operator[](unsigned n) const | |
| { | | { | |
| if(n >= size()) | | if(n >= size()) | |
|
| throw std::out_of_range("Invalid index to date_time_per
iod"); | | throw booster::out_of_range("Invalid index to date_time
_period"); | |
| if(n < 4) | | if(n < 4) | |
| return basic_[n]; | | return basic_[n]; | |
| else | | else | |
| return periods_[n-4]; | | return periods_[n-4]; | |
| } | | } | |
| private: | | private: | |
| date_time_period basic_[4]; | | date_time_period basic_[4]; | |
| std::vector<date_time_period> periods_; | | std::vector<date_time_period> periods_; | |
| }; | | }; | |
| | | | |
| | | | |
| skipping to change at line 567 | | skipping to change at line 538 | |
| class BOOSTER_API calendar { | | class BOOSTER_API calendar { | |
| public: | | public: | |
| | | | |
| /// | | /// | |
| /// Create calendar taking locale and timezone information from
ios_base instance. | | /// Create calendar taking locale and timezone information from
ios_base instance. | |
| /// | | /// | |
| calendar(std::ios_base &ios); | | calendar(std::ios_base &ios); | |
| /// | | /// | |
| /// Create calendar with locale \a l and time_zone \a zone | | /// Create calendar with locale \a l and time_zone \a zone | |
| /// | | /// | |
|
| calendar(std::locale const &l,time_zone const &zone); | | calendar(std::locale const &l,std::string const &zone); | |
| /// | | /// | |
| /// Create calendar with locale \a l and default timezone | | /// Create calendar with locale \a l and default timezone | |
| /// | | /// | |
| calendar(std::locale const &l); | | calendar(std::locale const &l); | |
| /// | | /// | |
| /// Create calendar with default locale and timezone \a zone | | /// Create calendar with default locale and timezone \a zone | |
| /// | | /// | |
|
| calendar(time_zone const &zone); | | calendar(std::string const &zone); | |
| /// | | /// | |
| /// Create calendar with default locale and timezone | | /// Create calendar with default locale and timezone | |
| /// | | /// | |
| calendar(); | | calendar(); | |
| ~calendar(); | | ~calendar(); | |
| | | | |
| /// | | /// | |
| /// copy calendar | | /// copy calendar | |
| /// | | /// | |
| calendar(calendar const &other); | | calendar(calendar const &other); | |
| | | | |
| skipping to change at line 619 | | skipping to change at line 590 | |
| /// Get first day of week for specific calendar, for example fo
r US it is 1 - Sunday for France it is 2 - Monday | | /// Get first day of week for specific calendar, for example fo
r US it is 1 - Sunday for France it is 2 - Monday | |
| int first_day_of_week() const; | | int first_day_of_week() const; | |
| | | | |
| /// | | /// | |
| /// get calendar's locale | | /// get calendar's locale | |
| /// | | /// | |
| std::locale get_locale() const; | | std::locale get_locale() const; | |
| /// | | /// | |
| /// get calendar's time zone | | /// get calendar's time zone | |
| /// | | /// | |
|
| time_zone get_time_zone() const; | | std::string get_time_zone() const; | |
| | | | |
| /// | | /// | |
| /// Check if the calendar is Gregorian | | /// Check if the calendar is Gregorian | |
| /// | | /// | |
| bool is_gregorian() const; | | bool is_gregorian() const; | |
| | | | |
| /// | | /// | |
| /// Compare calendars for equivalence: i.e. calendar types, tim
e zones etc. | | /// Compare calendars for equivalence: i.e. calendar types, tim
e zones etc. | |
| /// | | /// | |
| bool operator==(calendar const &other) const; | | bool operator==(calendar const &other) const; | |
| /// | | /// | |
| /// Opposite of == | | /// Opposite of == | |
| /// | | /// | |
| bool operator!=(calendar const &other) const; | | bool operator!=(calendar const &other) const; | |
| | | | |
| private: | | private: | |
| friend class date_time; | | friend class date_time; | |
| std::locale locale_; | | std::locale locale_; | |
|
| booster::locale::time_zone tz_; | | std::string tz_; | |
| void *impl_; | | hold_ptr<abstract_calendar> impl_; | |
| }; | | }; | |
| | | | |
| /// | | /// | |
| /// \brief this class represents a date time and allows to perform
various operation according to the | | /// \brief this class represents a date time and allows to perform
various operation according to the | |
| /// locale settings. | | /// locale settings. | |
| /// | | /// | |
| /// This class allows to manipulate various aspects of dates and ti
mes easily using arithmetic operations with | | /// This class allows to manipulate various aspects of dates and ti
mes easily using arithmetic operations with | |
| /// periods. | | /// periods. | |
| /// | | /// | |
| /// General arithmetic functions: | | /// General arithmetic functions: | |
| | | | |
| skipping to change at line 908 | | skipping to change at line 879 | |
| /// swaps two dates - efficient, does not throw | | /// swaps two dates - efficient, does not throw | |
| /// | | /// | |
| void swap(date_time &other); | | void swap(date_time &other); | |
| | | | |
| /// | | /// | |
| /// calculate the distance from this date_time to \a other in t
erms of perios \a f | | /// calculate the distance from this date_time to \a other in t
erms of perios \a f | |
| /// | | /// | |
| int difference(date_time const &other,period::period_type f) co
nst; | | int difference(date_time const &other,period::period_type f) co
nst; | |
| | | | |
| /// | | /// | |
|
| /// calculate the distance from this date_time to \a other in t | | | |
| erms of perios \a f | | | |
| /// | | | |
| int difference(date_time const &other,period::period_type f); | | | |
| | | | |
| /// | | | |
| /// Get minimal possible value for current time point for a per
iod \a f. | | /// Get minimal possible value for current time point for a per
iod \a f. | |
| /// | | /// | |
| int minimum(period::period_type f) const; | | int minimum(period::period_type f) const; | |
| /// | | /// | |
| /// Get minimal possible value for current time point for a per
iod \a f. For example | | /// Get minimal possible value for current time point for a per
iod \a f. For example | |
| /// in February maximum(day) may be 28 or 29, in January maximu
m(day)==31 | | /// in February maximum(day) may be 28 or 29, in January maximu
m(day)==31 | |
| /// | | /// | |
| int maximum(period::period_type f) const; | | int maximum(period::period_type f) const; | |
| | | | |
| private: | | private: | |
|
| void *impl_; | | hold_ptr<abstract_calendar> impl_; | |
| }; | | }; | |
| | | | |
| /// | | /// | |
| /// Writes date_time \a t to output stream \a out. | | /// Writes date_time \a t to output stream \a out. | |
| /// | | /// | |
| /// This function uses locale, calendar and time zone of the target
stream \a in. | | /// This function uses locale, calendar and time zone of the target
stream \a in. | |
| /// | | /// | |
| /// For example: | | /// For example: | |
| /// \code | | /// \code | |
| /// date_time now(time(0),hebrew_calendar) | | /// date_time now(time(0),hebrew_calendar) | |
| | | | |
| skipping to change at line 1011 | | skipping to change at line 977 | |
| | | | |
| /// | | /// | |
| /// Calculates the difference between two dates, the left operand i
s a later point on time line. | | /// Calculates the difference between two dates, the left operand i
s a later point on time line. | |
| /// Returns date_time_duration object. | | /// Returns date_time_duration object. | |
| /// | | /// | |
| inline date_time_duration operator-(date_time const &later,date_tim
e const &earlier) | | inline date_time_duration operator-(date_time const &later,date_tim
e const &earlier) | |
| { | | { | |
| return date_time_duration(earlier,later); | | return date_time_duration(earlier,later); | |
| } | | } | |
| | | | |
|
| | | /// | |
| | | /// \brief namespace that holds function for operating global time | |
| | | zone identifier | |
| | | /// | |
| | | namespace time_zone { | |
| | | /// | |
| | | /// Get global time zone identifier. If empty, system time zone | |
| | | is used | |
| | | /// | |
| | | BOOSTER_API std::string global(); | |
| | | /// | |
| | | /// Set global time zone identifier returing pervious one. If e | |
| | | mpty, system time zone is used | |
| | | /// | |
| | | BOOSTER_API std::string global(std::string const &new_tz); | |
| | | } | |
| | | | |
| /// @} | | /// @} | |
| | | | |
| } // locale | | } // locale | |
| } // boost | | } // boost | |
| | | | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| #pragma warning(pop) | | #pragma warning(pop) | |
| #endif | | #endif | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 13 change blocks. |
| 62 lines changed or deleted | | 29 lines changed or added | |
|
| encoding.h | | encoding.h | |
|
| /////////////////////////////////////////////////////////////////////////// | | | |
| //// | | | |
| // | | | |
| // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | | | |
| // | | // | |
|
| // This program is free software: you can redistribute it and/or modify | | // Copyright (c) 2009-2010 Artyom Beilis (Tonkikh) | |
| // it under the terms of the GNU Lesser General Public License as publishe | | | |
| d by | | | |
| // the Free Software Foundation, either version 3 of the License, or | | | |
| // (at your option) any later version. | | | |
| // | | | |
| // This program is distributed in the hope that it will be useful, | | | |
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | | | |
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | | |
| // GNU Lesser General Public License for more details. | | | |
| // | | // | |
|
| // You should have received a copy of the GNU Lesser General Public Licens | | // Distributed under the Boost Software License, Version 1.0. (See | |
| e | | // accompanying file LICENSE_1_0.txt or copy at | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | | // http://www.boost.org/LICENSE_1_0.txt) | |
| // | | // | |
|
| /////////////////////////////////////////////////////////////////////////// | | #ifndef BOOSTER_LOCALE_ENCODING_H_INCLUDED | |
| //// | | #define BOOSTER_LOCALE_ENCODING_H_INCLUDED | |
| #ifndef CPPCMS_ENCODING_H | | | |
| #define CPPCMS_ENCODING_H | | | |
| | | | |
|
| #include <string> | | #include <booster/config.h> | |
| #include <map> | | #ifdef BOOSTER_MSVC | |
| #include <locale> | | # pragma warning(push) | |
| #include <cppcms/defs.h> | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #include <cppcms/config.h> | | #endif | |
| | | #include <booster/locale/info.h> | |
| | | #include <booster/cstdint.h> | |
| | | #include <booster/backtrace.h> | |
| | | | |
|
| namespace cppcms { | | namespace booster { | |
| /// | | namespace locale { | |
| /// \brief this Namespace holds various function for dealing with en | | | |
| coding | | | |
| /// | | | |
| /// | | | |
| namespace encoding { | | | |
| | | | |
|
| /// Note: all these function assume that control characters | | /// | |
| that invalid in HTML are illegal. | | /// \brief Namespace that contains all functions related to charact | |
| /// For example. NUL is legal UTF-8 code but it is illegal i | | er set conversion | |
| n terms of HTML validity thus, | | /// | |
| /// valid_utf8 would return false. | | namespace conv { | |
| | | /// | |
| | | /// \defgroup codepage Character conversion functions | |
| | | /// | |
| | | /// @{ | |
| | | | |
|
| /// | | /// | |
| /// Check if string in range [begin,end) is valid in the loc | | /// \brief The excepton that is thrown in case of conversion er | |
| ale \a loc and does not include | | ror | |
| /// HTML illegal characters. Number of codepoints is stored | | /// | |
| in \a count | | class conversion_error : public booster::runtime_error { | |
| /// | | public: | |
| bool CPPCMS_API valid(std::locale const &loc,char const *beg | | conversion_error() : booster::runtime_error("Conversion fai | |
| in,char const *end,size_t &count); | | led") {} | |
| /// | | }; | |
| /// Check if string in range [begin,end) is valid UTF-8 and | | | |
| does not include | | | |
| /// HTML illegal characters. Number of codepoints is stored | | | |
| in \a count | | | |
| /// | | | |
| bool CPPCMS_API valid_utf8(char const *begin,char const *end | | | |
| ,size_t &count); | | | |
| /// | | | |
| /// Check if string in range [begin,end) is valid encoding \ | | | |
| a encoding and does not include | | | |
| /// HTML illegal characters. Number of codepoints is stored | | | |
| in \a count | | | |
| /// | | | |
| bool CPPCMS_API valid(char const *encoding,char const *begin | | | |
| ,char const *end,size_t &count); | | | |
| /// | | | |
| /// Check if string in range [begin,end) is valid encoding \ | | | |
| a encoding and does not include | | | |
| /// HTML illegal characters. Number of codepoints is stored | | | |
| in \a count | | | |
| /// | | | |
| bool CPPCMS_API valid(std::string const &encoding,char const | | | |
| *begin,char const *end,size_t &count); | | | |
| | | | |
|
| #if defined(CPPCMS_HAVE_ICU) || defined(CPPCMS_HAVE_ICONV) | | /// | |
| | | /// \brief This exception is thrown in case of use of unsupport | |
| | | ed | |
| | | /// or invalid character set | |
| | | /// | |
| | | class invalid_charset_error : public booster::runtime_error { | |
| | | public: | |
| | | | |
|
| /// | | /// Create an error for charset \a charset | |
| /// Convert string in range [begin,end) from local 8 bit enc | | invalid_charset_error(std::string charset) : | |
| oding according to locale \a loc to UTF-8 | | booster::runtime_error("Invalid or unsupported charset: | |
| /// If illegal characters found, the conversion is aborted a | | " + charset) | |
| nd only sucessefully converted part is returned. | | { | |
| /// | | } | |
| std::string CPPCMS_API to_utf8(std::locale const &loc,char c | | }; | |
| onst *begin,char const *end); | | | |
| /// | | | |
| /// Convert string in range [begin,end) from local 8 bit enc | | | |
| oding \a encoding to UTF-8 | | | |
| /// If illegal characters found, the conversion is aborted a | | | |
| nd only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API to_utf8(char const *encoding,char con | | | |
| st *begin,char const *end); | | | |
| /// | | | |
| /// Convert string \a str from local 8 bit encoding accordin | | | |
| g to locale \a loc to UTF-8 | | | |
| /// If illegal characters found, the conversion is aborted a | | | |
| nd only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API to_utf8(std::locale const &loc,std::s | | | |
| tring const &str); | | | |
| /// | | | |
| /// Convert string \a str from local 8 bit encoding accordin | | | |
| g to encoding \a encoding | | | |
| /// If illegal characters found, the conversion is aborted a | | | |
| nd only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API to_utf8(char const *encoding,std::str | | | |
| ing const &str); | | | |
| | | | |
|
| /// | | /// | |
| /// Convert UTF-8 string in range [begin,end) to local 8 bit | | /// enum that defines conversion policy | |
| encoding according to locale \a loc. | | /// | |
| /// If non-convertable characters found, the conversion is a | | typedef enum { | |
| borted and only sucessefully converted part is returned. | | skip = 0, ///< Skip illegal/unconvertable cha | |
| /// | | racters | |
| std::string CPPCMS_API from_utf8(std::locale const &loc,char | | stop = 1, ///< Stop conversion and throw conv | |
| const *begin,char const *end); | | ersion_error | |
| /// | | default_method = skip ///< Default method - skip | |
| /// Convert UTF-8 string in range [begin,end) to local 8 bit | | } method_type; | |
| encoding \a encoding. | | | |
| /// If non-convertable characters found, the conversion is a | | | |
| borted and only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API from_utf8(char const *encoding,char c | | | |
| onst *begin,char const *end); | | | |
| /// | | | |
| /// Convert UTF-8 string \a str to local 8 bit encoding acco | | | |
| rding to locale \a loc. | | | |
| /// If non-convertable characters found, the conversion is a | | | |
| borted and only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API from_utf8(std::locale const &loc,std: | | | |
| :string const &str); | | | |
| /// | | | |
| /// Convert UTF-8 string \a str to local 8 bit encoding \a e | | | |
| ncoding. | | | |
| /// If non-convertable characters found, the conversion is a | | | |
| borted and only sucessefully converted part is returned. | | | |
| /// | | | |
| std::string CPPCMS_API from_utf8(char const *encoding,std::s | | | |
| tring const &str); | | | |
| | | | |
|
| #endif | | /// | |
| | | /// convert string to UTF string from text in range [begin,end) | |
| | | encoded with \a charset according to policy \a how | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(char const *begin,char const | |
| | | *end,std::string const &charset,method_type how=default_method); | |
| | | | |
|
| } // encoding | | /// | |
| } // cppcms | | /// convert UTF text in range [begin,end) to a text encoded wit | |
| | | h \a charset according to policy \a how | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(CharType const *begin,CharType const *end, | |
| | | std::string const &charset,method_type how=default_method); | |
| | | | |
| | | /// | |
| | | /// convert string to UTF string from text in range [begin,end) | |
| | | encoded according to locale \a loc according to policy \a how | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(char const *begin,char const | |
| | | *end,std::locale const &loc,method_type how=default_method) | |
| | | { | |
| | | return to_utf<CharType>(begin,end,std::use_facet<info>(loc) | |
| | | .encoding(),how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// convert UTF text in range [begin,end) to a text encoded acc | |
| | | ording to locale \a loc according to policy \a how | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(CharType const *begin,CharType const *end, | |
| | | std::locale const &loc,method_type how=default_method) | |
| | | { | |
| | | return from_utf(begin,end,std::use_facet<info>(loc).encodin | |
| | | g(),how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// convert a string \a text encoded with \a charset to UTF str | |
| | | ing | |
| | | /// | |
| | | | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(std::string const &text,std: | |
| | | :string const &charset,method_type how=default_method) | |
| | | { | |
| | | return to_utf<CharType>(text.c_str(),text.c_str()+text.size | |
| | | (),charset,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text from \a charset to UTF string | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(std::basic_string<CharType> const &text,st | |
| | | d::string const &charset,method_type how=default_method) | |
| | | { | |
| | | return from_utf(text.c_str(),text.c_str()+text.size(),chars | |
| | | et,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text from \a charset to UTF string | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(char const *text,std::string | |
| | | const &charset,method_type how=default_method) | |
| | | { | |
| | | char const *text_end = text; | |
| | | while(*text_end) | |
| | | text_end++; | |
| | | return to_utf<CharType>(text,text_end,charset,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text from UTF to \a charset | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(CharType const *text,std::string const &ch | |
| | | arset,method_type how=default_method) | |
| | | { | |
| | | CharType const *text_end = text; | |
| | | while(*text_end) | |
| | | text_end++; | |
| | | return from_utf(text,text_end,charset,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text in locale encoding given by \a loc to UTF | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(std::string const &text,std: | |
| | | :locale const &loc,method_type how=default_method) | |
| | | { | |
| | | return to_utf<CharType>(text.c_str(),text.c_str()+text.size | |
| | | (),loc,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text in UTF to locale encoding given by \a loc | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(std::basic_string<CharType> const &text,st | |
| | | d::locale const &loc,method_type how=default_method) | |
| | | { | |
| | | return from_utf(text.c_str(),text.c_str()+text.size(),loc,h | |
| | | ow); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text in locale encoding given by \a loc to UTF | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> to_utf(char const *text,std::locale | |
| | | const &loc,method_type how=default_method) | |
| | | { | |
| | | char const *text_end = text; | |
| | | while(*text_end) | |
| | | text_end++; | |
| | | return to_utf<CharType>(text,text_end,loc,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text in UTF to locale encoding given by \a loc | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::string from_utf(CharType const *text,std::locale const &lo | |
| | | c,method_type how=default_method) | |
| | | { | |
| | | CharType const *text_end = text; | |
| | | while(*text_end) | |
| | | text_end++; | |
| | | return from_utf(text,text_end,loc,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a text in range [begin,end) to \a to_encoding from | |
| | | \a from_encoding | |
| | | /// | |
| | | | |
| | | BOOSTER_API | |
| | | std::string between(char const *begin, | |
| | | char const *end, | |
| | | std::string const &to_encoding, | |
| | | std::string const &from_encoding, | |
| | | method_type how=default_method); | |
| | | | |
| | | /// | |
| | | /// Convert a \a text to \a to_encoding from \a from_encoding | |
| | | /// | |
| | | | |
| | | inline | |
| | | std::string between(char const *text, | |
| | | std::string const &to_encoding, | |
| | | std::string const &from_encoding, | |
| | | method_type how=default_method) | |
| | | { | |
| | | char const *end=text; | |
| | | while(*end) | |
| | | end++; | |
| | | return between(text,end,to_encoding,from_encoding,how); | |
| | | } | |
| | | | |
| | | /// | |
| | | /// Convert a \a text to \a to_encoding from \a from_encoding | |
| | | /// | |
| | | inline | |
| | | std::string between(std::string const &text, | |
| | | std::string const &to_encoding, | |
| | | std::string const &from_encoding, | |
| | | method_type how=default_method) | |
| | | { | |
| | | return between(text.c_str(),text.c_str()+text.size(),to_enc | |
| | | oding,from_encoding,how); | |
| | | } | |
| | | | |
| | | /// @} | |
| | | | |
| | | /// \cond INTERNAL | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::basic_string<char> to_utf(char const *begin,ch | |
| | | ar const *end,std::string const &charset,method_type how); | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::string from_utf(char const *begin,char const * | |
| | | end,std::string const &charset,method_type how); | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::basic_string<wchar_t> to_utf(char const *begin | |
| | | ,char const *end,std::string const &charset,method_type how); | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::string from_utf(wchar_t const *begin,wchar_t c | |
| | | onst *end,std::string const &charset,method_type how); | |
| | | | |
| | | #ifdef BOOSTER_HAS_CHAR16_T | |
| | | template<> | |
| | | BOOSTER_API std::basic_string<char16_t> to_utf(char const *begi | |
| | | n,char const *end,std::string const &charset,method_type how); | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::string from_utf(char16_t const *begin,char16_t | |
| | | const *end,std::string const &charset,method_type how); | |
| | | #endif | |
| | | | |
| | | #ifdef BOOSTER_HAS_CHAR32_T | |
| | | template<> | |
| | | BOOSTER_API std::basic_string<char32_t> to_utf(char const *begi | |
| | | n,char const *end,std::string const &charset,method_type how); | |
| | | | |
| | | template<> | |
| | | BOOSTER_API std::string from_utf(char32_t const *begin,char32_t | |
| | | const *end,std::string const &charset,method_type how); | |
| | | #endif | |
| | | | |
| | | /// \endcond | |
| | | } // conv | |
| | | | |
| | | } // locale | |
| | | } // boost | |
| | | | |
| | | #ifdef BOOSTER_MSVC | |
| | | #pragma warning(pop) | |
| | | #endif | |
| | | | |
| #endif | | #endif | |
|
| | | | |
| | | // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | |
| | | | |
End of changes. 14 change blocks. |
| 138 lines changed or deleted | | 285 lines changed or added | |
|
| format.h | | format.h | |
| | | | |
| skipping to change at line 20 | | skipping to change at line 20 | |
| | | | |
| #include <booster/config.h> | | #include <booster/config.h> | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| # pragma warning(push) | | # pragma warning(push) | |
| # pragma warning(disable : 4275 4251 4231 4660) | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #endif | | #endif | |
| #include <booster/locale/message.h> | | #include <booster/locale/message.h> | |
| #include <booster/locale/formatting.h> | | #include <booster/locale/formatting.h> | |
| | | | |
| #include <sstream> | | #include <sstream> | |
|
| #include <iostream> | | | |
| | | | |
| namespace booster { | | namespace booster { | |
| namespace locale { | | namespace locale { | |
| | | | |
| /// | | /// | |
| /// \defgroup format Format | | /// \defgroup format Format | |
| /// | | /// | |
| /// This module provides printf like functionality integrated to io
streams and suitable for localization | | /// This module provides printf like functionality integrated to io
streams and suitable for localization | |
| /// | | /// | |
| /// @{ | | /// @{ | |
| | | | |
| skipping to change at line 101 | | skipping to change at line 100 | |
| { | | { | |
| output << *reinterpret_cast<Type const *>(ptr); | | output << *reinterpret_cast<Type const *>(ptr); | |
| } | | } | |
| | | | |
| void const *pointer_; | | void const *pointer_; | |
| writer_type writer_; | | writer_type writer_; | |
| }; // formattible | | }; // formattible | |
| | | | |
| class BOOSTER_API format_parser { | | class BOOSTER_API format_parser { | |
| public: | | public: | |
|
| format_parser(std::ios_base &ios); | | format_parser(std::ios_base &ios,void *,void (*imbuer)(void
*,std::locale const &)); | |
| ~format_parser(); | | ~format_parser(); | |
| | | | |
| unsigned get_posision(); | | unsigned get_posision(); | |
| | | | |
| void set_one_flag(std::string const &key,std::string const
&value); | | void set_one_flag(std::string const &key,std::string const
&value); | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| void set_flag_with_str(std::string const &key,std::basic_st
ring<CharType> const &value) | | void set_flag_with_str(std::string const &key,std::basic_st
ring<CharType> const &value) | |
| { | | { | |
| if(key=="ftime" || key=="strftime") { | | if(key=="ftime" || key=="strftime") { | |
| as::strftime(ios_); | | as::strftime(ios_); | |
|
| ext_pattern(ios_,flags::datetime_pattern,value); | | ios_info::get(ios_).date_time_pattern(value); | |
| } | | } | |
| } | | } | |
| void restore(); | | void restore(); | |
| private: | | private: | |
|
| | | void imbue(std::locale const &); | |
| format_parser(format_parser const &); | | format_parser(format_parser const &); | |
| void operator=(format_parser const &); | | void operator=(format_parser const &); | |
| | | | |
| std::ios_base &ios_; | | std::ios_base &ios_; | |
| struct data; | | struct data; | |
| std::auto_ptr<data> d; | | std::auto_ptr<data> d; | |
| }; | | }; | |
| | | | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 244 | | skipping to change at line 244 | |
| return buffer.str(); | | return buffer.str(); | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// write a formatted string to output stream \a out using out'
s locale | | /// write a formatted string to output stream \a out using out'
s locale | |
| /// | | /// | |
| void write(stream_type &out) const | | void write(stream_type &out) const | |
| { | | { | |
| string_type format; | | string_type format; | |
| if(translate_) | | if(translate_) | |
|
| format = message_.str<CharType>(out.getloc(),ext_value(
out,flags::domain_id)); | | format = message_.str<CharType>(out.getloc(),ios_info::
get(out).domain_id()); | |
| else | | else | |
| format = format_; | | format = format_; | |
| | | | |
| format_output(out,format); | | format_output(out,format); | |
| | | | |
| } | | } | |
| | | | |
| private: | | private: | |
| | | | |
| void format_output(stream_type &out,string_type const &sformat)
const | | void format_output(stream_type &out,string_type const &sformat)
const | |
| | | | |
| skipping to change at line 285 | | skipping to change at line 285 | |
| continue; | | continue; | |
| } | | } | |
| | | | |
| if(pos+1 < size && format[pos+1]==obrk) { | | if(pos+1 < size && format[pos+1]==obrk) { | |
| out << obrk; | | out << obrk; | |
| pos+=2; | | pos+=2; | |
| continue; | | continue; | |
| } | | } | |
| pos++; | | pos++; | |
| | | | |
|
| details::format_parser fmt(out); | | details::format_parser fmt(out,reinterpret_cast<void *>
(&out),&basic_format::imbue_locale); | |
| | | | |
| while(pos < size) { | | while(pos < size) { | |
| std::string key; | | std::string key; | |
| std::string svalue; | | std::string svalue; | |
| string_type value; | | string_type value; | |
| bool use_svalue = true; | | bool use_svalue = true; | |
| for(;format[pos];pos++) { | | for(;format[pos];pos++) { | |
| char_type c=format[pos]; | | char_type c=format[pos]; | |
| if(c==comma || c==eq || c==cbrk) | | if(c==comma || c==eq || c==cbrk) | |
| break; | | break; | |
| | | | |
| skipping to change at line 332 | | skipping to change at line 332 | |
| } | | } | |
| else { | | else { | |
| char_type c; | | char_type c; | |
| while((c=format[pos])!=0 && c!=comma && c!=
cbrk) { | | while((c=format[pos])!=0 && c!=comma && c!=
cbrk) { | |
| svalue+=static_cast<char>(c); | | svalue+=static_cast<char>(c); | |
| pos++; | | pos++; | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
|
| if(use_svalue) | | if(use_svalue) { | |
| fmt.set_one_flag(key,svalue); | | fmt.set_one_flag(key,svalue); | |
|
| | | } | |
| else | | else | |
| fmt.set_flag_with_str(key,value); | | fmt.set_flag_with_str(key,value); | |
| | | | |
| if(format[pos]==',') { | | if(format[pos]==',') { | |
| pos++; | | pos++; | |
| continue; | | continue; | |
| } | | } | |
| else if(format[pos]=='}') { | | else if(format[pos]=='}') { | |
| unsigned position = fmt.get_posision(); | | unsigned position = fmt.get_posision(); | |
| out << get(position); | | out << get(position); | |
| | | | |
| skipping to change at line 381 | | skipping to change at line 382 | |
| formattible_type get(unsigned id) const | | formattible_type get(unsigned id) const | |
| { | | { | |
| if(id >= parameters_count_) | | if(id >= parameters_count_) | |
| return formattible_type(); | | return formattible_type(); | |
| else if(id >= base_params_) | | else if(id >= base_params_) | |
| return ext_params_[id - base_params_]; | | return ext_params_[id - base_params_]; | |
| else | | else | |
| return parameters_[id]; | | return parameters_[id]; | |
| } | | } | |
| | | | |
|
| | | static void imbue_locale(void *ptr,std::locale const &l) | |
| | | { | |
| | | reinterpret_cast<stream_type *>(ptr)->imbue(l); | |
| | | } | |
| | | | |
| static unsigned const base_params_ = 8; | | static unsigned const base_params_ = 8; | |
| | | | |
| message message_; | | message message_; | |
| string_type format_; | | string_type format_; | |
| bool translate_; | | bool translate_; | |
| | | | |
| formattible_type parameters_[base_params_]; | | formattible_type parameters_[base_params_]; | |
| unsigned parameters_count_; | | unsigned parameters_count_; | |
| std::vector<formattible_type> ext_params_; | | std::vector<formattible_type> ext_params_; | |
| }; | | }; | |
| | | | |
| skipping to change at line 409 | | skipping to change at line 415 | |
| { | | { | |
| fmt.write(out); | | fmt.write(out); | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Definiton of char based format | | /// Definiton of char based format | |
| /// | | /// | |
| typedef basic_format<char> format; | | typedef basic_format<char> format; | |
| | | | |
|
| #ifndef BOOSTER_NO_STD_WSTRING | | | |
| /// | | /// | |
| /// Definiton of wchar_t based format | | /// Definiton of wchar_t based format | |
| /// | | /// | |
| typedef basic_format<wchar_t> wformat; | | typedef basic_format<wchar_t> wformat; | |
|
| #endif | | | |
| | | | |
| #ifdef BOOSTER_HAS_CHAR16_T | | #ifdef BOOSTER_HAS_CHAR16_T | |
| /// | | /// | |
| /// Definiton of char16_t based format | | /// Definiton of char16_t based format | |
| /// | | /// | |
| typedef basic_format<char16_t> u16format; | | typedef basic_format<char16_t> u16format; | |
| #endif | | #endif | |
| | | | |
| #ifdef BOOSTER_HAS_CHAR32_T | | #ifdef BOOSTER_HAS_CHAR32_T | |
| /// | | /// | |
| | | | |
End of changes. 11 change blocks. |
| 8 lines changed or deleted | | 12 lines changed or added | |
|
| formatting.h | | formatting.h | |
| | | | |
| skipping to change at line 16 | | skipping to change at line 16 | |
| // http://www.boost.org/LICENSE_1_0.txt) | | // http://www.boost.org/LICENSE_1_0.txt) | |
| // | | // | |
| #ifndef BOOSTER_LOCALE_FORMATTING_H_INCLUDED | | #ifndef BOOSTER_LOCALE_FORMATTING_H_INCLUDED | |
| #define BOOSTER_LOCALE_FORMATTING_H_INCLUDED | | #define BOOSTER_LOCALE_FORMATTING_H_INCLUDED | |
| | | | |
| #include <booster/config.h> | | #include <booster/config.h> | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| # pragma warning(push) | | # pragma warning(push) | |
| # pragma warning(disable : 4275 4251 4231 4660) | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #endif | | #endif | |
|
| #include <booster/locale/time_zone.h> | | | |
| #include <booster/cstdint.h> | | #include <booster/cstdint.h> | |
|
| | | #include <booster/locale/date_time.h> | |
| #include <ostream> | | #include <ostream> | |
| #include <istream> | | #include <istream> | |
| #include <string> | | #include <string> | |
|
| | | #include <string.h> | |
| | | #include <typeinfo> | |
| | | | |
| namespace booster { | | namespace booster { | |
| namespace locale { | | namespace locale { | |
|
| | | /// | |
| | | /// This namespace holds additional formatting | |
| | | /// flags that can be set using ios_info. | |
| | | /// | |
| namespace flags { | | namespace flags { | |
|
| | | /// | |
| | | /// Formatting flags, each one of them has corresponding manipu | |
| | | lation | |
| | | /// in namespace \a as | |
| | | /// | |
| typedef enum { | | typedef enum { | |
| posix = 0, | | posix = 0, | |
| number = 1, | | number = 1, | |
| currency = 2, | | currency = 2, | |
| percent = 3, | | percent = 3, | |
| date = 4, | | date = 4, | |
| time = 5, | | time = 5, | |
| datetime = 6, | | datetime = 6, | |
| strftime = 7, | | strftime = 7, | |
| spellout = 8, | | spellout = 8, | |
| | | | |
| skipping to change at line 63 | | skipping to change at line 73 | |
| date_short = 1 << 10, | | date_short = 1 << 10, | |
| date_medium = 2 << 10, | | date_medium = 2 << 10, | |
| date_long = 3 << 10, | | date_long = 3 << 10, | |
| date_full = 4 << 10, | | date_full = 4 << 10, | |
| date_flags_mask = 7 << 10, | | date_flags_mask = 7 << 10, | |
| | | | |
| datetime_flags_mask = date_flags_mask | time_flags_mask | | datetime_flags_mask = date_flags_mask | time_flags_mask | |
| | | | |
| } display_flags_type; | | } display_flags_type; | |
| | | | |
|
| | | /// | |
| | | /// Special string patters that can be used | |
| | | /// for text formatting | |
| | | /// | |
| typedef enum { | | typedef enum { | |
|
| datetime_pattern, | | datetime_pattern, ///< strftime like formatting | |
| time_zone_id | | time_zone_id ///< time zone name | |
| } pattern_type; | | } pattern_type; | |
| | | | |
|
| | | /// | |
| | | /// Special integer values that can be used for formatting | |
| | | /// | |
| typedef enum { | | typedef enum { | |
|
| domain_id | | domain_id ///< Domain code - for message formatti
ng | |
| } value_type; | | } value_type; | |
| | | | |
| } // flags | | } // flags | |
| | | | |
|
| /// \cond INTERNAL | | /// | |
| | | /// \brief This class holds an external data - beyond existing fmtf | |
| | | lags that std::ios_base holds | |
| | | /// | |
| | | /// You almost never create this object directly, you rather access | |
| | | it via ios_info::get(stream_object) | |
| | | /// static member function. It automatically creates default format | |
| | | ting data for that stream | |
| | | /// | |
| | | class BOOSTER_API ios_info { | |
| | | public: | |
| | | | |
|
| BOOSTER_API uint64_t ext_flags(std::ios_base &); | | /// \cond INTERNAL | |
| BOOSTER_API uint64_t ext_flags(std::ios_base &,flags::display_flags | | | |
| _type mask); | | | |
| BOOSTER_API void ext_setf(std::ios_base &,flags::display_flags_type | | | |
| flags,flags::display_flags_type mask); | | | |
| | | | |
|
| BOOSTER_API int ext_value(std::ios_base &,flags::value_type id); | | ios_info(); | |
| BOOSTER_API void ext_value(std::ios_base &,flags::value_type id,int | | ios_info(ios_info const &); | |
| value); | | ios_info const &operator=(ios_info const &); | |
| | | ~ios_info(); | |
| | | | |
|
| template<typename CharType> | | /// \endcond | |
| void ext_pattern(std::ios_base &,flags::pattern_type pat,std::basic | | | |
| _string<CharType> const &); | | | |
| | | | |
|
| template<typename CharType> | | /// | |
| std::basic_string<CharType> ext_pattern(std::ios_base &,flags::patt | | /// Get ios_info instance for specific stream object | |
| ern_type pattern); | | /// | |
| | | static ios_info &get(std::ios_base &ios); | |
| | | | |
|
| /// Specializations | | /// | |
| | | /// Set a flags that define a way for format data like number, | |
| | | spell, currency etc. | |
| | | /// | |
| | | void display_flags(uint64_t flags); | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | | /// Set a flags that define how to format currency | |
| ttern_id, std::string const &pattern); | | /// | |
| | | void currency_flags(uint64_t flags); | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API std::string ext_pattern(std::ios_base &,flags::pattern_ | | /// Set a flags that define how to format date | |
| type pattern_id); | | /// | |
| | | void date_flags(uint64_t flags); | |
| | | | |
|
| #ifndef BOOSTER_NO_STD_WSTRING | | /// | |
| | | /// Set a flags that define how to format time | |
| | | /// | |
| | | void time_flags(uint64_t flags); | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | | /// Set a flags that define how to format both date and time | |
| ttern_id, std::wstring const &pattern); | | /// | |
| | | void datetime_flags(uint64_t flags); | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API std::wstring ext_pattern(std::ios_base &,flags::pattern | | /// Set special message domain identification | |
| _type pattern_id); | | /// | |
| | | void domain_id(int); | |
| | | | |
|
| #endif // BOOST_NO_STD_WSTRING | | /// | |
| | | /// Set time zone for formatting dates and time | |
| | | /// | |
| | | void time_zone(std::string const &); | |
| | | | |
|
| #ifdef BOOSTER_HAS_CHAR16_T | | /// | |
| template<> | | /// Set date/time pattern (strftime like) | |
| BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | | /// | |
| ttern_id, std::u16string const &pattern); | | template<typename CharType> | |
| | | void date_time_pattern(std::basic_string<CharType> const &str) | |
| | | { | |
| | | string_set &s = date_time_pattern_set(); | |
| | | s.set<CharType>(str.c_str()); | |
| | | } | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API std::u16string ext_pattern(std::ios_base &,flags::patte | | /// Get a flags that define a way for format data like number, | |
| rn_type pattern_id); | | spell, currency etc. | |
| #endif // char16_t, u16string | | /// | |
| | | uint64_t display_flags() const; | |
| | | | |
|
| #ifdef BOOSTER_HAS_CHAR32_T | | /// | |
| template<> | | /// Get a flags that define how to format currency | |
| BOOSTER_API void ext_pattern(std::ios_base &,flags::pattern_type pa | | /// | |
| ttern_id, std::u32string const &pattern); | | uint64_t currency_flags() const; | |
| | | | |
|
| template<> | | /// | |
| BOOSTER_API std::u32string ext_pattern(std::ios_base &,flags::patte | | /// Get a flags that define how to format date | |
| rn_type pattern_id); | | /// | |
| #endif // char32_t, u32string | | uint64_t date_flags() const; | |
| | | | |
|
| /// \endcond | | /// | |
| | | /// Get a flags that define how to format time | |
| | | /// | |
| | | uint64_t time_flags() const; | |
| | | | |
| | | /// | |
| | | /// Get a flags that define how to format both date and time | |
| | | /// | |
| | | uint64_t datetime_flags() const; | |
| | | | |
| | | /// | |
| | | /// Get special message domain identification | |
| | | /// | |
| | | int domain_id() const; | |
| | | | |
| | | /// | |
| | | /// Get time zone for formatting dates and time | |
| | | /// | |
| | | std::string time_zone() const; | |
| | | | |
| | | /// | |
| | | /// Get date/time pattern (strftime like) | |
| | | /// | |
| | | template<typename CharType> | |
| | | std::basic_string<CharType> date_time_pattern() const | |
| | | { | |
| | | string_set const &s = date_time_pattern_set(); | |
| | | return s.get<CharType>(); | |
| | | } | |
| | | | |
| | | /// \cond INTERNAL | |
| | | void on_imbue(); | |
| | | /// \endcond | |
| | | | |
| | | private: | |
| | | | |
| | | class string_set; | |
| | | | |
| | | string_set const &date_time_pattern_set() const; | |
| | | string_set &date_time_pattern_set(); | |
| | | | |
| | | class BOOSTER_API string_set { | |
| | | public: | |
| | | string_set(); | |
| | | ~string_set(); | |
| | | string_set(string_set const &other); | |
| | | string_set const &operator=(string_set const &other); | |
| | | | |
| | | template<typename Char> | |
| | | void set(Char const *s) | |
| | | { | |
| | | delete [] ptr; | |
| | | ptr = 0; | |
| | | type=&typeid(Char); | |
| | | Char const *end = s; | |
| | | while(*end!=0) end++; | |
| | | size = sizeof(Char)*(end - s+1); | |
| | | ptr = new char[size]; | |
| | | memcpy(ptr,s,size); | |
| | | } | |
| | | | |
| | | template<typename Char> | |
| | | std::basic_string<Char> get() const | |
| | | { | |
| | | if(type==0 || *type!=typeid(Char)) | |
| | | throw std::bad_cast(); | |
| | | std::basic_string<Char> result = reinterpret_cast<Char | |
| | | const *>(ptr); | |
| | | return result; | |
| | | } | |
| | | | |
| | | private: | |
| | | std::type_info const *type; | |
| | | size_t size; | |
| | | char *ptr; | |
| | | }; | |
| | | | |
| | | uint64_t flags_; | |
| | | int domain_id_; | |
| | | std::string time_zone_; | |
| | | string_set datetime_; | |
| | | | |
| | | struct data; | |
| | | data *d; | |
| | | | |
| | | }; | |
| | | | |
| /// | | /// | |
| /// \brief This namespace includes all manipulators that can be use
d on IO streams | | /// \brief This namespace includes all manipulators that can be use
d on IO streams | |
| /// | | /// | |
| namespace as { | | namespace as { | |
| /// | | /// | |
| /// \defgroup manipulators I/O Stream manipulators | | /// \defgroup manipulators I/O Stream manipulators | |
| /// | | /// | |
| /// @{ | | /// @{ | |
| /// | | /// | |
| | | | |
| /// | | /// | |
| /// Format values with "POSIX" or "C" locale. Note, if locale
was created with additional non-classic locale then | | /// Format values with "POSIX" or "C" locale. Note, if locale
was created with additional non-classic locale then | |
| /// These numbers may be localized | | /// These numbers may be localized | |
| /// | | /// | |
| | | | |
| inline std::ios_base & posix(std::ios_base & ios) | | inline std::ios_base & posix(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::posix, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::posix); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format a number. Note, unlike standard number formatting, i
ntegers would be treated like real numbers when std::fixed or | | /// Format a number. Note, unlike standard number formatting, i
ntegers would be treated like real numbers when std::fixed or | |
| /// std::scientific manipulators were applied | | /// std::scientific manipulators were applied | |
| /// | | /// | |
| inline std::ios_base & number(std::ios_base & ios) | | inline std::ios_base & number(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::number, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::number); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format currency, number is treated like amount of money | | /// Format currency, number is treated like amount of money | |
| /// | | /// | |
| inline std::ios_base & currency(std::ios_base & ios) | | inline std::ios_base & currency(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::currency, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::currency); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format percent, value 0.3 is treaded as 30%. | | /// Format percent, value 0.3 is treaded as 30%. | |
| /// | | /// | |
| inline std::ios_base & percent(std::ios_base & ios) | | inline std::ios_base & percent(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::percent, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::percent); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format a date, number is treaded as POSIX time | | /// Format a date, number is treaded as POSIX time | |
| /// | | /// | |
| inline std::ios_base & date(std::ios_base & ios) | | inline std::ios_base & date(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::date); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format a time, number is treaded as POSIX time | | /// Format a time, number is treaded as POSIX time | |
| /// | | /// | |
| inline std::ios_base & time(std::ios_base & ios) | | inline std::ios_base & time(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::time); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Format a date and time, number is treaded as POSIX time | | /// Format a date and time, number is treaded as POSIX time | |
| /// | | /// | |
| inline std::ios_base & datetime(std::ios_base & ios) | | inline std::ios_base & datetime(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::datetime, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::datetime); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Create formatted date time, Please note, this manipulator o
nly changes formatting mode, | | /// Create formatted date time, Please note, this manipulator o
nly changes formatting mode, | |
| /// and not format itself, so you are probably looking for ftim
e manipulator | | /// and not format itself, so you are probably looking for ftim
e manipulator | |
| /// | | /// | |
| inline std::ios_base & strftime(std::ios_base & ios) | | inline std::ios_base & strftime(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::strftime, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::strftime); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Spell the number, like "one hundred and ten" | | /// Spell the number, like "one hundred and ten" | |
| /// | | /// | |
| inline std::ios_base & spellout(std::ios_base & ios) | | inline std::ios_base & spellout(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::spellout, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::spellout); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Write an order of the number like 4th. | | /// Write an order of the number like 4th. | |
| /// | | /// | |
| inline std::ios_base & ordinal(std::ios_base & ios) | | inline std::ios_base & ordinal(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::ordinal, flags::display_flags_mask); | | ios_info::get(ios).display_flags(flags::ordinal); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Set default currency formatting style -- national, like "$" | | /// Set default currency formatting style -- national, like "$" | |
| /// | | /// | |
| inline std::ios_base & currency_default(std::ios_base & ios) | | inline std::ios_base & currency_default(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::currency_default, flags::currency_flag
s_mask); | | ios_info::get(ios).currency_flags(flags::currency_default); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Set ISO currency formatting style, like "USD", (requires IC
U >= 4.2) | | /// Set ISO currency formatting style, like "USD", (requires IC
U >= 4.2) | |
| /// | | /// | |
| inline std::ios_base & currency_iso(std::ios_base & ios) | | inline std::ios_base & currency_iso(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::currency_iso, flags::currency_flags_ma
sk); | | ios_info::get(ios).currency_flags(flags::currency_iso); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Set national currency formatting style, like "$" | | /// Set national currency formatting style, like "$" | |
| /// | | /// | |
| inline std::ios_base & currency_national(std::ios_base & ios) | | inline std::ios_base & currency_national(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::currency_national, flags::currency_fla
gs_mask); | | ios_info::get(ios).currency_flags(flags::currency_national)
; | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set default (medium) time formatting style | | /// set default (medium) time formatting style | |
| /// | | /// | |
| inline std::ios_base & time_default(std::ios_base & ios) | | inline std::ios_base & time_default(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time_default, flags::time_flags_mask); | | ios_info::get(ios).time_flags(flags::time_default); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set short time formatting style | | /// set short time formatting style | |
| /// | | /// | |
| inline std::ios_base & time_short(std::ios_base & ios) | | inline std::ios_base & time_short(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time_short, flags::time_flags_mask); | | ios_info::get(ios).time_flags(flags::time_short); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set medium time formatting style | | /// set medium time formatting style | |
| /// | | /// | |
| inline std::ios_base & time_medium(std::ios_base & ios) | | inline std::ios_base & time_medium(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time_medium, flags::time_flags_mask); | | ios_info::get(ios).time_flags(flags::time_medium); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set long time formatting style | | /// set long time formatting style | |
| /// | | /// | |
| inline std::ios_base & time_long(std::ios_base & ios) | | inline std::ios_base & time_long(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time_long, flags::time_flags_mask); | | ios_info::get(ios).time_flags(flags::time_long); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set full time formatting style | | /// set full time formatting style | |
| /// | | /// | |
| inline std::ios_base & time_full(std::ios_base & ios) | | inline std::ios_base & time_full(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::time_full, flags::time_flags_mask); | | ios_info::get(ios).time_flags(flags::time_full); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set default (medium) date formatting style | | /// set default (medium) date formatting style | |
| /// | | /// | |
| inline std::ios_base & date_default(std::ios_base & ios) | | inline std::ios_base & date_default(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date_default, flags::date_flags_mask); | | ios_info::get(ios).date_flags(flags::date_default); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set short date formatting style | | /// set short date formatting style | |
| /// | | /// | |
| inline std::ios_base & date_short(std::ios_base & ios) | | inline std::ios_base & date_short(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date_short, flags::date_flags_mask); | | ios_info::get(ios).date_flags(flags::date_short); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set medium date formatting style | | /// set medium date formatting style | |
| /// | | /// | |
| inline std::ios_base & date_medium(std::ios_base & ios) | | inline std::ios_base & date_medium(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date_medium, flags::date_flags_mask); | | ios_info::get(ios).date_flags(flags::date_medium); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set long date formatting style | | /// set long date formatting style | |
| /// | | /// | |
| inline std::ios_base & date_long(std::ios_base & ios) | | inline std::ios_base & date_long(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date_long, flags::date_flags_mask); | | ios_info::get(ios).date_flags(flags::date_long); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// set full date formatting style | | /// set full date formatting style | |
| /// | | /// | |
| inline std::ios_base & date_full(std::ios_base & ios) | | inline std::ios_base & date_full(std::ios_base & ios) | |
| { | | { | |
|
| ext_setf(ios, flags::date_full, flags::date_flags_mask); | | ios_info::get(ios).date_flags(flags::date_full); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// \cond INTERNAL | | /// \cond INTERNAL | |
| namespace details { | | namespace details { | |
| template<typename CharType> | | template<typename CharType> | |
| struct add_ftime { | | struct add_ftime { | |
| | | | |
| std::basic_string<CharType> ftime; | | std::basic_string<CharType> ftime; | |
| | | | |
| void apply(std::basic_ios<CharType> &ios) const | | void apply(std::basic_ios<CharType> &ios) const | |
| { | | { | |
|
| ext_pattern(ios,flags::datetime_pattern,ftime); | | ios_info::get(ios).date_time_pattern(ftime); | |
| as::strftime(ios); | | as::strftime(ios); | |
| } | | } | |
| | | | |
| }; | | }; | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out,add_ftime<CharType> const &fmt) | | std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out,add_ftime<CharType> const &fmt) | |
| { | | { | |
| fmt.apply(out); | | fmt.apply(out); | |
| return out; | | return out; | |
| | | | |
| skipping to change at line 440 | | skipping to change at line 575 | |
| } | | } | |
| | | | |
| /// \cond INTERNAL | | /// \cond INTERNAL | |
| namespace details { | | namespace details { | |
| struct set_timezone { | | struct set_timezone { | |
| std::string id; | | std::string id; | |
| }; | | }; | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out,set_timezone const &fmt) | | std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out,set_timezone const &fmt) | |
| { | | { | |
|
| ext_pattern(out,flags::time_zone_id,fmt.id); | | ios_info::get(out).time_zone(fmt.id); | |
| return out; | | return out; | |
| } | | } | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_istream<CharType> &operator>>(std::basic_istream
<CharType> &in,set_timezone const &fmt) | | std::basic_istream<CharType> &operator>>(std::basic_istream
<CharType> &in,set_timezone const &fmt) | |
| { | | { | |
|
| ext_pattern(in,flags::time_zone_id,fmt.id); | | ios_info::get(in).time_zone(fmt.id); | |
| return in; | | return in; | |
| } | | } | |
| } | | } | |
| /// \endcond | | /// \endcond | |
| | | | |
| /// | | /// | |
| /// Set GMT time zone to stream | | /// Set GMT time zone to stream | |
| /// | | /// | |
| inline std::ios_base &gmt(std::ios_base &ios) | | inline std::ios_base &gmt(std::ios_base &ios) | |
| { | | { | |
|
| ext_pattern<char>(ios,flags::time_zone_id,"GMT"); | | ios_info::get(ios).time_zone("GMT"); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Set local time zone to stream | | /// Set local time zone to stream | |
| /// | | /// | |
| inline std::ios_base &local_time(std::ios_base &ios) | | inline std::ios_base &local_time(std::ios_base &ios) | |
| { | | { | |
|
| ext_pattern(ios,flags::time_zone_id,std::string()); | | ios_info::get(ios).time_zone(time_zone::global()); | |
| return ios; | | return ios; | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Set time zone using \a id | | /// Set time zone using \a id | |
| /// | | /// | |
| inline details::set_timezone time_zone(char const *id) | | inline details::set_timezone time_zone(char const *id) | |
| { | | { | |
| details::set_timezone tz; | | details::set_timezone tz; | |
| tz.id=id; | | tz.id=id; | |
| | | | |
| skipping to change at line 491 | | skipping to change at line 626 | |
| /// | | /// | |
| /// Set time zone using \a id | | /// Set time zone using \a id | |
| /// | | /// | |
| inline details::set_timezone time_zone(std::string const &id) | | inline details::set_timezone time_zone(std::string const &id) | |
| { | | { | |
| details::set_timezone tz; | | details::set_timezone tz; | |
| tz.id=id; | | tz.id=id; | |
| return tz; | | return tz; | |
| } | | } | |
| | | | |
|
| /// | | | |
| /// Set time zone using time_zone class \a id | | | |
| /// | | | |
| inline details::set_timezone time_zone(booster::locale::time_zo | | | |
| ne const &id) | | | |
| { | | | |
| details::set_timezone tz; | | | |
| tz.id=id.id(); | | | |
| return tz; | | | |
| } | | | |
| | | | |
| /// | | /// | |
| /// @} | | /// @} | |
| /// | | /// | |
| | | | |
| } // as manipulators | | } // as manipulators | |
| | | | |
| } // locale | | } // locale | |
| } // boost | | } // boost | |
| | | | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| | | | |
End of changes. 55 change blocks. |
| 90 lines changed or deleted | | 208 lines changed or added | |
|
| fstream.h | | fstream.h | |
| | | | |
| skipping to change at line 56 | | skipping to change at line 56 | |
| } | | } | |
| return 0; | | return 0; | |
| } | | } | |
| catch(bad_utf const &e) { | | catch(bad_utf const &e) { | |
| return 0; | | return 0; | |
| } | | } | |
| } | | } | |
| }; | | }; | |
| | | | |
| #else // not msvc | | #else // not msvc | |
|
| | | /// \cont INTERNAL | |
| namespace details { | | namespace details { | |
| class stdio_iodev : public booster::io_device { | | class stdio_iodev : public booster::io_device { | |
| stdio_iodev(stdio_iodev const &); | | stdio_iodev(stdio_iodev const &); | |
| void operator=(stdio_iodev const &); | | void operator=(stdio_iodev const &); | |
| public: | | public: | |
| stdio_iodev(FILE *f) : | | stdio_iodev(FILE *f) : | |
| file_(f) | | file_(f) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 103 | | skipping to change at line 103 | |
| } | | } | |
| ~stdio_iodev() | | ~stdio_iodev() | |
| { | | { | |
| fclose(file_); | | fclose(file_); | |
| } | | } | |
| private: | | private: | |
| FILE *file_; | | FILE *file_; | |
| }; | | }; | |
| } // details | | } // details | |
| | | | |
|
| | | /// \endcond | |
| | | | |
| template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | | template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | |
| class basic_filebuf; | | class basic_filebuf; | |
| | | | |
|
| | | /// | |
| | | /// Same as std::basic_filebuf<char> but accepts UTF-8 strings under | |
| | | Windows | |
| | | /// | |
| | | | |
| template<> | | template<> | |
| class basic_filebuf<char> : public booster::streambuf { | | class basic_filebuf<char> : public booster::streambuf { | |
| public: | | public: | |
| | | | |
| basic_filebuf() : opened_(false) | | basic_filebuf() : opened_(false) | |
| { | | { | |
| } | | } | |
| ~basic_filebuf() | | ~basic_filebuf() | |
| { | | { | |
| } | | } | |
| | | | |
| skipping to change at line 178 | | skipping to change at line 184 | |
| if(mode==(std::ios_base::binary | std::ios_base::out
| std::ios_base::app | std::ios_base::in)) | | if(mode==(std::ios_base::binary | std::ios_base::out
| std::ios_base::app | std::ios_base::in)) | |
| return "a+b"; | | return "a+b"; | |
| return ""; | | return ""; | |
| } | | } | |
| | | | |
| bool opened_; | | bool opened_; | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
|
| | | /// | |
| | | /// Same as std::basic_ifstream<char> but accepts UTF-8 strings unde | |
| | | r Windows | |
| | | /// | |
| template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | | template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | |
| class basic_ifstream : public std::basic_istream<CharType,Traits> | | class basic_ifstream : public std::basic_istream<CharType,Traits> | |
| { | | { | |
| public: | | public: | |
| typedef basic_filebuf<CharType,Traits> internal_buffer_type; | | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |
| typedef std::basic_istream<CharType,Traits> internal_stream_
type; | | typedef std::basic_istream<CharType,Traits> internal_stream_
type; | |
| | | | |
| basic_ifstream() : | | basic_ifstream() : | |
| internal_stream_type(new internal_buffer_type()) | | internal_stream_type(new internal_buffer_type()) | |
| { | | { | |
| | | | |
| skipping to change at line 234 | | skipping to change at line 243 | |
| } | | } | |
| ~basic_ifstream() | | ~basic_ifstream() | |
| { | | { | |
| buf_->close(); | | buf_->close(); | |
| } | | } | |
| | | | |
| private: | | private: | |
| std::auto_ptr<internal_buffer_type> buf_; | | std::auto_ptr<internal_buffer_type> buf_; | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// Same as std::basic_ofstream<char> but accepts UTF-8 strings unde | |
| | | r Windows | |
| | | /// | |
| | | | |
| template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | | template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | |
| class basic_ofstream : public std::basic_ostream<CharType,Traits> | | class basic_ofstream : public std::basic_ostream<CharType,Traits> | |
| { | | { | |
| public: | | public: | |
| typedef basic_filebuf<CharType,Traits> internal_buffer_type; | | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |
| typedef std::basic_ostream<CharType,Traits> internal_stream_
type; | | typedef std::basic_ostream<CharType,Traits> internal_stream_
type; | |
| | | | |
| basic_ofstream() : | | basic_ofstream() : | |
| internal_stream_type(new internal_buffer_type()) | | internal_stream_type(new internal_buffer_type()) | |
| { | | { | |
| | | | |
| skipping to change at line 290 | | skipping to change at line 303 | |
| } | | } | |
| ~basic_ofstream() | | ~basic_ofstream() | |
| { | | { | |
| buf_->close(); | | buf_->close(); | |
| } | | } | |
| | | | |
| private: | | private: | |
| std::auto_ptr<internal_buffer_type> buf_; | | std::auto_ptr<internal_buffer_type> buf_; | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// Same as std::basic_fstream<char> but accepts UTF-8 strings under | |
| | | Windows | |
| | | /// | |
| | | | |
| template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | | template<typename CharType,typename Traits = std::char_traits<CharTy
pe> > | |
| class basic_fstream : public std::basic_iostream<CharType,Traits> | | class basic_fstream : public std::basic_iostream<CharType,Traits> | |
| { | | { | |
| public: | | public: | |
| typedef basic_filebuf<CharType,Traits> internal_buffer_type; | | typedef basic_filebuf<CharType,Traits> internal_buffer_type; | |
| typedef std::basic_iostream<CharType,Traits> internal_stream
_type; | | typedef std::basic_iostream<CharType,Traits> internal_stream
_type; | |
| | | | |
| basic_fstream() : | | basic_fstream() : | |
| internal_stream_type(new internal_buffer_type()) | | internal_stream_type(new internal_buffer_type()) | |
| { | | { | |
| | | | |
| skipping to change at line 346 | | skipping to change at line 363 | |
| } | | } | |
| ~basic_fstream() | | ~basic_fstream() | |
| { | | { | |
| buf_->close(); | | buf_->close(); | |
| } | | } | |
| | | | |
| private: | | private: | |
| std::auto_ptr<internal_buffer_type> buf_; | | std::auto_ptr<internal_buffer_type> buf_; | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// Same as std::filebuf but accepts UTF-8 strings under Windows | |
| | | /// | |
| typedef basic_filebuf<char> filebuf; | | typedef basic_filebuf<char> filebuf; | |
|
| | | /// | |
| | | /// Same as std::ifstream but accepts UTF-8 strings under Windows | |
| | | /// | |
| typedef basic_ifstream<char> ifstream; | | typedef basic_ifstream<char> ifstream; | |
|
| | | /// | |
| | | /// Same as std::ofstream but accepts UTF-8 strings under Windows | |
| | | /// | |
| typedef basic_ofstream<char> ofstream; | | typedef basic_ofstream<char> ofstream; | |
|
| | | /// | |
| | | /// Same as std::fstream but accepts UTF-8 strings under Windows | |
| | | /// | |
| typedef basic_fstream<char> fstream; | | typedef basic_fstream<char> fstream; | |
| | | | |
| #endif | | #endif | |
| } // nowide | | } // nowide | |
| } // booster | | } // booster | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 10 change blocks. |
| 1 lines changed or deleted | | 34 lines changed or added | |
|
| generator.h | | generator.h | |
| | | | |
| skipping to change at line 20 | | skipping to change at line 20 | |
| #include <booster/config.h> | | #include <booster/config.h> | |
| #ifdef BOOSTER_MSVC | | #ifdef BOOSTER_MSVC | |
| # pragma warning(push) | | # pragma warning(push) | |
| # pragma warning(disable : 4275 4251 4231 4660) | | # pragma warning(disable : 4275 4251 4231 4660) | |
| #endif | | #endif | |
| #include <string> | | #include <string> | |
| #include <locale> | | #include <locale> | |
| #include <memory> | | #include <memory> | |
| | | | |
| namespace booster { | | namespace booster { | |
|
| | | | |
| | | template<typename Type> | |
| | | class shared_ptr; | |
| | | | |
| /// | | /// | |
| /// \brief This is the main namespace that encloses all localization cl
asses | | /// \brief This is the main namespace that encloses all localization cl
asses | |
| /// | | /// | |
| namespace locale { | | namespace locale { | |
| | | | |
|
| /// | | class localization_backend; | |
| /// a enum type that specifies the character type that locales can | | class localization_backend_manager; | |
| be generated for | | | |
| /// | | | |
| typedef enum { | | | |
| char_facet = 1 << 0, ///< 8-bit character facets | | | |
| wchar_t_facet = 1 << 1, ///< wide character facets | | | |
| char16_t_facet = 1 << 2, ///< C++0x char16_t facets | | | |
| char32_t_facet = 1 << 3, ///< C++0x char32_t facets | | | |
| | | | |
|
| all_characters = 0xFFFF ///< Special mask -- generate all | | static const unsigned nochar_facet = 0; ///< Unspecified | |
| } character_facet_type; | | character category for character independed facets | |
| | | static const unsigned char_facet = 1 << 0; ///< 8-bit charac | |
| | | ter facets | |
| | | static const unsigned wchar_t_facet = 1 << 1; ///< wide charact | |
| | | er facets | |
| | | static const unsigned char16_t_facet = 1 << 2; ///< C++0x char16 | |
| | | _t facets | |
| | | static const unsigned char32_t_facet = 1 << 3; ///< C++0x char32 | |
| | | _t facets | |
| | | | |
|
| /// | | static const unsigned character_first_facet = char_facet; ///< Fir | |
| /// a special enum used for more fine grained generation of facets | | st facet specific for character type | |
| /// | | static const unsigned character_last_facet = char32_t_facet; ///< L | |
| typedef enum { | | ast facet specific for character typr | |
| collation_facet = 1 << 0, ///< Generate collation facets | | static const unsigned all_characters = 0xFFFF; ///< Special mas | |
| formatting_facet= 1 << 1, ///< Generate numbers, currency, da | | k -- generate all | |
| te-time formatting facets | | | |
| message_facet = 1 << 2, ///< Generate message facets | | | |
| codepage_facet= 1 << 3, ///< Generate codepage conversion f | | | |
| acets (derived from std::codecvt) | | | |
| | | | |
|
| all_categories = 0xFFFFFFFFu ///< Generate all of them | | typedef unsigned character_facet_type; ///<type that specifies the | |
| } locale_category_type; | | character type that locales can be generated for | |
| | | | |
| | | static const unsigned convert_facet = 1 << 0; ///< Generate | |
| | | convertsion facets | |
| | | static const unsigned collation_facet = 1 << 1; ///< Generate | |
| | | collation facets | |
| | | static const unsigned formatting_facet= 1 << 2; ///< Generate | |
| | | numbers, currency, date-time formatting facets | |
| | | static const unsigned parsing_facet = 1 << 3; ///< Generate | |
| | | numbers, currency, date-time formatting facets | |
| | | static const unsigned message_facet = 1 << 4; ///< Generate | |
| | | message facets | |
| | | static const unsigned codepage_facet = 1 << 5; ///< Generate | |
| | | codepage conversion facets (derived from std::codecvt) | |
| | | static const unsigned boundary_facet = 1 << 6; ///< Generate | |
| | | boundary analysis facet | |
| | | | |
| | | static const unsigned per_character_facet_first = convert_facet | |
| | | ; ///< First facet specific for character | |
| | | static const unsigned per_character_facet_last = boundary_facet | |
| | | ; ///< Last facet specific for character | |
| | | | |
| | | static const unsigned calendar_facet = 1 << 16; ///< Generat | |
| | | e boundary analysis facet | |
| | | static const unsigned information_facet = 1 << 17; ///< Gener | |
| | | ate general locale information facet | |
| | | | |
| | | static const unsigned non_character_facet_first = calendar_facet | |
| | | ; ///< First character independed facet | |
| | | static const unsigned non_character_facet_last = information_fac | |
| | | et;///< Last character independed facet | |
| | | | |
| | | static const unsigned all_categories = 0xFFFFFFFFu; ///< Gene | |
| | | rate all of them | |
| | | | |
| | | typedef unsigned locale_category_type; ///< a type used for more fi | |
| | | ne grained generation of facets | |
| | | | |
| /// | | /// | |
| /// \brief the major class used for locale generation | | /// \brief the major class used for locale generation | |
| /// | | /// | |
| /// This class is used for specification of all parameters required
for locale generation and | | /// This class is used for specification of all parameters required
for locale generation and | |
| /// caching. This class const member functions are thread safe if l
ocale class implementation is thread safe. | | /// caching. This class const member functions are thread safe if l
ocale class implementation is thread safe. | |
| /// | | /// | |
| | | | |
| class BOOSTER_API generator { | | class BOOSTER_API generator { | |
| public: | | public: | |
| | | | |
|
| | | /// | |
| | | /// Create new generator using global localization_backend_mana | |
| | | ger | |
| | | /// | |
| generator(); | | generator(); | |
|
| | | /// | |
| | | /// Create new generator using specific localization_backend_ma | |
| | | nager | |
| | | /// | |
| | | generator(localization_backend_manager const &); | |
| | | | |
| ~generator(); | | ~generator(); | |
| | | | |
| /// | | /// | |
| /// Set types of facets that should be generated, default all | | /// Set types of facets that should be generated, default all | |
| /// | | /// | |
| void categories(unsigned cats); | | void categories(unsigned cats); | |
| /// | | /// | |
| /// Get types of facets that should be generated, default all | | /// Get types of facets that should be generated, default all | |
| /// | | /// | |
| unsigned categories() const; | | unsigned categories() const; | |
| | | | |
| skipping to change at line 81 | | skipping to change at line 105 | |
| /// | | /// | |
| /// Set the characters type for which the facets should be gene
rated, default all supported | | /// Set the characters type for which the facets should be gene
rated, default all supported | |
| /// | | /// | |
| void characters(unsigned chars); | | void characters(unsigned chars); | |
| /// | | /// | |
| /// Get the characters type for which the facets should be gene
rated, default all supported | | /// Get the characters type for which the facets should be gene
rated, default all supported | |
| /// | | /// | |
| unsigned characters() const; | | unsigned characters() const; | |
| | | | |
| /// | | /// | |
|
| /// Set encoding used for 8-bit character encoding. Default is | | | |
| system default encoding | | | |
| /// | | | |
| void octet_encoding(std::string const &encoding); | | | |
| /// | | | |
| /// Get encoding used for 8-bit character encoding. Default is | | | |
| system default encoding | | | |
| /// | | | |
| std::string octet_encoding() const; | | | |
| | | | |
| /// | | | |
| /// Add a new domain of messages that would be generated. It sh
ould be set in order to enable | | /// Add a new domain of messages that would be generated. It sh
ould be set in order to enable | |
| /// messages support. | | /// messages support. | |
| /// | | /// | |
| void add_messages_domain(std::string const &domain); | | void add_messages_domain(std::string const &domain); | |
| /// | | /// | |
| /// Set default message domain. If this member was not called,
the first added messages domain is used. | | /// Set default message domain. If this member was not called,
the first added messages domain is used. | |
| /// If the domain \a domain is not added yet it is added. | | /// If the domain \a domain is not added yet it is added. | |
| /// | | /// | |
| void set_default_messages_domain(std::string const &domain); | | void set_default_messages_domain(std::string const &domain); | |
| | | | |
| | | | |
| skipping to change at line 130 | | skipping to change at line 145 | |
| /// Remove all added paths | | /// Remove all added paths | |
| /// | | /// | |
| void clear_paths(); | | void clear_paths(); | |
| | | | |
| /// | | /// | |
| /// Remove all cached locales | | /// Remove all cached locales | |
| /// | | /// | |
| void clear_cache(); | | void clear_cache(); | |
| | | | |
| /// | | /// | |
|
| /// Generate a locale with id \a id and put it in cache | | /// Turn locale caching ON | |
| /// | | | |
| void preload(std::string const &id); | | | |
| /// | | | |
| /// Generate a locale with id \a id, encoding \a encoding and p | | | |
| ut it in cache | | | |
| /// | | /// | |
|
| void preload(std::string const &id,std::string const &encoding)
; | | void locale_cache_enabled(bool on); | |
| | | | |
| /// | | /// | |
|
| /// Generate a locale with id \a id and put it in cache, use \a | | /// Get locale cache option | |
| base as a locale for which all facets are added, | | | |
| /// instead of global one | | | |
| /// | | | |
| void preload(std::locale const &base,std::string const &id); | | | |
| /// | | | |
| /// Generate a locale with id \a id, encoding \a encoding and p | | | |
| ut it in cache, use \a base as a locale for which all facets are added, | | | |
| /// instead of global one | | | |
| /// | | /// | |
|
| void preload(std::locale const &base,std::string const &id,std:
:string const &encoding); | | bool locale_cache_enabled() const; | |
| | | | |
| /// | | /// | |
| /// Generate a locale with id \a id | | /// Generate a locale with id \a id | |
| /// | | /// | |
| std::locale generate(std::string const &id) const; | | std::locale generate(std::string const &id) const; | |
| /// | | /// | |
|
| /// Generate a locale with id \a id, encoding \a encoding | | | |
| /// | | | |
| std::locale generate(std::string const &id,std::string const &e | | | |
| ncoding) const; | | | |
| | | | |
| /// | | | |
| /// Generate a locale with id \a id, use \a base as a locale fo
r which all facets are added, | | /// Generate a locale with id \a id, use \a base as a locale fo
r which all facets are added, | |
|
| /// instead of global one | | /// instead of std::locale::classic() one | |
| /// | | /// | |
| std::locale generate(std::locale const &base,std::string const
&id) const; | | std::locale generate(std::locale const &base,std::string const
&id) const; | |
| /// | | /// | |
|
| /// Generate a locale with id \a id, encoding \a encoding, use | | /// Shortcut to generate(id) | |
| \a base as a locale for which all facets are added, | | | |
| /// instead of global one | | | |
| /// | | /// | |
|
| std::locale generate(std::locale const &base,std::string const | | std::locale operator()(std::string const &id) const | |
| &id,std::string const &encoding) const; | | { | |
| | | return generate(id); | |
| | | } | |
| | | | |
| /// | | /// | |
|
| /// Get a locale with id \a id from cache, if not found, genera | | /// Set backend specific option | |
| te one | | | |
| /// | | | |
| std::locale get(std::string const &id) const; | | | |
| /// | | | |
| /// Get a locale with id \a id and encoding \a encoding from ca | | | |
| che, if not found, generate one | | | |
| /// | | /// | |
|
| std::locale get(std::string const &id,std::string const &encodi
ng) const; | | void set_option(std::string const &name,std::string const &valu
e); | |
| | | | |
| /// | | /// | |
|
| /// Shortcut to get(id) | | /// Clear backend specific options | |
| /// | | | |
| std::locale operator()(std::string const &id) const | | | |
| { | | | |
| return get(id); | | | |
| } | | | |
| /// | | | |
| /// Shortcut to get(id,encoding) | | | |
| /// | | /// | |
|
| std::locale operator()(std::string const &id,std::string const | | void clear_options(); | |
| &encoding) const | | | |
| { | | | |
| return get(id,encoding); | | | |
| } | | | |
| | | | |
| private: | | private: | |
| | | | |
|
| template<typename CharType> | | void set_all_options(shared_ptr<localization_backend> backend,s | |
| std::locale generate_for(std::locale const &source) const; | | td::string const &id) const; | |
| std::locale complete_generation(std::locale const &source) cons | | | |
| t; | | | |
| | | | |
| generator(generator const &); | | generator(generator const &); | |
| void operator=(generator const &); | | void operator=(generator const &); | |
| | | | |
| struct data; | | struct data; | |
| std::auto_ptr<data> d; | | std::auto_ptr<data> d; | |
| }; | | }; | |
| | | | |
| } | | } | |
| } | | } | |
| | | | |
End of changes. 21 change blocks. |
| 88 lines changed or deleted | | 86 lines changed or added | |
|
| io_service.h | | io_service.h | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 26 | |
| #include <booster/aio/aio_category.h> | | #include <booster/aio/aio_category.h> | |
| #include <booster/callback.h> | | #include <booster/callback.h> | |
| #include <booster/noncopyable.h> | | #include <booster/noncopyable.h> | |
| #include <string> | | #include <string> | |
| #include <memory> | | #include <memory> | |
| | | | |
| namespace booster { | | namespace booster { | |
| class ptime; | | class ptime; | |
| namespace aio { | | namespace aio { | |
| | | | |
|
| typedef callback<void(system::error_code const &e,int fd)> accept_ha
ndler; | | | |
| class event_loop_impl; | | class event_loop_impl; | |
|
| | | | |
| | | /// | |
| | | /// \brief this is the central event loop that dispatches all reques | |
| | | ts. | |
| | | /// | |
| | | /// This all this class member functions are thread safe unless spec | |
| | | ified otherwise. | |
| | | /// | |
| | | /// Sinlge or multiple threads may execute run() member function and | |
| | | dispatch its handlers, this class | |
| | | /// also can be safely created before fork and used after it | |
| | | /// | |
| class BOOSTER_API io_service : public noncopyable { | | class BOOSTER_API io_service : public noncopyable { | |
| public: | | public: | |
| | | | |
| static const int in = 1 << 0; | | static const int in = 1 << 0; | |
| static const int out = 1 << 1; | | static const int out = 1 << 1; | |
| | | | |
|
| | | /// | |
| | | /// Create io service using specific reactor type and not de | |
| | | fault one (see reactor's class use_* constants) | |
| | | /// | |
| io_service(int reactor_type); | | io_service(int reactor_type); | |
|
| | | /// | |
| | | /// Create io service using default reactor | |
| | | /// | |
| io_service(); | | io_service(); | |
|
| | | /// | |
| | | /// Destroy io_service. It should be stopped before!. | |
| | | /// | |
| ~io_service(); | | ~io_service(); | |
| | | | |
|
| | | /// | |
| | | /// Set event handler \a h for file descriptor \fd. \a event | |
| | | can be in, out or in. | |
| | | /// | |
| | | /// Error handling: | |
| | | /// | |
| | | /// - If invalid \a event type is given, std::invalid_argume | |
| | | nt is throw. | |
| | | /// - All other applicative errors are always reported using | |
| | | event handler \a h and never thrown directly. | |
| | | /// | |
| void set_io_event(native_type fd,int event,event_handler con
st &h); | | void set_io_event(native_type fd,int event,event_handler con
st &h); | |
|
| | | /// | |
| | | /// Cancel all io-events for file descriptor \a fd. Event ha | |
| | | ndlers associated with this descriptor are | |
| | | /// dispatched asynchronously with aio_error::canceled error | |
| | | code. | |
| | | /// | |
| void cancel_io_events(native_type fd); | | void cancel_io_events(native_type fd); | |
| | | | |
|
| | | /// | |
| | | /// Create a timer that expires in \a point time, that is ha | |
| | | ndled with \a h handler. | |
| | | /// the handler will be called only in two cases: | |
| | | /// | |
| | | /// - When the current time >= \a point. | |
| | | /// - Timer was canceled. \a h will be dispatched with aio_e | |
| | | rror::canceled error code. | |
| | | /// | |
| | | /// The return value is special identification for the speci | |
| | | fic timer, it can be used for timer cancellation. | |
| | | /// Once cancel_timer_event is called with this unique ident | |
| | | ification, it should never be called again with | |
| | | /// this id as other timer may receive this identification. | |
| | | /// | |
| int set_timer_event(ptime const &point,event_handler const &
h); | | int set_timer_event(ptime const &point,event_handler const &
h); | |
|
| | | | |
| | | /// | |
| | | /// Cancel timer created with set_timer_event() asynchronous | |
| | | ly, | |
| | | /// | |
| void cancel_timer_event(int event_id); | | void cancel_timer_event(int event_id); | |
| | | | |
|
| | | /// | |
| | | /// Run main event loop. This function starts actual event l | |
| | | oop. It does not return until stop | |
| | | /// is called or error occurs. | |
| | | /// | |
| | | /// If error occurs (exception is thrown) you may try to res | |
| | | tart the event loop by calling run once again. | |
| | | /// | |
| | | /// However if run() is exited normally (i.e. by calling sto | |
| | | p()) then you need to call reset() member function | |
| | | /// before next call of run(). | |
| | | /// | |
| void run(); | | void run(); | |
|
| | | | |
| | | /// | |
| | | /// Same as run(), but, event-loop specific errors are repor | |
| | | ted via \a e error code rather then by throwing. | |
| | | /// Note, event handlers still may throw. | |
| | | /// | |
| void run(system::error_code &e); | | void run(system::error_code &e); | |
|
| | | | |
| | | /// | |
| | | /// Prepare the service after it was stopped. This function | |
| | | is not thread safe. | |
| | | /// | |
| void reset(); | | void reset(); | |
|
| | | /// | |
| | | /// Stop the service. All threads executing run() function w | |
| | | ill exit from it. You can't use this service | |
| | | /// till you call reset() function. | |
| | | /// | |
| void stop(); | | void stop(); | |
|
| | | | |
| | | /// | |
| | | /// Post a single handler \a h for immediate execution in th | |
| | | e event loop queue. Useful for execution of some | |
| | | /// job in the thread that runs the event loop of the io_ser | |
| | | vice. | |
| | | /// | |
| void post(handler const &h); | | void post(handler const &h); | |
| | | | |
|
| | | /// | |
| | | /// Get the real name of the reactor that io_service uses (c | |
| | | alls reactor::name()) | |
| | | /// | |
| | | | |
| std::string reactor_name(); | | std::string reactor_name(); | |
| private: | | private: | |
| struct data; | | struct data; | |
| hold_ptr<data> d; | | hold_ptr<data> d; | |
| std::auto_ptr<event_loop_impl> impl_; | | std::auto_ptr<event_loop_impl> impl_; | |
| }; | | }; | |
| | | | |
| } // aio | | } // aio | |
| } // booster | | } // booster | |
| | | | |
| | | | |
End of changes. 15 change blocks. |
| 1 lines changed or deleted | | 99 lines changed or added | |
|
| log.h | | log.h | |
| | | | |
| skipping to change at line 19 | | skipping to change at line 19 | |
| #define BOOSTER_LOGGER_H | | #define BOOSTER_LOGGER_H | |
| | | | |
| #include <booster/config.h> | | #include <booster/config.h> | |
| #include <iosfwd> | | #include <iosfwd> | |
| #include <memory> | | #include <memory> | |
| #include <string> | | #include <string> | |
| #include <booster/copy_ptr.h> | | #include <booster/copy_ptr.h> | |
| #include <booster/hold_ptr.h> | | #include <booster/hold_ptr.h> | |
| #include <booster/noncopyable.h> | | #include <booster/noncopyable.h> | |
| | | | |
|
| | | /*! \file */ | |
| | | | |
| namespace booster { | | namespace booster { | |
| | | | |
| template<typename T> | | template<typename T> | |
| class shared_ptr; | | class shared_ptr; | |
| template<typename T> | | template<typename T> | |
| class weak_ptr; | | class weak_ptr; | |
| | | | |
| /// | | /// | |
| /// \brief This namespace includes Booster.Log related classes | | /// \brief This namespace includes Booster.Log related classes | |
| /// | | /// | |
| | | | |
| namespace log { | | namespace log { | |
| | | | |
|
| | | /// | |
| | | /// This enum defined severity level of logged messages | |
| | | /// | |
| typedef enum { | | typedef enum { | |
| emergency = 0, | | emergency = 0, | |
| alert = 10, | | alert = 10, | |
| critical = 20, | | critical = 20, | |
| error = 30, | | error = 30, | |
| warning = 40, | | warning = 40, | |
| notice = 50, | | notice = 50, | |
| info = 60, | | info = 60, | |
| debug = 70, | | debug = 70, | |
| all = 100 | | all = 100 | |
| } level_type; | | } level_type; | |
| | | | |
|
| | | /// | |
| | | /// \brief This class represents a single message that should be wri | |
| | | tten to log | |
| | | /// | |
| | | /// Note, it is some generalization of data that allows you to forma | |
| | | t any generic | |
| | | /// data, it generally used by logging sinks rather then by end user | |
| | | s | |
| | | /// | |
| class BOOSTER_API message { | | class BOOSTER_API message { | |
| public: | | public: | |
|
| | | /// | |
| | | /// Create message with severity level \a l, sent from modul | |
| | | e \a m in file | |
| | | /// \a name in line \a line | |
| | | /// | |
| message(level_type l,char const *m,char const *name,int line
); | | message(level_type l,char const *m,char const *name,int line
); | |
| | | | |
|
| | | /// | |
| | | /// Default constructable | |
| | | /// | |
| message(); | | message(); | |
|
| | | | |
| ~message(); | | ~message(); | |
|
| | | /// Copy message | |
| message(message &); | | message(message &); | |
|
| | | /// Assign the message | |
| message &operator=(message &); | | message &operator=(message &); | |
| | | | |
|
| | | /// | |
| | | /// Get the severity level for the message | |
| | | /// | |
| level_type level() const; | | level_type level() const; | |
|
| | | /// | |
| | | /// Get the module name | |
| | | /// | |
| char const *module() const; | | char const *module() const; | |
|
| | | /// | |
| | | /// Get the file name | |
| | | /// | |
| char const *file_name() const; | | char const *file_name() const; | |
|
| | | /// | |
| | | /// Get the number of line in the file | |
| | | /// | |
| int file_line() const; | | int file_line() const; | |
|
| | | /// | |
| | | /// Get the actual message that should be written | |
| | | /// | |
| std::string log_message() const; | | std::string log_message() const; | |
| | | | |
|
| | | /// | |
| | | /// Get the output stream that consumes the message | |
| | | /// | |
| std::ostream &out(); | | std::ostream &out(); | |
| private: | | private: | |
| level_type level_; | | level_type level_; | |
| char const *module_; | | char const *module_; | |
| char const *file_name_; | | char const *file_name_; | |
| int file_line_; | | int file_line_; | |
| | | | |
| std::auto_ptr<std::ostringstream> message_; | | std::auto_ptr<std::ostringstream> message_; | |
| | | | |
| struct data; | | struct data; | |
| copy_ptr<data> d; | | copy_ptr<data> d; | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// \brief This is the abstract interface to general sink - the cons | |
| | | umer | |
| | | /// of the logged messages | |
| | | /// | |
| class BOOSTER_API sink : public noncopyable { | | class BOOSTER_API sink : public noncopyable { | |
| public: | | public: | |
|
| virtual void log(message const &) = 0; | | /// | |
| | | /// Send the message \a m to log | |
| | | /// | |
| | | /// Note: it does not have to be thread safe - in terms that | |
| | | only | |
| | | /// one message is sent each time and it is promised that ar | |
| | | e | |
| | | /// not sent in parallel | |
| | | /// | |
| | | virtual void log(message const &m) = 0; | |
| virtual ~sink() {} | | virtual ~sink() {} | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// \brief This is the central class that manages all logging operat | |
| | | ions. | |
| | | /// | |
| | | /// This is singleton, you access it only via instance() static memb | |
| | | er function. | |
| | | /// | |
| | | /// This class is thread safe | |
| | | /// | |
| class BOOSTER_API logger : public noncopyable { | | class BOOSTER_API logger : public noncopyable { | |
| public: | | public: | |
|
| | | /// | |
| | | /// Get the instance of the logger | |
| | | /// | |
| static logger &instance(); | | static logger &instance(); | |
| | | | |
|
| | | /// | |
| | | /// Test if the message with severity level \a level of modu | |
| | | le \a module should | |
| | | /// be logged. This is generally called before preparing a m | |
| | | essage in order | |
| | | /// to prevent logging messages that shouldn't be logged | |
| | | /// | |
| bool should_be_logged(level_type level,char const *module); | | bool should_be_logged(level_type level,char const *module); | |
| | | | |
|
| | | /// | |
| | | /// Set specific severity level \a level for a module \a mod | |
| | | ule. It would | |
| | | /// be logged with different logging level then others. | |
| | | /// | |
| | | /// Note: \a module string should remain valid all the time | |
| | | this log level | |
| | | /// is used. It is better to use static strings for these pu | |
| | | rposes | |
| | | /// | |
| void set_log_level(level_type level,char const *module); | | void set_log_level(level_type level,char const *module); | |
|
| | | | |
| | | /// | |
| | | /// Reset \a module's logging severity to default | |
| | | /// | |
| void reset_log_level(char const *module); | | void reset_log_level(char const *module); | |
|
| | | /// | |
| | | /// Set default logging level severity | |
| | | /// | |
| void set_default_level(level_type level); | | void set_default_level(level_type level); | |
| | | | |
|
| | | /// | |
| | | /// Add new logging sink - the target that receives messages | |
| | | . | |
| | | /// It is defined by it's pointer. | |
| | | /// | |
| | | /// If you plan to remove it, keep the pointer on such logge | |
| | | r. | |
| | | /// | |
| void add_sink(shared_ptr<sink> const &s); | | void add_sink(shared_ptr<sink> const &s); | |
|
| | | | |
| | | /// | |
| | | /// Remove a logging sink using its pointer. Note it is enou | |
| | | gh to keep | |
| | | /// weak pointer on it allowing the logger to destroy the si | |
| | | nk. | |
| | | /// | |
| void remove_sink(weak_ptr<sink> const &s); | | void remove_sink(weak_ptr<sink> const &s); | |
|
| | | | |
| | | /// | |
| | | /// Remove all logging sinks from the logger | |
| | | /// | |
| void remove_all_sinks(); | | void remove_all_sinks(); | |
| | | | |
|
| | | /// | |
| | | /// Send a message to the log, note, the message is sent reg | |
| | | ardless of its | |
| | | /// severity, use should_be_logged before you create the mes | |
| | | sage | |
| | | /// | |
| void log(message const &); | | void log(message const &); | |
| | | | |
|
| | | /// | |
| | | /// Get convert the severity level to string | |
| | | /// | |
| static char const *level_to_string(level_type level); | | static char const *level_to_string(level_type level); | |
|
| | | /// | |
| | | /// Convert string to severity level, if the string is inval | |
| | | id, std::invalid_argument is thrown | |
| | | /// | |
| static level_type string_to_level(std::string const &); | | static level_type string_to_level(std::string const &); | |
| | | | |
| private: | | private: | |
| | | | |
| struct entry { | | struct entry { | |
| char const *module; | | char const *module; | |
| level_type level; | | level_type level; | |
| }; | | }; | |
| | | | |
| static const int max_entries_size_ = 1024; | | static const int max_entries_size_ = 1024; | |
| | | | |
| skipping to change at line 123 | | skipping to change at line 227 | |
| ~logger(); | | ~logger(); | |
| }; | | }; | |
| | | | |
| /// | | /// | |
| /// \brief This namespace includes various output devices (sinks) fo
r logger. | | /// \brief This namespace includes various output devices (sinks) fo
r logger. | |
| /// | | /// | |
| /// It includes several standard devices that can be used in most ap
plications | | /// It includes several standard devices that can be used in most ap
plications | |
| /// | | /// | |
| namespace sinks { | | namespace sinks { | |
| | | | |
|
| | | /// | |
| | | /// Convert a logging message to a string with all the data | |
| | | that can be | |
| | | /// written to file. | |
| | | /// | |
| BOOSTER_API std::string format_plain_text_message(message co
nst &msg); | | BOOSTER_API std::string format_plain_text_message(message co
nst &msg); | |
| | | | |
|
| | | /// | |
| | | /// stderr based sink - sends messages to standard error out | |
| | | put | |
| | | /// | |
| class BOOSTER_API standard_error : public sink { | | class BOOSTER_API standard_error : public sink { | |
| public: | | public: | |
| standard_error(); | | standard_error(); | |
| virtual void log(message const &); | | virtual void log(message const &); | |
| virtual ~standard_error(); | | virtual ~standard_error(); | |
| private: | | private: | |
| struct data; | | struct data; | |
| hold_ptr<data> d; | | hold_ptr<data> d; | |
| }; | | }; | |
| | | | |
|
| | | /// | |
| | | /// stderr based sink - sends messages to log file | |
| | | /// | |
| class BOOSTER_API file : public sink { | | class BOOSTER_API file : public sink { | |
| public: | | public: | |
|
| | | /// | |
| | | /// Creates new object but does not open a file | |
| | | /// | |
| file(); | | file(); | |
| virtual ~file(); | | virtual ~file(); | |
|
| | | | |
| | | /// | |
| | | /// Open log file | |
| | | /// | |
| void open(std::string file_name); | | void open(std::string file_name); | |
|
| | | /// | |
| | | /// Enable file rotation and set the maximal number | |
| | | of files that should be kept. | |
| | | /// | |
| | | /// Each time the log opened, the old files are rena | |
| | | med, if there are more files | |
| | | /// then \a limit, the oldest is removed | |
| | | /// | |
| void max_files(unsigned limit); | | void max_files(unsigned limit); | |
|
| | | /// | |
| | | /// Append to output file rather then create new one | |
| | | . | |
| | | /// | |
| void append(); | | void append(); | |
| | | | |
|
| | | /// Send message to the log | |
| virtual void log(message const &); | | virtual void log(message const &); | |
| private: | | private: | |
| | | | |
| void shift(std::string const &base); | | void shift(std::string const &base); | |
| std::string format_file(std::string const &,int); | | std::string format_file(std::string const &,int); | |
| | | | |
| unsigned max_files_; | | unsigned max_files_; | |
| size_t max_size_; | | size_t max_size_; | |
| size_t current_size_; | | size_t current_size_; | |
| bool opened_; | | bool opened_; | |
| bool append_; | | bool append_; | |
| | | | |
| struct data; | | struct data; | |
| hold_ptr<data> d; | | hold_ptr<data> d; | |
| }; | | }; | |
| | | | |
| #ifdef BOOSTER_POSIX | | #ifdef BOOSTER_POSIX | |
|
| | | /// | |
| | | /// POSIX syslog sink. | |
| | | /// | |
| class BOOSTER_API syslog : public sink { | | class BOOSTER_API syslog : public sink { | |
| public: | | public: | |
|
| | | /// | |
| | | /// Create a new logger. Note: it does not call open | |
| | | log, if you want | |
| | | /// to provide non-default parameters, you need to c | |
| | | all it on your own | |
| | | /// | |
| syslog(); | | syslog(); | |
|
| | | /// | |
| | | /// Send the message to the log | |
| | | /// | |
| virtual void log(message const &); | | virtual void log(message const &); | |
| virtual ~syslog(); | | virtual ~syslog(); | |
| private: | | private: | |
| struct data; | | struct data; | |
| hold_ptr<data> d; | | hold_ptr<data> d; | |
| }; | | }; | |
| #endif | | #endif | |
| | | | |
| } // sinks | | } // sinks | |
| | | | |
|
| #define BOOSTER_LOG(_l,_m) | | /// | |
| \ | | /// \def BOOSTER_LOG(level,module) | |
| ::booster::log::logger::instance().should_be_logged(::booste | | /// | |
| r::log::_l,_m) \ | | /// \brief Log a message with severity \a level of the \a module to | |
| && ::booster::log::message(::booster::log::_l,_m,__FILE__,__ | | the log device if applicable. | |
| LINE__).out() | | /// | |
| | | /// Notes: | |
| | | /// | |
| | | /// - it first checks of the message should be logged at all, and if | |
| | | not, all the rest is not called | |
| | | /// - the message is logged in the destruction of the output stream | |
| | | object | |
| | | /// - the parameter \a level should be given as is "warning" or "deb | |
| | | ug" the namespace flags would | |
| | | /// be added withing macro | |
| | | /// - It may be more convenient to use BOOSTER_WARNING or BOOSTER_DE | |
| | | BUG macros | |
| | | /// | |
| | | /// Example: | |
| | | /// | |
| | | /// \code | |
| | | /// BOOSTER_LOG(warning,"file_system") << "Failed to open file nam | |
| | | e " << name; | |
| | | /// BOOSTER_CRITICAL("core") << "Failed to allocate memory"; | |
| | | /// \endcode | |
| | | /// | |
| | | #define BOOSTER_LOG(level,module) | |
| | | \ | |
| | | ::booster::log::logger::instance().should_be_logged(::booste | |
| | | r::log::level,module) \ | |
| | | && ::booster::log::message(::booster::log::level,module,__FI | |
| | | LE__,__LINE__).out() | |
| | | | |
|
| #define BOOSTER_EMERG(_m) BOOSTER_LOG(emergency,_m) | | /// Same as BOOSTER_LOG(emergency,m) | |
| #define BOOSTER_ALERT(_m) BOOSTER_LOG(alert,_m) | | #define BOOSTER_EMERG(m) BOOSTER_LOG(emergency,m) | |
| #define BOOSTER_CRITICAL(_m) BOOSTER_LOG(critical,_m) | | /// Same as BOOSTER_LOG(alert,m) | |
| #define BOOSTER_ERROR(_m) BOOSTER_LOG(error,_m) | | #define BOOSTER_ALERT(m) BOOSTER_LOG(alert,m) | |
| #define BOOSTER_WARNING(_m) BOOSTER_LOG(warning,_m) | | /// Same as BOOSTER_LOG(critical,m) | |
| #define BOOSTER_NOTICE(_m) BOOSTER_LOG(notice,_m) | | #define BOOSTER_CRITICAL(m) BOOSTER_LOG(critical,m) | |
| #define BOOSTER_INFO(_m) BOOSTER_LOG(info,_m) | | /// Same as BOOSTER_LOG(error,m) | |
| #define BOOSTER_DEBUG(_m) BOOSTER_LOG(debug,_m) | | #define BOOSTER_ERROR(m) BOOSTER_LOG(error,m) | |
| | | /// Same as BOOSTER_LOG(warning,m) | |
| | | #define BOOSTER_WARNING(m) BOOSTER_LOG(warning,m) | |
| | | /// Same as BOOSTER_LOG(notice,m) | |
| | | #define BOOSTER_NOTICE(m) BOOSTER_LOG(notice,m) | |
| | | /// Same as BOOSTER_LOG(info,m) | |
| | | #define BOOSTER_INFO(m) BOOSTER_LOG(info,m) | |
| | | /// Same as BOOSTER_LOG(debug,m) | |
| | | #define BOOSTER_DEBUG(m) BOOSTER_LOG(debug,m) | |
| | | | |
| } // log | | } // log | |
| | | | |
| } // booster | | } // booster | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 41 change blocks. |
| 15 lines changed or deleted | | 218 lines changed or added | |
|
| message.h | | message.h | |
| | | | |
| skipping to change at line 33 | | skipping to change at line 33 | |
| namespace booster { | | namespace booster { | |
| namespace locale { | | namespace locale { | |
| /// | | /// | |
| /// \defgroup message Message Formatting (translation) | | /// \defgroup message Message Formatting (translation) | |
| /// | | /// | |
| ///This module provides message translation functionality, i.e. all
ow your application to speak native language | | ///This module provides message translation functionality, i.e. all
ow your application to speak native language | |
| /// | | /// | |
| /// @{ | | /// @{ | |
| /// | | /// | |
| | | | |
|
| class info; | | | |
| | | | |
| /// | | | |
| /// \cond INTERNAL | | /// \cond INTERNAL | |
|
| /// | | | |
| template<typename CharType> | | template<typename CharType> | |
| struct base_message_format: public std::locale::facet | | struct base_message_format: public std::locale::facet | |
| { | | { | |
| }; | | }; | |
| | | | |
|
| | | /// \endcond | |
| | | | |
| | | /// | |
| | | /// \brief This facet provides message formatting abilities | |
| | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| class message_format : public base_message_format<CharType> | | class message_format : public base_message_format<CharType> | |
| { | | { | |
| public: | | public: | |
| | | | |
|
| | | /// | |
| | | /// Character type | |
| | | /// | |
| typedef CharType char_type; | | typedef CharType char_type; | |
|
| | | /// | |
| | | /// String type | |
| | | /// | |
| typedef std::basic_string<CharType> string_type; | | typedef std::basic_string<CharType> string_type; | |
| | | | |
|
| | | /// | |
| | | /// Default constructor | |
| | | /// | |
| message_format(size_t refs = 0) : | | message_format(size_t refs = 0) : | |
| base_message_format<CharType>(refs) | | base_message_format<CharType>(refs) | |
| { | | { | |
| } | | } | |
| | | | |
|
| | | /// | |
| | | /// This function returns a pointer to string for a message def | |
| | | ined by a \a context | |
| | | /// and identification string \a id, both create a single key f | |
| | | or message lookup in | |
| | | /// a domain defined by \a domain_id. | |
| | | /// | |
| | | /// If translated string is found, it is returned, otherwise NU | |
| | | LL is returned | |
| | | /// | |
| | | /// | |
| virtual char_type const *get(int domain_id,char const *context,
char const *id) const = 0; | | virtual char_type const *get(int domain_id,char const *context,
char const *id) const = 0; | |
|
| | | /// | |
| | | /// This function returns a pointer to string for a plural mess | |
| | | age defined by a \a context | |
| | | /// and identification string \a single_id, both create a singl | |
| | | e key for message lookup in | |
| | | /// a domain defined \a domain_id. \a n used to pick a correct | |
| | | translation string for specific | |
| | | /// number. | |
| | | /// | |
| | | /// If translated string is found, it is returned, otherwise NU | |
| | | LL is returned | |
| | | /// | |
| | | /// | |
| virtual char_type const *get(int domain_id,char const *context,
char const *single_id,int n) const = 0; | | virtual char_type const *get(int domain_id,char const *context,
char const *single_id,int n) const = 0; | |
|
| | | | |
| | | /// | |
| | | /// Convert a string that defines \a domain to the integer id u | |
| | | sed by \a get functions | |
| | | /// | |
| virtual int domain(std::string const &domain) const = 0; | | virtual int domain(std::string const &domain) const = 0; | |
| | | | |
| #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | | #if defined (__SUNPRO_CC) && defined (_RWSTD_VER) | |
| std::locale::id& __get_id (void) const { return id; } | | std::locale::id& __get_id (void) const { return id; } | |
| #endif | | #endif | |
|
| static message_format<CharType> *create(info const &,std::vecto | | | |
| r<std::string> const &paths,std::vector<std::string> const &domains); | | | |
| | | | |
| protected: | | protected: | |
| virtual ~message_format() | | virtual ~message_format() | |
| { | | { | |
| } | | } | |
| | | | |
| }; | | }; | |
| | | | |
|
| /// \endcond | | | |
| | | | |
| /// | | /// | |
| /// \brief This class represents a message that can be converted to
specific locale message | | /// \brief This class represents a message that can be converted to
specific locale message | |
| /// | | /// | |
| /// It holds original ASCII string that is queried in the dictionar
y when converting to output string. | | /// It holds original ASCII string that is queried in the dictionar
y when converting to output string. | |
| /// The created string may be UTF-8, UTF-16, UTF-32 or other 8-bit
encoded string according to target | | /// The created string may be UTF-8, UTF-16, UTF-32 or other 8-bit
encoded string according to target | |
| /// character type and locale encoding. | | /// character type and locale encoding. | |
| /// | | /// | |
| struct message { | | struct message { | |
| public: | | public: | |
| | | | |
| | | | |
| skipping to change at line 281 | | skipping to change at line 309 | |
| } | | } | |
| | | | |
| /// | | /// | |
| /// Translate message and write to stream \a out, using imbued
locale and domain set to the | | /// Translate message and write to stream \a out, using imbued
locale and domain set to the | |
| /// stream | | /// stream | |
| /// | | /// | |
| template<typename CharType> | | template<typename CharType> | |
| void write(std::basic_ostream<CharType> &out) const | | void write(std::basic_ostream<CharType> &out) const | |
| { | | { | |
| std::locale const &loc = out.getloc(); | | std::locale const &loc = out.getloc(); | |
|
| int id = ext_value(out,flags::domain_id); | | int id = ios_info::get(out).domain_id(); | |
| std::basic_string<CharType> buffer; | | std::basic_string<CharType> buffer; | |
| out << write(loc,id,buffer); | | out << write(loc,id,buffer); | |
| } | | } | |
| | | | |
| private: | | private: | |
| | | | |
| template<typename CharType> | | template<typename CharType> | |
| CharType const *write(std::locale const &loc,int domain_id,std:
:basic_string<CharType> &buffer) const | | CharType const *write(std::locale const &loc,int domain_id,std:
:basic_string<CharType> &buffer) const | |
| { | | { | |
| CharType const *translated = 0; | | CharType const *translated = 0; | |
| | | | |
| skipping to change at line 467 | | skipping to change at line 495 | |
| return message(context,id).str<char>(loc,domain); | | return message(context,id).str<char>(loc,domain); | |
| } | | } | |
| /// | | /// | |
| /// Translate plural form according to locale \a loc in domain \a d
omain in context \a context | | /// Translate plural form according to locale \a loc in domain \a d
omain in context \a context | |
| /// | | /// | |
| inline std::string dnpgettext(char const *domain,char const *contex
t,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | | inline std::string dnpgettext(char const *domain,char const *contex
t,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | |
| { | | { | |
| return message(context,s,p,n).str<char>(loc,domain); | | return message(context,s,p,n).str<char>(loc,domain); | |
| } | | } | |
| | | | |
|
| #ifndef BOOSTER_NO_STD_WSTRING | | | |
| | | | |
| /// | | /// | |
| /// Translate message \a id according to locale \a loc | | /// Translate message \a id according to locale \a loc | |
| /// | | /// | |
| inline std::wstring wgettext(char const *id,std::locale const &loc=
std::locale()) | | inline std::wstring wgettext(char const *id,std::locale const &loc=
std::locale()) | |
| { | | { | |
| return message(id).str<wchar_t>(loc); | | return message(id).str<wchar_t>(loc); | |
| } | | } | |
| /// | | /// | |
| /// Translate plural form according to locale \a loc | | /// Translate plural form according to locale \a loc | |
| /// | | /// | |
| | | | |
| skipping to change at line 527 | | skipping to change at line 553 | |
| return message(context,id).str<wchar_t>(loc,domain); | | return message(context,id).str<wchar_t>(loc,domain); | |
| } | | } | |
| /// | | /// | |
| /// Translate plural form according to locale \a loc in domain \a d
omain in context \a context | | /// Translate plural form according to locale \a loc in domain \a d
omain in context \a context | |
| /// | | /// | |
| inline std::wstring wdnpgettext(char const *domain,char const *cont
ext,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | | inline std::wstring wdnpgettext(char const *domain,char const *cont
ext,char const *s,char const *p,int n,std::locale const &loc=std::locale()) | |
| { | | { | |
| return message(context,s,p,n).str<wchar_t>(loc,domain); | | return message(context,s,p,n).str<wchar_t>(loc,domain); | |
| } | | } | |
| | | | |
|
| #endif | | | |
| | | | |
| #ifdef BOOSTER_HAS_CHAR16_T | | #ifdef BOOSTER_HAS_CHAR16_T | |
| /// | | /// | |
| /// Translate message \a id according to locale \a loc | | /// Translate message \a id according to locale \a loc | |
| /// | | /// | |
| inline std::u16string u16gettext(char const *id,std::locale const &
loc=std::locale()) | | inline std::u16string u16gettext(char const *id,std::locale const &
loc=std::locale()) | |
| { | | { | |
| return message(id).str<char16_t>(loc); | | return message(id).str<char16_t>(loc); | |
| } | | } | |
| /// | | /// | |
| /// Translate plural form according to locale \a loc | | /// Translate plural form according to locale \a loc | |
| | | | |
| skipping to change at line 665 | | skipping to change at line 689 | |
| template<> | | template<> | |
| struct BOOSTER_API base_message_format<char> : public std::locale::
facet | | struct BOOSTER_API base_message_format<char> : public std::locale::
facet | |
| { | | { | |
| base_message_format(size_t refs = 0) : std::locale::facet(refs) | | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |
| { | | { | |
| } | | } | |
| static std::locale::id id; | | static std::locale::id id; | |
| }; | | }; | |
| | | | |
| template<> | | template<> | |
|
| BOOSTER_API message_format<char> *message_format<char>::create( i | | | |
| nfo const &, | | | |
| | | | |
| std::vector<std::string> const &domains, | | | |
| | | | |
| std::vector<std::string> const &paths); | | | |
| #ifndef BOOSTER_NO_STD_WSTRING | | | |
| | | | |
| template<> | | | |
| struct BOOSTER_API base_message_format<wchar_t> : public std::local
e::facet | | struct BOOSTER_API base_message_format<wchar_t> : public std::local
e::facet | |
| { | | { | |
| base_message_format(size_t refs = 0) : std::locale::facet(refs) | | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |
| { | | { | |
| } | | } | |
| static std::locale::id id; | | static std::locale::id id; | |
| }; | | }; | |
|
| template<> | | | |
| BOOSTER_API message_format<wchar_t> *message_format<wchar_t>::creat | | | |
| e( info const &, | | | |
| | | | |
| std::vector<std::string> const &domains, | | | |
| | | | |
| std::vector<std::string> const &paths); | | | |
| | | | |
| #endif | | | |
| | | | |
| #ifdef BOOSTER_HAS_CHAR16_T | | #ifdef BOOSTER_HAS_CHAR16_T | |
| | | | |
| template<> | | template<> | |
| struct BOOSTER_API base_message_format<char16_t> : public std::loca
le::facet | | struct BOOSTER_API base_message_format<char16_t> : public std::loca
le::facet | |
| { | | { | |
| base_message_format(size_t refs = 0) : std::locale::facet(refs) | | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |
| { | | { | |
| } | | } | |
| static std::locale::id id; | | static std::locale::id id; | |
| }; | | }; | |
|
| template<> | | | |
| BOOSTER_API message_format<char16_t> *message_format<char16_t>::cre | | | |
| ate( info const &, | | | |
| | | | |
| std::vector<std::string> const &domains, | | | |
| | | | |
| std::vector<std::string> const &paths); | | | |
| | | | |
| #endif | | #endif | |
| | | | |
| #ifdef BOOSTER_HAS_CHAR32_T | | #ifdef BOOSTER_HAS_CHAR32_T | |
| | | | |
| template<> | | template<> | |
| struct BOOSTER_API base_message_format<char32_t> : public std::loca
le::facet | | struct BOOSTER_API base_message_format<char32_t> : public std::loca
le::facet | |
| { | | { | |
| base_message_format(size_t refs = 0) : std::locale::facet(refs) | | base_message_format(size_t refs = 0) : std::locale::facet(refs) | |
| { | | { | |
| } | | } | |
| static std::locale::id id; | | static std::locale::id id; | |
| }; | | }; | |
| | | | |
|
| template<> | | | |
| BOOSTER_API message_format<char32_t> *message_format<char32_t>::cre | | | |
| ate( info const &, | | | |
| | | | |
| std::vector<std::string> const &domains, | | | |
| | | | |
| std::vector<std::string> const &paths); | | | |
| | | | |
| #endif | | #endif | |
| | | | |
| /// \endcond | | /// \endcond | |
| | | | |
| /// | | /// | |
| /// @} | | /// @} | |
| /// | | /// | |
| | | | |
| namespace as { | | namespace as { | |
| /// \cond INTERNAL | | /// \cond INTERNAL | |
| namespace details { | | namespace details { | |
| struct set_domain { | | struct set_domain { | |
| std::string domain_id; | | std::string domain_id; | |
| }; | | }; | |
| template<typename CharType> | | template<typename CharType> | |
| std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out, set_domain const &dom) | | std::basic_ostream<CharType> &operator<<(std::basic_ostream
<CharType> &out, set_domain const &dom) | |
| { | | { | |
| int id = std::use_facet<message_format<CharType> >(out.
getloc()).domain(dom.domain_id); | | int id = std::use_facet<message_format<CharType> >(out.
getloc()).domain(dom.domain_id); | |
|
| ext_value(out,flags::domain_id,id); | | ios_info::get(out).domain_id(id); | |
| return out; | | return out; | |
| } | | } | |
| } // details | | } // details | |
| /// \endcond | | /// \endcond | |
| | | | |
| /// | | /// | |
| /// \addtogroup manipulators | | /// \addtogroup manipulators | |
| /// | | /// | |
| /// @{ | | /// @{ | |
| | | | |
| | | | |
End of changes. 19 change blocks. |
| 48 lines changed or deleted | | 46 lines changed or added | |
|