Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

18
test/external/boost/locale/boundary.hpp vendored Normal file
View File

@@ -0,0 +1,18 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_BOUNDARY_HPP_INCLUDED
#define BOOST_LOCALE_BOUNDARY_HPP_INCLUDED
#include <boost/locale/boundary/types.hpp>
#include <boost/locale/boundary/facets.hpp>
#include <boost/locale/boundary/segment.hpp>
#include <boost/locale/boundary/boundary_point.hpp>
#include <boost/locale/boundary/index.hpp>
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,183 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
#define BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED
#include <boost/locale/boundary/types.hpp>
namespace boost {
namespace locale {
namespace boundary {
///
/// \addtogroup boundary
/// @{
///
/// \brief This class represents a boundary point in the text.
///
/// It represents a pair - an iterator and a rule that defines this
/// point.
///
/// This type of object is dereference by the iterators of boundary_point_index. Using a rule()
/// member function you can get the reason why this specific boundary point was selected.
///
/// For example, When you use a sentence boundary analysis, the (rule() & \ref sentence_term) != 0 means
/// that this boundary point was selected because a sentence terminator (like .?!) was spotted
/// and the (rule() & \ref sentence_sep)!=0 means that a separator like line feed or carriage
/// return was observed.
///
/// \note
///
/// - The beginning of analyzed range is always considered a boundary point and its rule is always 0.
/// - when using a word boundary analysis the returned rule relates to a chunk of text preceding
/// this point.
///
/// \see
///
/// - \ref boundary_point_index
/// - \ref segment
/// - \ref segment_index
///
template<typename IteratorType>
class boundary_point {
public:
///
/// The type of the base iterator that iterates the original text
///
typedef IteratorType iterator_type;
///
/// Empty default constructor
///
boundary_point() : rule_(0) {}
///
/// Create a new boundary_point using iterator \p and a rule \a r
///
boundary_point(iterator_type p,rule_type r) :
iterator_(p),
rule_(r)
{
}
///
/// Set an new iterator value \a i
///
void iterator(iterator_type i)
{
iterator_ = i;
}
///
/// Set an new rule value \a r
///
void rule(rule_type r)
{
rule_ = r;
}
///
/// Fetch an iterator
///
iterator_type iterator() const
{
return iterator_;
}
///
/// Fetch a rule
///
rule_type rule() const
{
return rule_;
}
///
/// Check if two boundary points are the same
///
bool operator==(boundary_point const &other) const
{
return iterator_ == other.iterator_ && rule_ = other.rule_;
}
///
/// Check if two boundary points are different
///
bool operator!=(boundary_point const &other) const
{
return !(*this==other);
}
///
/// Check if the boundary point points to same location as an iterator \a other
///
bool operator==(iterator_type const &other) const
{
return iterator_ == other;
}
///
/// Check if the boundary point points to different location from an iterator \a other
///
bool operator!=(iterator_type const &other) const
{
return iterator_ != other;
}
///
/// Automatic cast to the iterator it represents
///
operator iterator_type ()const
{
return iterator_;
}
private:
iterator_type iterator_;
rule_type rule_;
};
///
/// Check if the boundary point \a r points to same location as an iterator \a l
///
template<typename BaseIterator>
bool operator==(BaseIterator const &l,boundary_point<BaseIterator> const &r)
{
return r==l;
}
///
/// Check if the boundary point \a r points to different location from an iterator \a l
///
template<typename BaseIterator>
bool operator!=(BaseIterator const &l,boundary_point<BaseIterator> const &r)
{
return r!=l;
}
/// @}
typedef boundary_point<std::string::const_iterator> sboundary_point; ///< convenience typedef
typedef boundary_point<std::wstring::const_iterator> wsboundary_point; ///< convenience typedef
#ifdef BOOST_HAS_CHAR16_T
typedef boundary_point<std::u16string::const_iterator> u16sboundary_point;///< convenience typedef
#endif
#ifdef BOOST_HAS_CHAR32_T
typedef boundary_point<std::u32string::const_iterator> u32sboundary_point;///< convenience typedef
#endif
typedef boundary_point<char const *> cboundary_point; ///< convenience typedef
typedef boundary_point<wchar_t const *> wcboundary_point; ///< convenience typedef
#ifdef BOOST_HAS_CHAR16_T
typedef boundary_point<char16_t const *> u16cboundary_point; ///< convenience typedef
#endif
#ifdef BOOST_HAS_CHAR32_T
typedef boundary_point<char32_t const *> u32cboundary_point; ///< convenience typedef
#endif
} // boundary
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,203 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
#define BOOST_LOCALE_BOUNDARY_FACETS_HPP_INCLUDED
#include <boost/locale/config.hpp>
#include <boost/locale/boundary/types.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
#include <vector>
namespace boost {
namespace locale {
///
/// \brief This namespae contains all operations required for boundary analysis of text
///
namespace boundary {
///
/// \addtogroup boundary
///
/// @{
///
///
/// \brief This structure is used for representing boundary point
/// that follows the offset.
///
struct break_info {
///
/// Create empty break point at beginning
///
break_info() :
offset(0),
rule(0)
{
}
///
/// Create empty break point at offset v.
/// it is useful for order comparison with other points.
///
break_info(size_t v) :
offset(v),
rule(0)
{
}
///
/// Offset from the beggining of the text where a break occurs.
///
size_t offset;
///
/// The identification of this break point according to
/// various break types
///
rule_type rule;
///
/// Compare two break points' offset. Allows to search with
/// standard algorithms over the index.
///
bool operator<(break_info const &other) const
{
return offset < other.offset;
}
};
///
/// This type holds the analysis of the text - all its break points
/// with marks
///
typedef std::vector<break_info> index_type;
template<typename CharType>
class boundary_indexing;
#ifdef BOOST_LOCALE_DOXYGEN
///
/// \brief This facet generates an index for boundary analysis
/// for a given text.
///
/// It is specialized for 4 types of characters \c char_t, \c wchar_t, \c char16_t and \c char32_t
///
template<typename Char>
class BOOST_LOCALE_DECL boundary_indexing : public std::locale::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)
///
/// The returned value is an index of type \ref index_type. Note that this
/// index is never empty, even if the range [begin,end) is empty it consists
/// of at least one boundary point with the offset 0.
///
virtual index_type map(boundary_type t,Char const *begin,Char 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
};
#else
template<>
class BOOST_LOCALE_DECL boundary_indexing<char> : public std::locale::facet {
public:
boundary_indexing(size_t refs=0) : std::locale::facet(refs)
{
}
virtual index_type map(boundary_type t,char const *begin,char 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
};
template<>
class BOOST_LOCALE_DECL boundary_indexing<wchar_t> : public std::locale::facet {
public:
boundary_indexing(size_t refs=0) : std::locale::facet(refs)
{
}
virtual index_type map(boundary_type t,wchar_t const *begin,wchar_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
};
#ifdef BOOST_HAS_CHAR16_T
template<>
class BOOST_LOCALE_DECL boundary_indexing<char16_t> : public std::locale::facet {
public:
boundary_indexing(size_t refs=0) : std::locale::facet(refs)
{
}
virtual index_type map(boundary_type t,char16_t const *begin,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
#ifdef BOOST_HAS_CHAR32_T
template<>
class BOOST_LOCALE_DECL boundary_indexing<char32_t> : public std::locale::facet {
public:
boundary_indexing(size_t refs=0) : std::locale::facet(refs)
{
}
virtual index_type map(boundary_type t,char32_t const *begin,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
#endif
///
/// @}
///
} // boundary
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,484 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED
#define BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
#include <string>
#include <iosfwd>
#include <iterator>
namespace boost {
namespace locale {
namespace boundary {
/// \cond INTERNAL
namespace details {
template<typename LeftIterator,typename RightIterator>
int compare_text(LeftIterator l_begin,LeftIterator l_end,RightIterator r_begin,RightIterator r_end)
{
typedef LeftIterator left_iterator;
typedef RightIterator right_iterator;
typedef typename std::iterator_traits<left_iterator>::value_type char_type;
typedef std::char_traits<char_type> traits;
while(l_begin!=l_end && r_begin!=r_end) {
char_type lchar = *l_begin++;
char_type rchar = *r_begin++;
if(traits::eq(lchar,rchar))
continue;
if(traits::lt(lchar,rchar))
return -1;
else
return 1;
}
if(l_begin==l_end && r_begin==r_end)
return 0;
if(l_begin==l_end)
return -1;
else
return 1;
}
template<typename Left,typename Right>
int compare_text(Left const &l,Right const &r)
{
return compare_text(l.begin(),l.end(),r.begin(),r.end());
}
template<typename Left,typename Char>
int compare_string(Left const &l,Char const *begin)
{
Char const *end = begin;
while(*end!=0)
end++;
return compare_text(l.begin(),l.end(),begin,end);
}
template<typename Right,typename Char>
int compare_string(Char const *begin,Right const &r)
{
Char const *end = begin;
while(*end!=0)
end++;
return compare_text(begin,end,r.begin(),r.end());
}
}
/// \endcond
///
/// \addtogroup boundary
/// @{
///
/// \brief a segment object that represents a pair of two iterators that define the range where
/// this segment exits and a rule that defines it.
///
/// This type of object is dereferenced by the iterators of segment_index. Using a rule() member function
/// you can get a specific rule this segment was selected with. For example, when you use
/// word boundary analysis, you can check if the specific word contains Kana letters by checking (rule() & \ref word_kana)!=0
/// For a sentence analysis you can check if the sentence is selected because a sentence terminator is found (\ref sentence_term) or
/// there is a line break (\ref sentence_sep).
///
/// This object can be automatically converted to std::basic_string with the same type of character. It is also
/// valid range that has begin() and end() member functions returning iterators on the location of the segment.
///
/// \see
///
/// - \ref segment_index
/// - \ref boundary_point
/// - \ref boundary_point_index
///
template<typename IteratorType>
class segment : public std::pair<IteratorType,IteratorType> {
public:
///
/// The type of the underlying character
///
typedef typename std::iterator_traits<IteratorType>::value_type char_type;
///
/// The type of the string it is converted to
///
typedef std::basic_string<char_type> string_type;
///
/// The value that iterators return - the character itself
///
typedef char_type value_type;
///
/// The iterator that allows to iterate the range
///
typedef IteratorType iterator;
///
/// The iterator that allows to iterate the range
///
typedef IteratorType const_iterator;
///
/// The type that represent a difference between two iterators
///
typedef typename std::iterator_traits<IteratorType>::difference_type difference_type;
///
/// Default constructor
///
segment() {}
///
/// Create a segment using two iterators and a rule that represents this point
///
segment(iterator b,iterator e,rule_type r) :
std::pair<IteratorType,IteratorType>(b,e),
rule_(r)
{
}
///
/// Set the start of the range
///
void begin(iterator const &v)
{
this->first = v;
}
///
/// Set the end of the range
///
void end(iterator const &v)
{
this->second = v;
}
///
/// Get the start of the range
///
IteratorType begin() const
{
return this->first;
}
///
/// Set the end of the range
///
IteratorType end() const
{
return this->second;
}
///
/// Convert the range to a string automatically
///
template <class T, class A>
operator std::basic_string<char_type, T, A> ()const
{
return std::basic_string<char_type, T, A>(this->first, this->second);
}
///
/// Create a string from the range explicitly
///
string_type str() const
{
return string_type(begin(),end());
}
///
/// Get the length of the text chunk
///
size_t length() const
{
return std::distance(begin(),end());
}
///
/// Check if the segment is empty
///
bool empty() const
{
return begin() == end();
}
///
/// Get the rule that is used for selection of this segment.
///
rule_type rule() const
{
return rule_;
}
///
/// Set a rule that is used for segment selection
///
void rule(rule_type r)
{
rule_ = r;
}
// make sure we override std::pair's operator==
/// Compare two segments
bool operator==(segment const &other)
{
return details::compare_text(*this,other) == 0;
}
/// Compare two segments
bool operator!=(segment const &other)
{
return details::compare_text(*this,other) != 0;
}
private:
rule_type rule_;
};
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator==(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) == 0;
}
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator!=(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) != 0;
}
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator<(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) < 0;
}
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator<=(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) <= 0;
}
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator>(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) > 0;
}
/// Compare two segments
template<typename IteratorL,typename IteratorR>
bool operator>=(segment<IteratorL> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) >= 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator==(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) == 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator!=(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) != 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator<(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) < 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator<=(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) <= 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator>(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) > 0;
}
/// Compare string and segment
template<typename CharType,typename Traits,typename Alloc,typename IteratorR>
bool operator>=(std::basic_string<CharType,Traits,Alloc> const &l,segment<IteratorR> const &r)
{
return details::compare_text(l,r) >= 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator==(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) == 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator!=(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) != 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator<(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) < 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator<=(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) <= 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator>(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) > 0;
}
/// Compare string and segment
template<typename Iterator,typename CharType,typename Traits,typename Alloc>
bool operator>=(segment<Iterator> const &l,std::basic_string<CharType,Traits,Alloc> const &r)
{
return details::compare_text(l,r) >= 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator==(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) == 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator!=(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) != 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator<(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) < 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator<=(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) <= 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator>(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) > 0;
}
/// Compare C string and segment
template<typename CharType,typename IteratorR>
bool operator>=(CharType const *l,segment<IteratorR> const &r)
{
return details::compare_string(l,r) >= 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator==(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) == 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator!=(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) != 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator<(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) < 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator<=(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) <= 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator>(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) > 0;
}
/// Compare C string and segment
template<typename Iterator,typename CharType>
bool operator>=(segment<Iterator> const &l,CharType const *r)
{
return details::compare_string(l,r) >= 0;
}
typedef segment<std::string::const_iterator> ssegment; ///< convenience typedef
typedef segment<std::wstring::const_iterator> wssegment; ///< convenience typedef
#ifdef BOOST_HAS_CHAR16_T
typedef segment<std::u16string::const_iterator> u16ssegment;///< convenience typedef
#endif
#ifdef BOOST_HAS_CHAR32_T
typedef segment<std::u32string::const_iterator> u32ssegment;///< convenience typedef
#endif
typedef segment<char const *> csegment; ///< convenience typedef
typedef segment<wchar_t const *> wcsegment; ///< convenience typedef
#ifdef BOOST_HAS_CHAR16_T
typedef segment<char16_t const *> u16csegment; ///< convenience typedef
#endif
#ifdef BOOST_HAS_CHAR32_T
typedef segment<char32_t const *> u32csegment; ///< convenience typedef
#endif
///
/// Write the segment to the stream character by character
///
template<typename CharType,typename TraitsType,typename Iterator>
std::basic_ostream<CharType,TraitsType> &operator<<(
std::basic_ostream<CharType,TraitsType> &out,
segment<Iterator> const &tok)
{
for(Iterator p=tok.begin(),e=tok.end();p!=e;++p)
out << *p;
return out;
}
/// @}
} // boundary
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,136 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_BOUNDARY_TYPES_HPP_INCLUDED
#define BOOST_LOCALE_BOUNDARY_TYPES_HPP_INCLUDED
#include <boost/locale/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/assert.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
namespace boost {
namespace locale {
///
/// \brief This namespase contains all operations required for boundary analysis of text
///
namespace boundary {
///
/// \defgroup boundary Boundary Analysis
///
/// This module contains all operations required for boundary analysis of text: character, word, like and sentence boundaries
///
/// @{
///
///
/// This type describes a possible boundary analysis alternatives.
///
enum boundary_type {
character, ///< Analyse the text for character boundaries
word, ///< Analyse the text for word boundaries
sentence, ///< Analyse the text for Find sentence boundaries
line ///< Analyse the text for positions suitable for line breaks
};
///
/// \brief Flags used with word boundary analysis -- the type of the word, line or sentence boundary found.
///
/// It is a bit-mask that represents various combinations of rules used to select this specific boundary.
///
typedef uint32_t rule_type;
///
/// \anchor bl_boundary_word_rules
/// \name Flags that describe a type of word selected
/// @{
static const rule_type
word_none = 0x0000F, ///< Not a word, like white space or punctuation mark
word_number = 0x000F0, ///< Word that appear to be a number
word_letter = 0x00F00, ///< Word that contains letters, excluding kana and ideographic characters
word_kana = 0x0F000, ///< Word that contains kana characters
word_ideo = 0xF0000, ///< Word that contains ideographic characters
word_any = 0xFFFF0, ///< Any word including numbers, 0 is special flag, equivalent to 15
word_letters = 0xFFF00, ///< Any word, excluding numbers but including letters, kana and ideograms.
word_kana_ideo = 0xFF000, ///< Word that includes kana or ideographic characters
word_mask = 0xFFFFF; ///< Full word mask - select all possible variants
/// @}
///
/// \anchor bl_boundary_line_rules
/// \name Flags that describe a type of line break
/// @{
static const rule_type
line_soft = 0x0F, ///< Soft line break: optional but not required
line_hard = 0xF0, ///< Hard line break: like break is required (as per CR/LF)
line_any = 0xFF, ///< Soft or Hard line break
line_mask = 0xFF; ///< Select all types of line breaks
/// @}
///
/// \anchor bl_boundary_sentence_rules
/// \name Flags that describe a type of sentence break
///
/// @{
static const rule_type
sentence_term = 0x0F, ///< \brief The sentence was terminated with a sentence terminator
/// like ".", "!" possible followed by hard separator like CR, LF, PS
sentence_sep = 0xF0, ///< \brief The sentence does not contain terminator like ".", "!" but ended with hard separator
/// like CR, LF, PS or end of input.
sentence_any = 0xFF, ///< Either first or second sentence break type;.
sentence_mask = 0xFF; ///< Select all sentence breaking points
///@}
///
/// \name Flags that describe a type of character break.
///
/// At this point break iterator does not distinguish different
/// kinds of characters so it is used for consistency.
///@{
static const rule_type
character_any = 0xF, ///< Not in use, just for consistency
character_mask = 0xF; ///< Select all character breaking points
///@}
///
/// This function returns the mask that covers all variants for specific boundary type
///
inline rule_type boundary_rule(boundary_type t)
{
switch(t) {
case character: return character_mask;
case word: return word_mask;
case sentence: return sentence_mask;
case line: return line_mask;
default: return 0;
}
}
///
///@}
///
} // boundary
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

261
test/external/boost/locale/collator.hpp vendored Normal file
View File

@@ -0,0 +1,261 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_COLLATOR_HPP_INCLUDED
#define BOOST_LOCALE_COLLATOR_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
namespace boost {
namespace locale {
class info;
///
/// \defgroup collation Collation
///
/// This module introduces collation related classes
///
/// @{
///
/// \brief a base class that includes collation level flags
///
class collator_base {
public:
///
/// Unicode collation level types
///
typedef enum {
primary = 0, ///< 1st collation level: base letters
secondary = 1, ///< 2nd collation level: letters and accents
tertiary = 2, ///< 3rd collation level: letters, accents and case
quaternary = 3, ///< 4th collation level: letters, accents, case and punctuation
identical = 4 ///< identical collation level: include code-point comparison
} level_type;
};
///
/// \brief Collation facet.
///
/// It reimplements standard C++ std::collate,
/// allowing usage of std::locale for direct string comparison
///
template<typename CharType>
class collator :
public std::collate<CharType>,
public collator_base
{
public:
///
/// Type of the underlying character
///
typedef CharType char_type;
///
/// Type of string used with this facet
///
typedef std::basic_string<CharType> string_type;
///
/// Compare two strings in rage [b1,e1), [b2,e2) according using a collation level \a level. Calls do_compare
///
/// Returns -1 if the first of the two strings sorts before the seconds, returns 1 if sorts after and 0 if
/// they considered equal.
///
int compare(level_type level,
char_type const *b1,char_type const *e1,
char_type const *b2,char_type const *e2) const
{
return do_compare(level,b1,e1,b2,e2);
}
///
/// Create a binary string that can be compared to other in order to get collation order. The string is created
/// for text in range [b,e). It is useful for collation of multiple strings for text.
///
/// The transformation follows these rules:
/// \code
/// compare(level,b1,e1,b2,e2) == sign( transform(level,b1,e1).compare(transform(level,b2,e2)) );
/// \endcode
///
/// Calls do_transform
///
string_type transform(level_type level,char_type const *b,char_type const *e) const
{
return do_transform(level,b,e);
}
///
/// Calculate a hash of a text in range [b,e). The value can be used for collation sensitive string comparison.
///
/// If compare(level,b1,e1,b2,e2) == 0 then hash(level,b1,e1) == hash(level,b2,e2)
///
/// Calls do_hash
///
long hash(level_type level,char_type const *b,char_type const *e) const
{
return do_hash(level,b,e);
}
///
/// Compare two strings \a l and \a r using collation level \a level
///
/// Returns -1 if the first of the two strings sorts before the seconds, returns 1 if sorts after and 0 if
/// they considered equal.
///
///
int compare(level_type level,string_type const &l,string_type const &r) const
{
return do_compare(level,l.data(),l.data()+l.size(),r.data(),r.data()+r.size());
}
///
/// Calculate a hash that can be used for collation sensitive string comparison of a string \a s
///
/// If compare(level,s1,s2) == 0 then hash(level,s1) == hash(level,s2)
///
long hash(level_type level,string_type const &s) const
{
return do_hash(level,s.data(),s.data()+s.size());
}
///
/// Create a binary string from string \a s, that can be compared to other, useful for collation of multiple
/// strings.
///
/// The transformation follows these rules:
/// \code
/// compare(level,s1,s2) == sign( transform(level,s1).compare(transform(level,s2)) );
/// \endcode
///
string_type transform(level_type level,string_type const &s) const
{
return do_transform(level,s.data(),s.data()+s.size());
}
protected:
///
/// constructor of the collator object
///
collator(size_t refs = 0) : std::collate<CharType>(refs)
{
}
virtual ~collator()
{
}
///
/// This function is used to override default collation function that does not take in account collation level.
/// Uses primary level
///
virtual int do_compare( char_type const *b1,char_type const *e1,
char_type const *b2,char_type const *e2) const
{
return do_compare(identical,b1,e1,b2,e2);
}
///
/// This function is used to override default collation function that does not take in account collation level.
/// Uses primary level
///
virtual string_type do_transform(char_type const *b,char_type const *e) const
{
return do_transform(identical,b,e);
}
///
/// This function is used to override default collation function that does not take in account collation level.
/// Uses primary level
///
virtual long do_hash(char_type const *b,char_type const *e) const
{
return do_hash(identical,b,e);
}
///
/// Actual function that performs comparison between the strings. For details see compare member function. Can be overridden.
///
virtual int do_compare( level_type level,
char_type const *b1,char_type const *e1,
char_type const *b2,char_type const *e2) const = 0;
///
/// Actual function that performs transformation. For details see transform member function. Can be overridden.
///
virtual string_type do_transform(level_type level,char_type const *b,char_type const *e) const = 0;
///
/// Actual function that calculates hash. For details see hash member function. Can be overridden.
///
virtual long do_hash(level_type level,char_type const *b,char_type const *e) const = 0;
};
///
/// \brief This class can be used in STL algorithms and containers for comparison of strings
/// with a level other than primary
///
/// For example:
///
/// \code
/// std::map<std::string,std::string,comparator<char,collator_base::secondary> > data;
/// \endcode
///
/// Would create a map the keys of which are sorted using secondary collation level
///
template<typename CharType,collator_base::level_type default_level = collator_base::identical>
struct comparator
{
public:
///
/// Create a comparator class for locale \a l and with collation leval \a level
///
/// \note throws std::bad_cast if l does not have \ref collator facet installed
///
comparator(std::locale const &l=std::locale(),collator_base::level_type level=default_level) :
locale_(l),
level_(level)
{
}
///
/// Compare two strings -- equivalent to return left < right according to collation rules
///
bool operator()(std::basic_string<CharType> const &left,std::basic_string<CharType> const &right) const
{
return std::use_facet<collator<CharType> >(locale_).compare(level_,left,right) < 0;
}
private:
std::locale locale_;
collator_base::level_type level_;
};
///
///@}
///
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
///
/// \example collate.cpp
/// Example of using collation functions
///
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

37
test/external/boost/locale/config.hpp vendored Normal file
View File

@@ -0,0 +1,37 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_CONFIG_HPP_INCLUDED
#define BOOST_LOCALE_CONFIG_HPP_INCLUDED
#include <boost/locale/definitions.hpp>
//
// Automatically link to the correct build variant where possible.
//
#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_LOCALE_NO_LIB) && !defined(BOOST_LOCALE_SOURCE)
//
// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_locale
//
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_LOCALE_DYN_LINK)
# define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:
//
#include <boost/config/auto_link.hpp>
#endif // auto-linking disabled
#endif // boost/locale/config.hpp
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,380 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_CONVERTER_HPP_INCLUDED
#define BOOST_LOCALE_CONVERTER_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
namespace boost {
namespace locale {
///
/// \defgroup convert Text Conversions
///
/// This module provides various function for string manipulation like Unicode normalization, case conversion etc.
/// @{
///
///
/// \brief This class provides base flags for text manipulation. It is used as base for converter facet.
///
class converter_base {
public:
///
/// The flag used for facet - the type of operation to perform
///
typedef enum {
normalization, ///< Apply Unicode normalization on the text
upper_case, ///< Convert text to upper case
lower_case, ///< Convert text to lower case
case_folding, ///< Fold case in the text
title_case ///< Convert text to title case
} conversion_type;
};
template<typename CharType>
class converter;
#ifdef BOOST_LOCALE_DOXYGEN
///
/// \brief The facet that implements text manipulation
///
/// It is used to performs text conversion operations defined by \ref conversion_type. It is specialized
/// for four types of characters \c char, \c wchar_t, \c char16_t, \c char32_t
///
template<typename Char>
class BOOST_LOCALE_DECL converter: public converter_base, public 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 conversion method \a how. Parameter
/// \a flags is used for specification of normalization method like nfd, nfc etc.
///
virtual std::basic_string<Char> convert(conversion_type how,Char const *begin,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
};
#else
template<>
class BOOST_LOCALE_DECL converter<char> : public converter_base, public std::locale::facet {
public:
static std::locale::id id;
converter(size_t refs = 0) : std::locale::facet(refs)
{
}
virtual std::string convert(conversion_type how,char const *begin,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
};
template<>
class BOOST_LOCALE_DECL converter<wchar_t> : public converter_base, public std::locale::facet {
public:
static std::locale::id id;
converter(size_t refs = 0) : std::locale::facet(refs)
{
}
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 BOOST_HAS_CHAR16_T
template<>
class BOOST_LOCALE_DECL converter<char16_t> : public converter_base, public 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 const *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 BOOST_HAS_CHAR32_T
template<>
class BOOST_LOCALE_DECL converter<char32_t> : public converter_base, public 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 const *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
#endif
///
/// The type that defined <a href="http://unicode.org/reports/tr15/#Norm_Forms">normalization form</a>
///
typedef enum {
norm_nfd, ///< Canonical decomposition
norm_nfc, ///< Canonical decomposition followed by canonical composition
norm_nfkd, ///< Compatibility decomposition
norm_nfkc, ///< Compatibility decomposition followed by canonical composition.
norm_default = norm_nfc, ///< Default normalization - canonical decomposition followed by canonical composition
} norm_type;
///
/// Normalize Unicode string \a str according to \ref norm_type "normalization form" \a n
///
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not take
/// in account the locale encoding, because Unicode decomposition and composition are meaningless outside
/// of a Unicode character set.
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> normalize(std::basic_string<CharType> const &str,norm_type n=norm_default,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::normalization,str.data(),str.data() + str.size(),n);
}
///
/// Normalize NUL terminated Unicode string \a str according to \ref norm_type "normalization form" \a n
///
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not take
/// in account the locale encoding, because Unicode decomposition and composition are meaningless outside
/// of a Unicode character set.
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> normalize(CharType const *str,norm_type n=norm_default,std::locale const &loc=std::locale())
{
CharType const *end=str;
while(*end)
end++;
return std::use_facet<converter<CharType> >(loc).convert(converter_base::normalization,str,end,n);
}
///
/// Normalize Unicode string in range [begin,end) according to \ref norm_type "normalization form" \a n
///
/// Note: This function receives only Unicode strings, i.e.: UTF-8, UTF-16 or UTF-32. It does not take
/// in account the locale encoding, because Unicode decomposition and composition are meaningless outside
/// of a Unicode character set.
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> normalize( CharType const *begin,
CharType const *end,
norm_type n=norm_default,
std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::normalization,begin,end,n);
}
///////////////////////////////////////////////////
///
/// Convert a string \a str to upper case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_upper(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::upper_case,str.data(),str.data()+str.size());
}
///
/// Convert a NUL terminated string \a str to upper case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_upper(CharType const *str,std::locale const &loc=std::locale())
{
CharType const *end=str;
while(*end)
end++;
return std::use_facet<converter<CharType> >(loc).convert(converter_base::upper_case,str,end);
}
///
/// Convert a string in range [begin,end) to upper case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_upper(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::upper_case,begin,end);
}
///////////////////////////////////////////////////
///
/// Convert a string \a str to lower case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_lower(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::lower_case,str.data(),str.data()+str.size());
}
///
/// Convert a NUL terminated string \a str to lower case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_lower(CharType const *str,std::locale const &loc=std::locale())
{
CharType const *end=str;
while(*end)
end++;
return std::use_facet<converter<CharType> >(loc).convert(converter_base::lower_case,str,end);
}
///
/// Convert a string in range [begin,end) to lower case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_lower(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::lower_case,begin,end);
}
///////////////////////////////////////////////////
///
/// Convert a string \a str to title case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_title(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::title_case,str.data(),str.data()+str.size());
}
///
/// Convert a NUL terminated string \a str to title case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_title(CharType const *str,std::locale const &loc=std::locale())
{
CharType const *end=str;
while(*end)
end++;
return std::use_facet<converter<CharType> >(loc).convert(converter_base::title_case,str,end);
}
///
/// Convert a string in range [begin,end) to title case according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> to_title(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::title_case,begin,end);
}
///////////////////////////////////////////////////
///
/// Fold case of a string \a str according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> fold_case(std::basic_string<CharType> const &str,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::case_folding,str.data(),str.data()+str.size());
}
///
/// Fold case of a NUL terminated string \a str according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> fold_case(CharType const *str,std::locale const &loc=std::locale())
{
CharType const *end=str;
while(*end)
end++;
return std::use_facet<converter<CharType> >(loc).convert(converter_base::case_folding,str,end);
}
///
/// Fold case of a string in range [begin,end) according to locale \a loc
///
/// \note throws std::bad_cast if loc does not have \ref converter facet installed
///
template<typename CharType>
std::basic_string<CharType> fold_case(CharType const *begin,CharType const *end,std::locale const &loc=std::locale())
{
return std::use_facet<converter<CharType> >(loc).convert(converter_base::case_folding,begin,end);
}
///
///@}
///
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
///
/// \example conversions.cpp
///
/// Example of using various text conversion functions.
///
/// \example wconversions.cpp
///
/// Example of using various text conversion functions with wide strings.
///
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

1150
test/external/boost/locale/date_time.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,263 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
#define BOOST_LOCALE_DATE_TIME_FACET_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <boost/cstdint.hpp>
#include <locale>
namespace boost {
namespace locale {
///
/// \brief Namespace that contains various types for manipulation with dates
///
namespace period {
///
/// \brief This namespace holds a enum of various period types like era, year, month, etc..
///
namespace marks {
/// \brief the type that defines a flag that holds a period identifier
enum period_mark {
invalid, ///< Special invalid value, should not be used directly
era, ///< Era i.e. AC, BC in Gregorian and Julian calendar, range [0,1]
year, ///< Year, it is calendar specific, for example 2011 in Gregorian calendar.
extended_year, ///< Extended year for Gregorian/Julian calendars, where 1 BC == 0, 2 BC == -1.
month, ///< The month of year, calendar 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, in Gregorian [1..366]
day_of_week, ///< Day of week, Sunday=1, Monday=2,..., Saturday=7.
///< Note that that updating this value respects local day of week, so for example,
///< If first day of week is Monday and the current day is Tuesday then setting
///< the value to Sunday (1) would forward the date by 5 days forward and not backward
///< by two days as it could be expected if the numbers were taken as is.
day_of_week_in_month, ///< Original number of the day of the week in month. For example 1st Sunday,
///< 2nd Sunday, etc. in Gregorian [1..5]
day_of_week_local, ///< Local day of week, for example 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 year
week_of_month, ///< The week number within current month
first_day_of_week, ///< First day of week, constant, for example Sunday in US = 1, Monday in France = 2
};
} // marks
///
/// \brief This class holds a type that represents certain period of time like
/// year, hour, second and so on.
///
/// It can be created from either marks::period_mark type or by using shortcuts in period
/// namespace - calling functions like period::year(), period::hour() and so on.
///
/// Basically it represents the same object as enum marks::period_mark but allows to
/// provide save operator overloading that would not collide with casing of enum to
/// numeric values.
///
class period_type {
public:
///
/// Create a period of specific type, default is invalid.
///
period_type(marks::period_mark m = marks::invalid) : mark_(m)
{
}
///
/// Get the value of marks::period_mark it was created with.
///
marks::period_mark mark() const
{
return mark_;
}
///
/// Check if two periods are the same
///
bool operator==(period_type const &other) const
{
return mark()==other.mark();
}
///
/// Check if two periods are different
///
bool operator!=(period_type const &other) const
{
return mark()!=other.mark();
}
private:
marks::period_mark mark_;
};
} // namespace period
///
/// Structure that define POSIX time, seconds and milliseconds
/// since Jan 1, 1970, 00:00 not including leap seconds.
///
struct posix_time {
int64_t seconds; ///< Seconds since epoch
uint32_t nanoseconds; ///< Nanoseconds resolution
};
///
/// This class defines generic calendar class, it is used by date_time and calendar
/// objects internally. It is less useful for end users, but it is build for localization
/// backend implementation
///
class abstract_calendar {
public:
///
/// Type that defines how to fetch the value
///
typedef enum {
absolute_minimum, ///< Absolute possible minimum for the value, for example for day is 1
actual_minimum, ///< Actual minimal value for this period.
greatest_minimum, ///< Maximal minimum value that can be for this period
current, ///< Current value of this period
least_maximum, ///< The last maximal value for this period, For example for Gregorian calendar
///< day it is 28
actual_maximum, ///< Actual maximum, for it can be 28, 29, 30, 31 for day according to current month
absolute_maximum, ///< Maximal value, for Gregorian day it would be 31.
} value_type;
///
/// A way to update the value
///
typedef enum {
move, ///< Change the value up or down effecting others for example 1990-12-31 + 1 day = 1991-01-01
roll, ///< Change the value up or down not effecting others for example 1990-12-31 + 1 day = 1990-12-01
} update_type;
///
/// Information about calendar
///
typedef enum {
is_gregorian, ///< Check if the calendar is Gregorian
is_dst ///< Check if the current time is in daylight time savings
} calendar_option_type;
///
/// Make a polymorphic copy of the calendar
///
virtual abstract_calendar *clone() const = 0;
///
/// Set specific \a value for period \a p, note not all values are settable.
///
/// After call of set_value you may want to call normalize() function to make sure
/// vall periods are updated, if you set sereral fields that are part of single
/// date/time representation you should call set_value several times and then
/// call normalize().
///
/// If normalize() is not called after set_value, the behavior is undefined
///
virtual void set_value(period::marks::period_mark p,int value) = 0;
///
/// Recalculate all periods after setting them, should be called after use of set_value() function.
///
virtual void normalize() = 0;
///
/// Get specific value for period \a p according to a value_type \a v
///
virtual int get_value(period::marks::period_mark p,value_type v) const = 0;
///
/// Set current time point
///
virtual void set_time(posix_time const &p) = 0;
///
/// Get current time point
///
virtual posix_time get_time() const = 0;
///
/// Set option for calendar, for future use
///
virtual void set_option(calendar_option_type opt,int v) = 0;
///
/// Get option for calendar, currently only check if it is Gregorian calendar
///
virtual int get_option(calendar_option_type opt) const = 0;
///
/// Adjust period's \a p value by \a difference items using a update_type \a u.
/// Note: not all values are adjustable
///
virtual void adjust_value(period::marks::period_mark p,update_type u,int difference) = 0;
///
/// Calculate the difference between this calendar and \a other in \a p units
///
virtual int difference(abstract_calendar const *other,period::marks::period_mark p) const = 0;
///
/// Set time zone, empty - use system
///
virtual void set_timezone(std::string const &tz) = 0;
///
/// Get current time zone, empty - system one
///
virtual std::string get_timezone() const = 0;
///
/// Check of two calendars have same rules
///
virtual bool same(abstract_calendar const *other) const = 0;
virtual ~abstract_calendar()
{
}
};
///
/// \brief the facet that generates calendar for specific locale
///
class BOOST_LOCALE_DECL calendar_facet : public std::locale::facet {
public:
///
/// Basic constructor
///
calendar_facet(size_t refs = 0) : std::locale::facet(refs)
{
}
///
/// Create a new calendar that points to current point of time.
///
virtual abstract_calendar *create_calendar() const = 0;
///
/// Locale id (needed to work with std::locale)
///
static std::locale::id id;
};
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,34 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_DEFINITIONS_HPP_INCLUDED
#define BOOST_LOCALE_DEFINITIONS_HPP_INCLUDED
#include <boost/config.hpp>
// Support older ICU versions
#ifndef BOOST_SYMBOL_VISIBLE
# define BOOST_SYMBOL_VISIBLE
#endif
#ifdef BOOST_HAS_DECLSPEC
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_LOCALE_DYN_LINK)
# ifdef BOOST_LOCALE_SOURCE
# define BOOST_LOCALE_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_LOCALE_DECL BOOST_SYMBOL_IMPORT
# endif // BOOST_LOCALE_SOURCE
# endif // DYN_LINK
#endif // BOOST_HAS_DECLSPEC
#ifndef BOOST_LOCALE_DECL
# define BOOST_LOCALE_DECL
#endif
#endif // boost/locale/config.hpp
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

246
test/external/boost/locale/encoding.hpp vendored Normal file
View File

@@ -0,0 +1,246 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_ENCODING_HPP_INCLUDED
#define BOOST_LOCALE_ENCODING_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <boost/locale/info.hpp>
#include <boost/locale/encoding_errors.hpp>
#include <boost/locale/encoding_utf.hpp>
namespace boost {
namespace locale {
///
/// \brief Namespace that contains all functions related to character set conversion
///
namespace conv {
///
/// \defgroup codepage Character conversion functions
///
/// @{
///
/// 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);
///
/// convert UTF text in range [begin,end) to a text encoded with \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
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
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 according to locale \a loc according to policy \a how
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
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).encoding(),how);
}
///
/// convert a string \a text encoded with \a charset to UTF string
///
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,std::string const &charset,method_type how=default_method)
{
return from_utf(text.c_str(),text.c_str()+text.size(),charset,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 &charset,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
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
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
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
template<typename CharType>
std::string from_utf(std::basic_string<CharType> const &text,std::locale const &loc,method_type how=default_method)
{
return from_utf(text.c_str(),text.c_str()+text.size(),loc,how);
}
///
/// Convert a \a text in locale encoding given by \a loc to UTF
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
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
///
/// \note throws std::bad_cast if the loc does not have \ref info facet installed
///
template<typename CharType>
std::string from_utf(CharType const *text,std::locale const &loc,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
///
BOOST_LOCALE_DECL
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 boost::locale::conv::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 boost::locale::conv::between(text.c_str(),text.c_str()+text.size(),to_encoding,from_encoding,how);
}
/// \cond INTERNAL
template<>
BOOST_LOCALE_DECL std::basic_string<char> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
template<>
BOOST_LOCALE_DECL std::string from_utf(char const *begin,char const *end,std::string const &charset,method_type how);
template<>
BOOST_LOCALE_DECL std::basic_string<wchar_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
template<>
BOOST_LOCALE_DECL std::string from_utf(wchar_t const *begin,wchar_t const *end,std::string const &charset,method_type how);
#ifdef BOOST_HAS_CHAR16_T
template<>
BOOST_LOCALE_DECL std::basic_string<char16_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
template<>
BOOST_LOCALE_DECL std::string from_utf(char16_t const *begin,char16_t const *end,std::string const &charset,method_type how);
#endif
#ifdef BOOST_HAS_CHAR32_T
template<>
BOOST_LOCALE_DECL std::basic_string<char32_t> to_utf(char const *begin,char const *end,std::string const &charset,method_type how);
template<>
BOOST_LOCALE_DECL std::string from_utf(char32_t const *begin,char32_t const *end,std::string const &charset,method_type how);
#endif
/// @}
} // conv
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,75 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_ENCODING_ERRORS_HPP_INCLUDED
#define BOOST_LOCALE_ENCODING_ERRORS_HPP_INCLUDED
#include <boost/locale/definitions.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <stdexcept>
namespace boost {
namespace locale {
namespace conv {
///
/// \addtogroup codepage
///
/// @{
///
/// \brief The excepton that is thrown in case of conversion error
///
class BOOST_SYMBOL_VISIBLE conversion_error : public std::runtime_error {
public:
conversion_error() : std::runtime_error("Conversion failed") {}
};
///
/// \brief This exception is thrown in case of use of unsupported
/// or invalid character set
///
class BOOST_SYMBOL_VISIBLE invalid_charset_error : public std::runtime_error {
public:
/// Create an error for charset \a charset
invalid_charset_error(std::string charset) :
std::runtime_error("Invalid or unsupported charset:" + charset)
{
}
};
///
/// enum that defines conversion policy
///
typedef enum {
skip = 0, ///< Skip illegal/unconvertable characters
stop = 1, ///< Stop conversion and throw conversion_error
default_method = skip ///< Default method - skip
} method_type;
/// @}
} // conv
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,93 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
#define BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED
#include <boost/locale/utf.hpp>
#include <boost/locale/encoding_errors.hpp>
#include <iterator>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
namespace boost {
namespace locale {
namespace conv {
///
/// \addtogroup codepage
///
/// @{
///
/// Convert a Unicode text in range [begin,end) to other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(CharIn const *begin,CharIn const *end,method_type how = default_method)
{
std::basic_string<CharOut> result;
result.reserve(end-begin);
typedef std::back_insert_iterator<std::basic_string<CharOut> > inserter_type;
inserter_type inserter(result);
utf::code_point c;
while(begin!=end) {
c=utf::utf_traits<CharIn>::template decode<CharIn const *>(begin,end);
if(c==utf::illegal || c==utf::incomplete) {
if(how==stop)
throw conversion_error();
}
else {
utf::utf_traits<CharOut>::template encode<inserter_type>(c,inserter);
}
}
return result;
}
///
/// Convert a Unicode NUL terminated string \a str other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(CharIn const *str,method_type how = default_method)
{
CharIn const *end = str;
while(*end)
end++;
return utf_to_utf<CharOut,CharIn>(str,end,how);
}
///
/// Convert a Unicode string \a str other Unicode encoding
///
template<typename CharOut,typename CharIn>
std::basic_string<CharOut>
utf_to_utf(std::basic_string<CharIn> const &str,method_type how = default_method)
{
return utf_to_utf<CharOut,CharIn>(str.c_str(),str.c_str()+str.size(),how);
}
/// @}
} // conv
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

515
test/external/boost/locale/format.hpp vendored Normal file
View File

@@ -0,0 +1,515 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_FORMAT_HPP_INCLUDED
#define BOOST_LOCALE_FORMAT_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <boost/locale/message.hpp>
#include <boost/locale/formatting.hpp>
#include <sstream>
namespace boost {
namespace locale {
///
/// \defgroup format Format
///
/// This module provides printf like functionality integrated into iostreams and suitable for localization
///
/// @{
///
/// \cond INTERNAL
namespace details {
template<typename CharType>
struct formattible {
typedef std::basic_ostream<CharType> stream_type;
typedef void (*writer_type)(stream_type &output,void const *ptr);
formattible() :
pointer_(0),
writer_(&formattible::void_write)
{
}
formattible(formattible const &other) :
pointer_(other.pointer_),
writer_(other.writer_)
{
}
formattible const &operator=(formattible const &other)
{
if(this != &other) {
pointer_=other.pointer_;
writer_=other.writer_;
}
return *this;
}
template<typename Type>
formattible(Type const &value)
{
pointer_ = static_cast<void const *>(&value);
writer_ = &write<Type>;
}
template<typename Type>
formattible const &operator=(Type const &other)
{
*this = formattible(other);
return *this;
}
friend stream_type &operator<<(stream_type &out,formattible const &fmt)
{
fmt.writer_(out,fmt.pointer_);
return out;
}
private:
static void void_write(stream_type &output,void const * /*ptr*/)
{
CharType empty_string[1]={0};
output<<empty_string;
}
template<typename Type>
static void write(stream_type &output,void const *ptr)
{
output << *static_cast<Type const *>(ptr);
}
void const *pointer_;
writer_type writer_;
}; // formattible
class BOOST_LOCALE_DECL format_parser {
public:
format_parser(std::ios_base &ios,void *,void (*imbuer)(void *,std::locale const &));
~format_parser();
unsigned get_position();
void set_one_flag(std::string const &key,std::string const &value);
template<typename CharType>
void set_flag_with_str(std::string const &key,std::basic_string<CharType> const &value)
{
if(key=="ftime" || key=="strftime") {
as::strftime(ios_);
ios_info::get(ios_).date_time_pattern(value);
}
}
void restore();
private:
void imbue(std::locale const &);
format_parser(format_parser const &);
void operator=(format_parser const &);
std::ios_base &ios_;
struct data;
std::auto_ptr<data> d;
};
}
/// \endcond
///
/// \brief a printf like class that allows type-safe and locale aware message formatting
///
/// This class creates a formatted message similar to printf or boost::format and receives
/// formatted entries via operator %.
///
/// For example
/// \code
/// cout << format("Hello {1}, you are {2} years old") % name % age << endl;
/// \endcode
///
/// Formatting is enclosed between curly brackets \c { \c } and defined by a comma separated list of flags in the format key[=value]
/// value may also be text included between single quotes \c ' that is used for special purposes where inclusion of non-ASCII
/// text is allowed
///
/// Including of literal \c { and \c } is possible by specifying double brackets \c {{ and \c }} accordingly.
///
///
/// For example:
///
/// \code
/// cout << format("The height of water at {1,time} is {2,num=fixed,precision=3}") % time % height;
/// \endcode
///
/// The special key -- a number without a value defines the position of an input parameter.
/// List of keys:
/// - \c [0-9]+ -- digits, the index of a formatted parameter -- mandatory key.
/// - \c num or \c number -- format a number. Optional values are:
/// - \c hex -- display hexadecimal number
/// - \c oct -- display in octal format
/// - \c sci or \c scientific -- display in scientific format
/// - \c fix or \c fixed -- display in fixed format
/// .
/// For example \c number=sci
/// - \c cur or \c currency -- format currency. Optional values are:
///
/// - \c iso -- display using ISO currency symbol.
/// - \c nat or \c national -- display using national currency symbol.
/// .
/// - \c per or \c percent -- format percent value.
/// - \c date, \c time , \c datetime or \c dt -- format date, time or date and time. Optional values are:
/// - \c s or \c short -- display in short format
/// - \c m or \c medium -- display in medium format.
/// - \c l or \c long -- display in long format.
/// - \c f or \c full -- display in full format.
/// .
/// - \c ftime with string (quoted) parameter -- display as with \c strftime see, \c as::ftime manipulator
/// - \c spell or \c spellout -- spell the number.
/// - \c ord or \c ordinal -- format ordinal number (1st, 2nd... etc)
/// - \c left or \c < -- align to left.
/// - \c right or \c > -- align to right.
/// - \c width or \c w -- set field width (requires parameter).
/// - \c precision or \c p -- set precision (requires parameter).
/// - \c locale -- with parameter -- switch locale for current operation. This command generates locale
/// with formatting facets giving more fine grained control of formatting. For example:
/// \code
/// cout << format("Today {1,date} ({1,date,locale=he_IL.UTF-8@calendar=hebrew,date} Hebrew Date)") % date;
/// \endcode
/// - \c timezone or \c tz -- the name of the timezone to display the time in. For example:\n
/// \code
/// cout << format("Time is: Local {1,time}, ({1,time,tz=EET} Eastern European Time)") % date;
/// \endcode
/// - \c local - display the time in local time
/// - \c gmt - display the time in UTC time scale
/// \code
/// cout << format("Local time is: {1,time,local}, universal time is {1,time,gmt}") % time;
/// \endcode
///
///
/// Invalid formatting strings are slightly ignored. This would prevent from translator
/// to crash the program in unexpected location.
///
template<typename CharType>
class basic_format {
public:
typedef CharType char_type; ///< Underlying character type
typedef basic_message<char_type> message_type; ///< The translation message type
/// \cond INTERNAL
typedef details::formattible<CharType> formattible_type;
/// \endcond
typedef std::basic_string<CharType> string_type; ///< string type for this type of character
typedef std::basic_ostream<CharType> stream_type; ///< output stream type for this type of character
///
/// Create a format class for \a format_string
///
basic_format(string_type format_string) :
format_(format_string),
translate_(false),
parameters_count_(0)
{
}
///
/// Create a format class using message \a trans. The message if translated first according
/// to the rules of target locale and then interpreted as format string
///
basic_format(message_type const &trans) :
message_(trans),
translate_(true),
parameters_count_(0)
{
}
///
/// Add new parameter to format list. The object should be a type
/// with defined expression out << object where \c out is \c std::basic_ostream.
///
template<typename Formattible>
basic_format &operator % (Formattible const &object)
{
add(formattible_type(object));
return *this;
}
///
/// Format a string using a locale \a loc
///
string_type str(std::locale const &loc = std::locale()) const
{
std::basic_ostringstream<CharType> buffer;
buffer.imbue(loc);
write(buffer);
return buffer.str();
}
///
/// write a formatted string to output stream \a out using out's locale
///
void write(stream_type &out) const
{
string_type format;
if(translate_)
format = message_.str(out.getloc(),ios_info::get(out).domain_id());
else
format = format_;
format_output(out,format);
}
private:
class format_guard {
public:
format_guard(details::format_parser &fmt) :
fmt_(&fmt),
restored_(false)
{
}
void restore()
{
if(restored_)
return;
fmt_->restore();
restored_ = true;
}
~format_guard()
{
try {
restore();
}
catch(...) {
}
}
private:
details::format_parser *fmt_;
bool restored_;
};
void format_output(stream_type &out,string_type const &sformat) const
{
char_type obrk='{';
char_type cbrk='}';
char_type eq='=';
char_type comma=',';
char_type quote='\'';
size_t pos = 0;
size_t size=sformat.size();
CharType const *format=sformat.c_str();
while(format[pos]!=0) {
if(format[pos] != obrk) {
if(format[pos]==cbrk && format[pos+1]==cbrk) {
out << cbrk;
pos+=2;
}
else {
out<<format[pos];
pos++;
}
continue;
}
if(pos+1 < size && format[pos+1]==obrk) {
out << obrk;
pos+=2;
continue;
}
pos++;
details::format_parser fmt(out,static_cast<void *>(&out),&basic_format::imbue_locale);
format_guard guard(fmt);
while(pos < size) {
std::string key;
std::string svalue;
string_type value;
bool use_svalue = true;
for(;format[pos];pos++) {
char_type c=format[pos];
if(c==comma || c==eq || c==cbrk)
break;
else {
key+=static_cast<char>(c);
}
}
if(format[pos]==eq) {
pos++;
if(format[pos]==quote) {
pos++;
use_svalue = false;
while(format[pos]) {
if(format[pos]==quote) {
if(format[pos+1]==quote) {
value+=quote;
pos+=2;
}
else {
pos++;
break;
}
}
else {
value+=format[pos];
pos++;
}
}
}
else {
char_type c;
while((c=format[pos])!=0 && c!=comma && c!=cbrk) {
svalue+=static_cast<char>(c);
pos++;
}
}
}
if(use_svalue) {
fmt.set_one_flag(key,svalue);
}
else
fmt.set_flag_with_str(key,value);
if(format[pos]==comma) {
pos++;
continue;
}
else if(format[pos]==cbrk) {
unsigned position = fmt.get_position();
out << get(position);
guard.restore();
pos++;
break;
}
else {
guard.restore();
break;
}
}
}
}
//
// Non-copyable
//
basic_format(basic_format const &other);
void operator=(basic_format const &other);
void add(formattible_type const &param)
{
if(parameters_count_ >= base_params_)
ext_params_.push_back(param);
else
parameters_[parameters_count_] = param;
parameters_count_++;
}
formattible_type get(unsigned id) const
{
if(id >= parameters_count_)
return formattible_type();
else if(id >= base_params_)
return ext_params_[id - base_params_];
else
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;
message_type message_;
string_type format_;
bool translate_;
formattible_type parameters_[base_params_];
unsigned parameters_count_;
std::vector<formattible_type> ext_params_;
};
///
/// Write formatted message to stream.
///
/// This operator actually causes actual text formatting. It uses the locale of \a out stream
///
template<typename CharType>
std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,basic_format<CharType> const &fmt)
{
fmt.write(out);
return out;
}
///
/// Definition of char based format
///
typedef basic_format<char> format;
///
/// Definition of wchar_t based format
///
typedef basic_format<wchar_t> wformat;
#ifdef BOOST_HAS_CHAR16_T
///
/// Definition of char16_t based format
///
typedef basic_format<char16_t> u16format;
#endif
#ifdef BOOST_HAS_CHAR32_T
///
/// Definition of char32_t based format
///
typedef basic_format<char32_t> u32format;
#endif
///
/// @}
///
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
///
/// \example hello.cpp
///
/// Basic example of using various functions provided by this library
///
/// \example whello.cpp
///
/// Basic example of using various functions with wide strings provided by this library
///
///
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,673 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_FORMATTING_HPP_INCLUDED
#define BOOST_LOCALE_FORMATTING_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <boost/cstdint.hpp>
#include <boost/locale/time_zone.hpp>
#include <ostream>
#include <istream>
#include <string>
#include <string.h>
#include <typeinfo>
namespace boost {
namespace locale {
///
/// \brief This namespace holds additional formatting
/// flags that can be set using ios_info.
///
namespace flags {
///
/// Formatting flags, each one of them has corresponding manipulation
/// in namespace \a as
///
typedef enum {
posix = 0,
number = 1,
currency = 2,
percent = 3,
date = 4,
time = 5,
datetime = 6,
strftime = 7,
spellout = 8,
ordinal = 9,
display_flags_mask = 31,
currency_default = 0 << 5,
currency_iso = 1 << 5,
currency_national = 2 << 5,
currency_flags_mask = 3 << 5,
time_default = 0 << 7,
time_short = 1 << 7,
time_medium = 2 << 7,
time_long = 3 << 7,
time_full = 4 << 7,
time_flags_mask = 7 << 7,
date_default = 0 << 10,
date_short = 1 << 10,
date_medium = 2 << 10,
date_long = 3 << 10,
date_full = 4 << 10,
date_flags_mask = 7 << 10,
datetime_flags_mask = date_flags_mask | time_flags_mask
} display_flags_type;
///
/// Special string patters that can be used
/// for text formatting
///
typedef enum {
datetime_pattern, ///< strftime like formatting
time_zone_id ///< time zone name
} pattern_type;
///
/// Special integer values that can be used for formatting
///
typedef enum {
domain_id ///< Domain code - for message formatting
} value_type;
} // flags
///
/// \brief This class holds an external data - beyond existing fmtflags that std::ios_base holds
///
/// You should almost never create this object directly. Instead, you should access it via ios_info::get(stream_object)
/// static member function. It automatically creates default formatting data for that stream
///
class BOOST_LOCALE_DECL ios_info {
public:
/// \cond INTERNAL
ios_info();
ios_info(ios_info const &);
ios_info const &operator=(ios_info const &);
~ios_info();
/// \endcond
///
/// Get ios_info instance for specific stream object
///
static ios_info &get(std::ios_base &ios);
///
/// Set a flags that define a way for format data like number, spell, currency etc.
///
void display_flags(uint64_t flags);
///
/// Set a flags that define how to format currency
///
void currency_flags(uint64_t flags);
///
/// Set a flags that define how to format date
///
void date_flags(uint64_t flags);
///
/// Set a flags that define how to format time
///
void time_flags(uint64_t flags);
///
/// Set a flags that define how to format both date and time
///
void datetime_flags(uint64_t flags);
///
/// Set special message domain identification
///
void domain_id(int);
///
/// Set time zone for formatting dates and time
///
void time_zone(std::string const &);
///
/// Set date/time pattern (strftime like)
///
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());
}
///
/// Get a flags that define a way for format data like number, spell, currency etc.
///
uint64_t display_flags() const;
///
/// Get a flags that define how to format currency
///
uint64_t currency_flags() const;
///
/// Get a flags that define how to format date
///
uint64_t date_flags() const;
///
/// 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 BOOST_LOCALE_DECL string_set {
public:
string_set();
~string_set();
string_set(string_set const &other);
string_set const &operator=(string_set const &other);
void swap(string_set &other);
template<typename Char>
void set(Char const *s)
{
delete [] ptr;
ptr = 0;
type=&typeid(Char);
Char const *end = s;
while(*end!=0) end++;
// if ptr = 0 it does not matter what is value of size
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 used on IO streams
///
namespace as {
///
/// \defgroup manipulators I/O Stream manipulators
///
/// @{
///
///
/// Format values with "POSIX" or "C" locale. Note, if locale was created with additional non-classic locale then
/// These numbers may be localized
///
inline std::ios_base & posix(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::posix);
return ios;
}
///
/// Format a number. Note, unlike standard number formatting, integers would be treated like real numbers when std::fixed or
/// std::scientific manipulators were applied
///
inline std::ios_base & number(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::number);
return ios;
}
///
/// Format currency, number is treated like amount of money
///
inline std::ios_base & currency(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::currency);
return ios;
}
///
/// Format percent, value 0.3 is treated as 30%.
///
inline std::ios_base & percent(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::percent);
return ios;
}
///
/// Format a date, number is treated as POSIX time
///
inline std::ios_base & date(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::date);
return ios;
}
///
/// Format a time, number is treated as POSIX time
///
inline std::ios_base & time(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::time);
return ios;
}
///
/// Format a date and time, number is treated as POSIX time
///
inline std::ios_base & datetime(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::datetime);
return ios;
}
///
/// Create formatted date time, Please note, this manipulator only changes formatting mode,
/// and not format itself, so you are probably looking for ftime manipulator
///
inline std::ios_base & strftime(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::strftime);
return ios;
}
///
/// Spell the number, like "one hundred and ten"
///
inline std::ios_base & spellout(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::spellout);
return ios;
}
///
/// Write an order of the number like 4th.
///
inline std::ios_base & ordinal(std::ios_base & ios)
{
ios_info::get(ios).display_flags(flags::ordinal);
return ios;
}
///
/// Set default currency formatting style -- national, like "$"
///
inline std::ios_base & currency_default(std::ios_base & ios)
{
ios_info::get(ios).currency_flags(flags::currency_default);
return ios;
}
///
/// Set ISO currency formatting style, like "USD", (requires ICU >= 4.2)
///
inline std::ios_base & currency_iso(std::ios_base & ios)
{
ios_info::get(ios).currency_flags(flags::currency_iso);
return ios;
}
///
/// Set national currency formatting style, like "$"
///
inline std::ios_base & currency_national(std::ios_base & ios)
{
ios_info::get(ios).currency_flags(flags::currency_national);
return ios;
}
///
/// set default (medium) time formatting style
///
inline std::ios_base & time_default(std::ios_base & ios)
{
ios_info::get(ios).time_flags(flags::time_default);
return ios;
}
///
/// set short time formatting style
///
inline std::ios_base & time_short(std::ios_base & ios)
{
ios_info::get(ios).time_flags(flags::time_short);
return ios;
}
///
/// set medium time formatting style
///
inline std::ios_base & time_medium(std::ios_base & ios)
{
ios_info::get(ios).time_flags(flags::time_medium);
return ios;
}
///
/// set long time formatting style
///
inline std::ios_base & time_long(std::ios_base & ios)
{
ios_info::get(ios).time_flags(flags::time_long);
return ios;
}
///
/// set full time formatting style
///
inline std::ios_base & time_full(std::ios_base & ios)
{
ios_info::get(ios).time_flags(flags::time_full);
return ios;
}
///
/// set default (medium) date formatting style
///
inline std::ios_base & date_default(std::ios_base & ios)
{
ios_info::get(ios).date_flags(flags::date_default);
return ios;
}
///
/// set short date formatting style
///
inline std::ios_base & date_short(std::ios_base & ios)
{
ios_info::get(ios).date_flags(flags::date_short);
return ios;
}
///
/// set medium date formatting style
///
inline std::ios_base & date_medium(std::ios_base & ios)
{
ios_info::get(ios).date_flags(flags::date_medium);
return ios;
}
///
/// set long date formatting style
///
inline std::ios_base & date_long(std::ios_base & ios)
{
ios_info::get(ios).date_flags(flags::date_long);
return ios;
}
///
/// set full date formatting style
///
inline std::ios_base & date_full(std::ios_base & ios)
{
ios_info::get(ios).date_flags(flags::date_full);
return ios;
}
/// \cond INTERNAL
namespace details {
template<typename CharType>
struct add_ftime {
std::basic_string<CharType> ftime;
void apply(std::basic_ios<CharType> &ios) const
{
ios_info::get(ios).date_time_pattern(ftime);
as::strftime(ios);
}
};
template<typename CharType>
std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,add_ftime<CharType> const &fmt)
{
fmt.apply(out);
return out;
}
template<typename CharType>
std::basic_istream<CharType> &operator>>(std::basic_istream<CharType> &in,add_ftime<CharType> const &fmt)
{
fmt.apply(in);
return in;
}
}
/// \endcond
///
/// Set strftime like formatting string
///
/// Please note, formatting flags are very similar but not exactly the same as flags for C function strftime.
/// Differences: some flags as "%e" do not add blanks to fill text up to two spaces, not all flags supported.
///
/// Flags:
/// - "%a" -- Abbreviated weekday (Sun.)
/// - "%A" -- Full weekday (Sunday)
/// - "%b" -- Abbreviated month (Jan.)
/// - "%B" -- Full month (January)
/// - "%c" -- Locale date-time format. **Note:** prefer using "as::datetime"
/// - "%d" -- Day of Month [01,31]
/// - "%e" -- Day of Month [1,31]
/// - "%h" -- Same as "%b"
/// - "%H" -- 24 clock hour [00,23]
/// - "%I" -- 12 clock hour [01,12]
/// - "%j" -- Day of year [1,366]
/// - "%m" -- Month [01,12]
/// - "%M" -- Minute [00,59]
/// - "%n" -- New Line
/// - "%p" -- AM/PM in locale representation
/// - "%r" -- Time with AM/PM, same as "%I:%M:%S %p"
/// - "%R" -- Same as "%H:%M"
/// - "%S" -- Second [00,61]
/// - "%t" -- Tab character
/// - "%T" -- Same as "%H:%M:%S"
/// - "%x" -- Local date representation. **Note:** prefer using "as::date"
/// - "%X" -- Local time representation. **Note:** prefer using "as::time"
/// - "%y" -- Year [00,99]
/// - "%Y" -- 4 digits year. (2009)
/// - "%Z" -- Time Zone
/// - "%%" -- Percent symbol
///
template<typename CharType>
#ifdef BOOST_LOCALE_DOXYGEN
unspecified_type
#else
details::add_ftime<CharType>
#endif
ftime(std::basic_string<CharType> const &format)
{
details::add_ftime<CharType> fmt;
fmt.ftime=format;
return fmt;
}
///
/// See ftime(std::basic_string<CharType> const &format)
///
template<typename CharType>
#ifdef BOOST_LOCALE_DOXYGEN
unspecified_type
#else
details::add_ftime<CharType>
#endif
ftime(CharType const *format)
{
details::add_ftime<CharType> fmt;
fmt.ftime=format;
return fmt;
}
/// \cond INTERNAL
namespace details {
struct set_timezone {
std::string id;
};
template<typename CharType>
std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,set_timezone const &fmt)
{
ios_info::get(out).time_zone(fmt.id);
return out;
}
template<typename CharType>
std::basic_istream<CharType> &operator>>(std::basic_istream<CharType> &in,set_timezone const &fmt)
{
ios_info::get(in).time_zone(fmt.id);
return in;
}
}
/// \endcond
///
/// Set GMT time zone to stream
///
inline std::ios_base &gmt(std::ios_base &ios)
{
ios_info::get(ios).time_zone("GMT");
return ios;
}
///
/// Set local time zone to stream
///
inline std::ios_base &local_time(std::ios_base &ios)
{
ios_info::get(ios).time_zone(time_zone::global());
return ios;
}
///
/// Set time zone using \a id
///
inline
#ifdef BOOST_LOCALE_DOXYGEN
unspecified_type
#else
details::set_timezone
#endif
time_zone(char const *id)
{
details::set_timezone tz;
tz.id=id;
return tz;
}
///
/// Set time zone using \a id
///
inline
#ifdef BOOST_LOCALE_DOXYGEN
unspecified_type
#else
details::set_timezone
#endif
time_zone(std::string const &id)
{
details::set_timezone tz;
tz.id=id;
return tz;
}
///
/// @}
///
} // as manipulators
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

235
test/external/boost/locale/generator.hpp vendored Normal file
View File

@@ -0,0 +1,235 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_GENERATOR_HPP
#define BOOST_LOCALE_GENERATOR_HPP
#include <boost/locale/config.hpp>
#include <boost/cstdint.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <string>
#include <locale>
#include <memory>
namespace boost {
template<typename Type>
class shared_ptr;
///
/// \brief This is the main namespace that encloses all localization classes
///
namespace locale {
class localization_backend;
class localization_backend_manager;
static const uint32_t nochar_facet = 0; ///< Unspecified character category for character independent facets
static const uint32_t char_facet = 1 << 0; ///< 8-bit character facets
static const uint32_t wchar_t_facet = 1 << 1; ///< wide character facets
static const uint32_t char16_t_facet = 1 << 2; ///< C++0x char16_t facets
static const uint32_t char32_t_facet = 1 << 3; ///< C++0x char32_t facets
static const uint32_t character_first_facet = char_facet; ///< First facet specific for character type
static const uint32_t character_last_facet = char32_t_facet; ///< Last facet specific for character type
static const uint32_t all_characters = 0xFFFF; ///< Special mask -- generate all
typedef uint32_t character_facet_type; ///<type that specifies the character type that locales can be generated for
static const uint32_t convert_facet = 1 << 0; ///< Generate conversion facets
static const uint32_t collation_facet = 1 << 1; ///< Generate collation facets
static const uint32_t formatting_facet= 1 << 2; ///< Generate numbers, currency, date-time formatting facets
static const uint32_t parsing_facet = 1 << 3; ///< Generate numbers, currency, date-time formatting facets
static const uint32_t message_facet = 1 << 4; ///< Generate message facets
static const uint32_t codepage_facet = 1 << 5; ///< Generate character set conversion facets (derived from std::codecvt)
static const uint32_t boundary_facet = 1 << 6; ///< Generate boundary analysis facet
static const uint32_t per_character_facet_first = convert_facet; ///< First facet specific for character
static const uint32_t per_character_facet_last = boundary_facet; ///< Last facet specific for character
static const uint32_t calendar_facet = 1 << 16; ///< Generate boundary analysis facet
static const uint32_t information_facet = 1 << 17; ///< Generate general locale information facet
static const uint32_t non_character_facet_first = calendar_facet; ///< First character independent facet
static const uint32_t non_character_facet_last = information_facet;///< Last character independent facet
static const uint32_t all_categories = 0xFFFFFFFFu; ///< Generate all of them
typedef uint32_t locale_category_type; ///< a type used for more fine grained generation of facets
///
/// \brief the major class used for locale generation
///
/// This class is used for specification of all parameters required for locale generation and
/// caching. This class const member functions are thread safe if locale class implementation is thread safe.
///
class BOOST_LOCALE_DECL generator {
public:
///
/// Create new generator using global localization_backend_manager
///
generator();
///
/// Create new generator using specific localization_backend_manager
///
generator(localization_backend_manager const &);
~generator();
///
/// Set types of facets that should be generated, default all
///
void categories(locale_category_type cats);
///
/// Get types of facets that should be generated, default all
///
locale_category_type categories() const;
///
/// Set the characters type for which the facets should be generated, default all supported
///
void characters(character_facet_type chars);
///
/// Get the characters type for which the facets should be generated, default all supported
///
character_facet_type characters() const;
///
/// Add a new domain of messages that would be generated. It should be set in order to enable
/// messages support.
///
/// Messages domain has following format: "name" or "name/encoding"
/// where name is the base name of the "mo" file where the catalog is stored
/// without ".mo" extension. For example for file \c /usr/share/locale/he/LC_MESSAGES/blog.mo
/// it would be \c blog.
///
/// You can optionally specify the encoding of the keys in the sources by adding "/encoding_name"
/// For example blog/cp1255.
///
/// If not defined all keys are assumed to be UTF-8 encoded.
///
/// \note When you select a domain for the program using dgettext or message API, you
/// do not specify the encoding part. So for example if the provided
/// domain name was "blog/windows-1255" then for translation
/// you should use dgettext("blog","Hello")
///
///
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.
/// If the domain \a domain is not added yet it is added.
///
void set_default_messages_domain(std::string const &domain);
///
/// Remove all added domains from the list
///
void clear_domains();
///
/// Add a search path where dictionaries are looked in.
///
/// \note
///
/// - Under the Windows platform the path is treated as a path in the locale's encoding so
/// if you create locale "en_US.windows-1251" then path would be treated as cp1255,
/// and if it is en_US.UTF-8 it is treated as UTF-8. File name is always opened with
/// a wide file name as wide file names are the native file name on Windows.
///
/// - Under POSIX platforms all paths passed as-is regardless of encoding as narrow
/// encodings are the native encodings for POSIX platforms.
///
///
void add_messages_path(std::string const &path);
///
/// Remove all added paths
///
void clear_paths();
///
/// Remove all cached locales
///
void clear_cache();
///
/// Turn locale caching ON
///
void locale_cache_enabled(bool on);
///
/// Get locale cache option
///
bool locale_cache_enabled() const;
///
/// Check if by default ANSI encoding is selected or UTF-8 onces. The default is false.
///
bool use_ansi_encoding() const;
///
/// Select ANSI encodings as default system encoding rather then UTF-8 by default
/// under Windows.
///
/// The default is the most portable and most powerful encoding, UTF-8, but the user
/// can select "system" one if dealing with legacy applications
///
void use_ansi_encoding(bool enc);
///
/// Generate a locale with id \a id
///
std::locale generate(std::string const &id) const;
///
/// Generate a locale with id \a id. Use \a base as a locale to which all facets are added,
/// instead of std::locale::classic().
///
std::locale generate(std::locale const &base,std::string const &id) const;
///
/// Shortcut to generate(id)
///
std::locale operator()(std::string const &id) const
{
return generate(id);
}
///
/// Set backend specific option
///
void set_option(std::string const &name,std::string const &value);
///
/// Clear backend specific options
///
void clear_options();
private:
void set_all_options(shared_ptr<localization_backend> backend,std::string const &id) const;
generator(generator const &);
void operator=(generator const &);
struct data;
std::auto_ptr<data> d;
};
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,167 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCLAE_GNU_GETTEXT_HPP
#define BOOST_LOCLAE_GNU_GETTEXT_HPP
#include <boost/locale/message.hpp>
#include <boost/function.hpp>
#include <stdexcept>
namespace boost {
namespace locale {
/// \addtogroup message
/// @{
///
/// \brief This namespace holds classes that provide GNU Gettext message catalogs support.
///
namespace gnu_gettext {
///
/// \brief This structure holds all information required for creating gnu-gettext message catalogs,
///
/// The user is expected to set its parameters to load these catalogs correctly. This structure
/// also allows providing functions for charset conversion. Note, you need to provide them,
/// so this structure is not useful for wide characters without subclassing and it will also
/// ignore gettext catalogs that use a charset different from \a encoding.
///
struct messages_info {
messages_info() :
language("C"),
locale_category("LC_MESSAGES")
{
}
std::string language; ///< The language we load the catalog for, like "ru", "en", "de"
std::string country; ///< The country we load the catalog for, like "US", "IL"
std::string variant; ///< Language variant, like "euro" so it would look for catalog like de_DE\@euro
std::string encoding; ///< Required target charset encoding. Ignored for wide characters.
///< For narrow, should specify the correct encoding required for this catalog
std::string locale_category; ///< Locale category, is set by default to LC_MESSAGES, but may be changed
///
/// \brief This type represents GNU Gettext domain name for the messages.
///
/// It consists of two parameters:
///
/// - name - the name of the domain - used for opening the file name
/// - encoding - the encoding of the keys in the sources, default - UTF-8
///
struct domain {
std::string name; ///< The name of the domain
std::string encoding; ///< The character encoding for the domain
domain() {}
///
/// Create a domain object from the name that can hold an encoding after symbol "/"
/// such that if n is "hello/cp1255" then the name would be "hello" and "encoding" would
/// be "cp1255" and if n is "hello" then the name would be the same but encoding would be
/// "UTF-8"
///
domain(std::string const &n)
{
size_t pos = n.find("/");
if(pos==std::string::npos) {
name = n;
encoding = "UTF-8";
}
else {
name = n.substr(0,pos);
encoding = n.substr(pos+1);
}
}
///
/// Check whether two objects are equivalent, only names are compared, encoding is ignored
///
bool operator==(domain const &other) const
{
return name==other.name;
}
///
/// Check whether two objects are distinct, only names are compared, encoding is ignored
///
bool operator!=(domain const &other) const
{
return !(*this==other);
}
};
typedef std::vector<domain> domains_type; ///< Type that defines a list of domains that are loaded
///< The first one is the default one
domains_type domains; ///< Message domains - application name, like my_app. So files named my_app.mo
///< would be loaded
std::vector<std::string> paths; ///< Paths to search files in. Under MS Windows it uses encoding
///< parameter to convert them to wide OS specific paths.
///
/// The callback for custom file system support. This callback should read the file named \a file_name
/// encoded in \a encoding character set into std::vector<char> and return it.
///
/// - If the file does not exist, it should return an empty vector.
/// - If a error occurs during file read it should throw a error.
///
/// \note The user should support only the encodings the locales are created for. So if the user
/// uses only one encoding or the file system is encoding agnostic, he may ignore the \a encoding parameter.
///
typedef function<
std::vector<char>(
std::string const &file_name,
std::string const &encoding
)
> callback_type;
///
/// The callback for handling custom file systems, if it is empty, the real OS file-system
/// is being used.
///
callback_type callback;
};
///
/// Create a message_format facet using GNU Gettext catalogs. It uses \a info structure to get
/// information about where to read them from and uses it for character set conversion (if needed)
///
template<typename CharType>
message_format<CharType> *create_messages_facet(messages_info const &info);
/// \cond INTERNAL
template<>
BOOST_LOCALE_DECL message_format<char> *create_messages_facet(messages_info const &info);
template<>
BOOST_LOCALE_DECL message_format<wchar_t> *create_messages_facet(messages_info const &info);
#ifdef BOOST_HAS_CHAR16_T
template<>
BOOST_LOCALE_DECL message_format<char16_t> *create_messages_facet(messages_info const &info);
#endif
#ifdef BOOST_HAS_CHAR32_T
template<>
BOOST_LOCALE_DECL message_format<char32_t> *create_messages_facet(messages_info const &info);
#endif
/// \endcond
} // gnu_gettext
/// @}
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

93
test/external/boost/locale/hold_ptr.hpp vendored Normal file
View File

@@ -0,0 +1,93 @@
//
// Copyright (c) 2010 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_HOLD_PTR_H
#define BOOST_LOCALE_HOLD_PTR_H
namespace boost {
namespace locale {
///
/// \brief a smart pointer similar to std::auto_ptr but it is non-copyable and the
/// underlying object has the same constness as the pointer itself (unlike an ordinary pointer).
///
template<typename T>
class hold_ptr {
hold_ptr(hold_ptr const &other); // non copyable
hold_ptr const &operator=(hold_ptr const &other); // non assignable
public:
///
/// Create new empty pointer
///
hold_ptr() : ptr_(0) {}
///
/// Create a pointer that holds \a v, ownership is transferred to smart pointer
///
explicit hold_ptr(T *v) : ptr_(v) {}
///
/// Destroy smart pointer and the object it owns.
///
~hold_ptr()
{
delete ptr_;
}
///
/// Get a const pointer to the object
///
T const *get() const { return ptr_; }
///
/// Get a mutable pointer to the object
///
T *get() { return ptr_; }
///
/// Get a const reference to the object
///
T const &operator *() const { return *ptr_; }
///
/// Get a mutable reference to the object
///
T &operator *() { return *ptr_; }
///
/// Get a const pointer to the object
///
T const *operator->() const { return ptr_; }
///
/// Get a mutable pointer to the object
///
T *operator->() { return ptr_; }
///
/// Transfer an ownership on the pointer to user
///
T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
///
/// Set new value to pointer, previous object is destroyed, ownership on new object is transferred
///
void reset(T *p=0)
{
if(ptr_) delete ptr_;
ptr_=p;
}
/// Swap two pointers
void swap(hold_ptr &other)
{
T *tmp=other.ptr_;
other.ptr_=ptr_;
ptr_=tmp;
}
private:
T *ptr_;
};
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

125
test/external/boost/locale/info.hpp vendored Normal file
View File

@@ -0,0 +1,125 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_INFO_HPP_INCLUDED
#define BOOST_LOCALE_INFO_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
#include <string>
namespace boost {
namespace locale {
///
/// \brief a facet that holds general information about locale
///
/// This facet should be always created in order to make all Boost.Locale functions work
///
class BOOST_LOCALE_DECL info : public std::locale::facet
{
public:
static std::locale::id id; ///< This member uniquely defines this facet, required by STL
///
/// String information about the locale
///
enum string_propery {
language_property, ///< ISO 639 language id
country_property, ///< ISO 3166 country id
variant_property, ///< Variant for locale
encoding_property, ///< encoding name
name_property ///< locale name
};
///
/// Integer information about locale
///
enum integer_property {
utf8_property ///< Non zero value if uses UTF-8 encoding
};
///
/// Standard facet's constructor
///
info(size_t refs = 0) : std::locale::facet(refs)
{
}
///
/// Get language name
///
std::string language() const
{
return get_string_property(language_property);
}
///
/// Get country name
///
std::string country() const
{
return get_string_property(country_property);
}
///
/// Get locale variant
///
std::string variant() const
{
return get_string_property(variant_property);
}
///
/// Get encoding
///
std::string encoding() const
{
return get_string_property(encoding_property);
}
///
/// Get the name of the locale, like en_US.UTF-8
///
std::string name() const
{
return get_string_property(name_property);
}
///
/// True if the underlying encoding is UTF-8 (for char streams and strings)
///
bool utf8() const
{
return get_integer_property(utf8_property) != 0;
}
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
std::locale::id& __get_id (void) const { return id; }
#endif
protected:
///
/// Get string property by its id \a v
///
virtual std::string get_string_property(string_propery v) const = 0;
///
/// Get integer property by its id \a v
///
virtual int get_integer_property(integer_property v) const = 0;
};
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,159 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_LOCALIZATION_BACKEND_HPP
#define BOOST_LOCALE_LOCALIZATION_BACKEND_HPP
#include <boost/locale/config.hpp>
#include <boost/locale/generator.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <string>
#include <locale>
#include <vector>
#include <memory>
namespace boost {
namespace locale {
///
/// \brief this class represents a localization backend that can be used for localizing your application.
///
/// Backends are usually registered inside the localization backends manager and allow transparent support
/// of different backends, so a user can switch the backend by simply linking the application to the correct one.
///
/// Backends may support different tuning options, but these are the default options available to the user
/// for all of them
///
/// -# \c locale - the name of the locale in POSIX format like en_US.UTF-8
/// -# \c use_ansi_encoding - select system locale using ANSI codepages rather then UTF-8 under Windows
/// by default
/// -# \c message_path - path to the location of message catalogs (vector of strings)
/// -# \c message_application - the name of applications that use message catalogs (vector of strings)
///
/// Each backend can be installed with a different default priotiry so when you work with two different backends, you
/// can specify priotiry so this backend will be chosen according to their priority.
///
class localization_backend {
localization_backend(localization_backend const &);
void operator=(localization_backend const &);
public:
localization_backend()
{
}
virtual ~localization_backend()
{
}
///
/// Make a polymorphic copy of the backend
///
virtual localization_backend *clone() const = 0;
///
/// Set option for backend, for example "locale" or "encoding"
///
virtual void set_option(std::string const &name,std::string const &value) = 0;
///
/// Clear all options
///
virtual void clear_options() = 0;
///
/// Create a facet for category \a category and character type \a type
///
virtual std::locale install(std::locale const &base,locale_category_type category,character_facet_type type = nochar_facet) = 0;
}; // localization_backend
///
/// \brief Localization backend manager is a class that holds various backend and allows creation
/// of their combination or selection
///
class BOOST_LOCALE_DECL localization_backend_manager {
public:
///
/// New empty localization_backend_manager
///
localization_backend_manager();
///
/// Copy localization_backend_manager
///
localization_backend_manager(localization_backend_manager const &);
///
/// Assign localization_backend_manager
///
localization_backend_manager const &operator=(localization_backend_manager const &);
///
/// Destructor
///
~localization_backend_manager();
///
/// Create new localization backend according to current settings.
///
std::auto_ptr<localization_backend> get() const;
///
/// Add new backend to the manager, each backend should be uniquely defined by its name.
///
/// This library provides: "icu", "posix", "winapi" and "std" backends.
///
void add_backend(std::string const &name,std::auto_ptr<localization_backend> backend);
///
/// Clear backend
///
void remove_all_backends();
///
/// Get list of all available backends
///
std::vector<std::string> get_all_backends() const;
///
/// Select specific backend by name for a category \a category. It allows combining different
/// backends for user preferences.
///
void select(std::string const &backend_name,locale_category_type category = all_categories);
///
/// Set new global backend manager, the old one is returned.
///
/// This function is thread safe
///
static localization_backend_manager global(localization_backend_manager const &);
///
/// Get global backend manager
///
/// This function is thread safe
///
static localization_backend_manager global();
private:
class impl;
std::auto_ptr<impl> pimpl_;
};
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

807
test/external/boost/locale/message.hpp vendored Normal file
View File

@@ -0,0 +1,807 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_MESSAGE_HPP_INCLUDED
#define BOOST_LOCALE_MESSAGE_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <locale>
#include <string>
#include <vector>
#include <set>
#include <memory>
#include <boost/locale/formatting.hpp>
namespace boost {
namespace locale {
///
/// \defgroup message Message Formatting (translation)
///
///This module provides message translation functionality, i.e. allow your application to speak native language
///
/// @{
///
/// \cond INTERNAL
template<typename CharType>
struct base_message_format: public std::locale::facet
{
};
/// \endcond
///
/// \brief This facet provides message formatting abilities
///
template<typename CharType>
class message_format : public base_message_format<CharType>
{
public:
///
/// Character type
///
typedef CharType char_type;
///
/// String type
///
typedef std::basic_string<CharType> string_type;
///
/// Default constructor
///
message_format(size_t refs = 0) :
base_message_format<CharType>(refs)
{
}
///
/// This function returns a pointer to the string for a message defined by a \a context
/// and identification string \a id. Both create a single key for message lookup in
/// a domain defined by \a domain_id.
///
/// If \a context is NULL it is not considered to be a part of the key
///
/// If a translated string is found, it is returned, otherwise NULL is returned
///
///
virtual char_type const *get(int domain_id,char_type const *context,char_type const *id) const = 0;
///
/// This function returns a pointer to the string for a plural message defined by a \a context
/// and identification string \a single_id.
///
/// If \a context is NULL it is not considered to be a part of the key
///
/// Both create a single key for message lookup in
/// a domain defined \a domain_id. \a n is used to pick the correct translation string for a specific
/// number.
///
/// If a translated string is found, it is returned, otherwise NULL is returned
///
///
virtual char_type const *get(int domain_id,char_type const *context,char_type const *single_id,int n) const = 0;
///
/// Convert a string that defines \a domain to the integer id used by \a get functions
///
virtual int domain(std::string const &domain) const = 0;
///
/// Convert the string \a msg to target locale's encoding. If \a msg is already
/// in target encoding it would be returned otherwise the converted
/// string is stored in temporary \a buffer and buffer.c_str() is returned.
///
/// Note: for char_type that is char16_t, char32_t and wchar_t it is no-op, returns
/// msg
///
virtual char_type const *convert(char_type const *msg,string_type &buffer) const = 0;
#if defined (__SUNPRO_CC) && defined (_RWSTD_VER)
std::locale::id& __get_id (void) const { return id; }
#endif
protected:
virtual ~message_format()
{
}
};
/// \cond INTERNAL
namespace details {
inline bool is_us_ascii_char(char c)
{
// works for null terminated strings regardless char "signness"
return 0<c && c<0x7F;
}
inline bool is_us_ascii_string(char const *msg)
{
while(*msg) {
if(!is_us_ascii_char(*msg++))
return false;
}
return true;
}
template<typename CharType>
struct string_cast_traits {
static CharType const *cast(CharType const *msg,std::basic_string<CharType> &/*unused*/)
{
return msg;
}
};
template<>
struct string_cast_traits<char> {
static char const *cast(char const *msg,std::string &buffer)
{
if(is_us_ascii_string(msg))
return msg;
buffer.reserve(strlen(msg));
char c;
while((c=*msg++)!=0) {
if(is_us_ascii_char(c))
buffer+=c;
}
return buffer.c_str();
}
};
} // details
/// \endcond
///
/// \brief This class represents a message that can be converted to a specific locale message
///
/// It holds the original ASCII string that is queried in the dictionary when converting to the output string.
/// The created string may be UTF-8, UTF-16, UTF-32 or other 8-bit encoded string according to the target
/// character type and locale encoding.
///
template<typename CharType>
class basic_message {
public:
typedef CharType char_type; ///< The character this message object is used with
typedef std::basic_string<char_type> string_type; ///< The string type this object can be used with
typedef message_format<char_type> facet_type; ///< The type of the facet the messages are fetched with
///
/// Create default empty message
///
basic_message() :
n_(0),
c_id_(0),
c_context_(0),
c_plural_(0)
{
}
///
/// Create a simple message from 0 terminated string. The string should exist
/// until the message is destroyed. Generally useful with static constant strings
///
explicit basic_message(char_type const *id) :
n_(0),
c_id_(id),
c_context_(0),
c_plural_(0)
{
}
///
/// Create a simple plural form message from 0 terminated strings. The strings should exist
/// until the message is destroyed. Generally useful with static constant strings.
///
/// \a n is the number, \a single and \a plural are singular and plural forms of the message
///
explicit basic_message(char_type const *single,char_type const *plural,int n) :
n_(n),
c_id_(single),
c_context_(0),
c_plural_(plural)
{
}
///
/// Create a simple message from 0 terminated strings, with context
/// information. The string should exist
/// until the message is destroyed. Generally useful with static constant strings
///
explicit basic_message(char_type const *context,char_type const *id) :
n_(0),
c_id_(id),
c_context_(context),
c_plural_(0)
{
}
///
/// Create a simple plural form message from 0 terminated strings, with context. The strings should exist
/// until the message is destroyed. Generally useful with static constant strings.
///
/// \a n is the number, \a single and \a plural are singular and plural forms of the message
///
explicit basic_message(char_type const *context,char_type const *single,char_type const *plural,int n) :
n_(n),
c_id_(single),
c_context_(context),
c_plural_(plural)
{
}
///
/// Create a simple message from a string.
///
explicit basic_message(string_type const &id) :
n_(0),
c_id_(0),
c_context_(0),
c_plural_(0),
id_(id)
{
}
///
/// Create a simple plural form message from strings.
///
/// \a n is the number, \a single and \a plural are single and plural forms of the message
///
explicit basic_message(string_type const &single,string_type const &plural,int number) :
n_(number),
c_id_(0),
c_context_(0),
c_plural_(0),
id_(single),
plural_(plural)
{
}
///
/// Create a simple message from a string with context.
///
explicit basic_message(string_type const &context,string_type const &id) :
n_(0),
c_id_(0),
c_context_(0),
c_plural_(0),
id_(id),
context_(context)
{
}
///
/// Create a simple plural form message from strings.
///
/// \a n is the number, \a single and \a plural are single and plural forms of the message
///
explicit basic_message(string_type const &context,string_type const &single,string_type const &plural,int number) :
n_(number),
c_id_(0),
c_context_(0),
c_plural_(0),
id_(single),
context_(context),
plural_(plural)
{
}
///
/// Copy an object
///
basic_message(basic_message const &other) :
n_(other.n_),
c_id_(other.c_id_),
c_context_(other.c_context_),
c_plural_(other.c_plural_),
id_(other.id_),
context_(other.context_),
plural_(other.plural_)
{
}
///
/// Assign other message object to this one
///
basic_message const &operator=(basic_message const &other)
{
if(this==&other) {
return *this;
}
basic_message tmp(other);
swap(tmp);
return *this;
}
///
/// Swap two message objects
///
void swap(basic_message &other)
{
std::swap(n_,other.n_);
std::swap(c_id_,other.c_id_);
std::swap(c_context_,other.c_context_);
std::swap(c_plural_,other.c_plural_);
id_.swap(other.id_);
context_.swap(other.context_);
plural_.swap(other.plural_);
}
///
/// Message class can be explicitly converted to string class
///
operator string_type () const
{
return str();
}
///
/// Translate message to a string in the default global locale, using default domain
///
string_type str() const
{
std::locale loc;
return str(loc,0);
}
///
/// Translate message to a string in the locale \a locale, using default domain
///
string_type str(std::locale const &locale) const
{
return str(locale,0);
}
///
/// Translate message to a string using locale \a locale and message domain \a domain_id
///
string_type str(std::locale const &locale,std::string const &domain_id) const
{
int id=0;
if(std::has_facet<facet_type>(locale))
id=std::use_facet<facet_type>(locale).domain(domain_id);
return str(locale,id);
}
///
/// Translate message to a string using the default locale and message domain \a domain_id
///
string_type str(std::string const &domain_id) const
{
int id=0;
std::locale loc;
if(std::has_facet<facet_type>(loc))
id=std::use_facet<facet_type>(loc).domain(domain_id);
return str(loc,id);
}
///
/// Translate message to a string using locale \a loc and message domain index \a id
///
string_type str(std::locale const &loc,int id) const
{
string_type buffer;
char_type const *ptr = write(loc,id,buffer);
if(ptr == buffer.c_str())
return buffer;
else
buffer = ptr;
return buffer;
}
///
/// Translate message and write to stream \a out, using imbued locale and domain set to the
/// stream
///
void write(std::basic_ostream<char_type> &out) const
{
std::locale const &loc = out.getloc();
int id = ios_info::get(out).domain_id();
string_type buffer;
out << write(loc,id,buffer);
}
private:
char_type const *plural() const
{
if(c_plural_)
return c_plural_;
if(plural_.empty())
return 0;
return plural_.c_str();
}
char_type const *context() const
{
if(c_context_)
return c_context_;
if(context_.empty())
return 0;
return context_.c_str();
}
char_type const *id() const
{
return c_id_ ? c_id_ : id_.c_str();
}
char_type const *write(std::locale const &loc,int domain_id,string_type &buffer) const
{
char_type const *translated = 0;
static const char_type empty_string[1] = {0};
char_type const *id = this->id();
char_type const *context = this->context();
char_type const *plural = this->plural();
if(*id == 0)
return empty_string;
facet_type const *facet = 0;
if(std::has_facet<facet_type>(loc))
facet = &std::use_facet<facet_type>(loc);
if(facet) {
if(!plural) {
translated = facet->get(domain_id,context,id);
}
else {
translated = facet->get(domain_id,context,id,n_);
}
}
if(!translated) {
char_type const *msg = plural ? ( n_ == 1 ? id : plural) : id;
if(facet) {
translated = facet->convert(msg,buffer);
}
else {
translated = details::string_cast_traits<char_type>::cast(msg,buffer);
}
}
return translated;
}
/// members
int n_;
char_type const *c_id_;
char_type const *c_context_;
char_type const *c_plural_;
string_type id_;
string_type context_;
string_type plural_;
};
///
/// Convenience typedef for char
///
typedef basic_message<char> message;
///
/// Convenience typedef for wchar_t
///
typedef basic_message<wchar_t> wmessage;
#ifdef BOOST_HAS_CHAR16_T
///
/// Convenience typedef for char16_t
///
typedef basic_message<char16_t> u16message;
#endif
#ifdef BOOST_HAS_CHAR32_T
///
/// Convenience typedef for char32_t
///
typedef basic_message<char32_t> u32message;
#endif
///
/// Translate message \a msg and write it to stream
///
template<typename CharType>
std::basic_ostream<CharType> &operator<<(std::basic_ostream<CharType> &out,basic_message<CharType> const &msg)
{
msg.write(out);
return out;
}
///
/// \anchor boost_locale_translate_family \name Indirect message translation function family
/// @{
///
/// \brief Translate a message, \a msg is not copied
///
template<typename CharType>
inline basic_message<CharType> translate(CharType const *msg)
{
return basic_message<CharType>(msg);
}
///
/// \brief Translate a message in context, \a msg and \a context are not copied
///
template<typename CharType>
inline basic_message<CharType> translate( CharType const *context,
CharType const *msg)
{
return basic_message<CharType>(context,msg);
}
///
/// \brief Translate a plural message form, \a single and \a plural are not copied
///
template<typename CharType>
inline basic_message<CharType> translate( CharType const *single,
CharType const *plural,
int n)
{
return basic_message<CharType>(single,plural,n);
}
///
/// \brief Translate a plural message from in constext, \a context, \a single and \a plural are not copied
///
template<typename CharType>
inline basic_message<CharType> translate( CharType const *context,
CharType const *single,
CharType const *plural,
int n)
{
return basic_message<CharType>(context,single,plural,n);
}
///
/// \brief Translate a message, \a msg is copied
///
template<typename CharType>
inline basic_message<CharType> translate(std::basic_string<CharType> const &msg)
{
return basic_message<CharType>(msg);
}
///
/// \brief Translate a message in context,\a context and \a msg is copied
///
template<typename CharType>
inline basic_message<CharType> translate( std::basic_string<CharType> const &context,
std::basic_string<CharType> const &msg)
{
return basic_message<CharType>(context,msg);
}
///
/// \brief Translate a plural message form in constext, \a context, \a single and \a plural are copied
///
template<typename CharType>
inline basic_message<CharType> translate( std::basic_string<CharType> const &context,
std::basic_string<CharType> const &single,
std::basic_string<CharType> const &plural,
int n)
{
return basic_message<CharType>(context,single,plural,n);
}
///
/// \brief Translate a plural message form, \a single and \a plural are copied
///
template<typename CharType>
inline basic_message<CharType> translate( std::basic_string<CharType> const &single,
std::basic_string<CharType> const &plural,
int n)
{
return basic_message<CharType>(single,plural,n);
}
/// @}
///
/// \anchor boost_locale_gettext_family \name Direct message translation functions family
///
///
/// Translate message \a id according to locale \a loc
///
template<typename CharType>
std::basic_string<CharType> gettext(CharType const *id,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(id).str(loc);
}
///
/// Translate plural form according to locale \a loc
///
template<typename CharType>
std::basic_string<CharType> ngettext( CharType const *s,
CharType const *p,
int n,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(s,p,n).str(loc);
}
///
/// Translate message \a id according to locale \a loc in domain \a domain
///
template<typename CharType>
std::basic_string<CharType> dgettext( char const *domain,
CharType const *id,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(id).str(loc,domain);
}
///
/// Translate plural form according to locale \a loc in domain \a domain
///
template<typename CharType>
std::basic_string<CharType> dngettext( char const *domain,
CharType const *s,
CharType const *p,
int n,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(s,p,n).str(loc,domain);
}
///
/// Translate message \a id according to locale \a loc in context \a context
///
template<typename CharType>
std::basic_string<CharType> pgettext( CharType const *context,
CharType const *id,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(context,id).str(loc);
}
///
/// Translate plural form according to locale \a loc in context \a context
///
template<typename CharType>
std::basic_string<CharType> npgettext( CharType const *context,
CharType const *s,
CharType const *p,
int n,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(context,s,p,n).str(loc);
}
///
/// Translate message \a id according to locale \a loc in domain \a domain in context \a context
///
template<typename CharType>
std::basic_string<CharType> dpgettext( char const *domain,
CharType const *context,
CharType const *id,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(context,id).str(loc,domain);
}
///
/// Translate plural form according to locale \a loc in domain \a domain in context \a context
///
template<typename CharType>
std::basic_string<CharType> dnpgettext(char const *domain,
CharType const *context,
CharType const *s,
CharType const *p,
int n,
std::locale const &loc=std::locale())
{
return basic_message<CharType>(context,s,p,n).str(loc,domain);
}
///
/// \cond INTERNAL
///
template<>
struct BOOST_LOCALE_DECL base_message_format<char> : public std::locale::facet
{
base_message_format(size_t refs = 0) : std::locale::facet(refs)
{
}
static std::locale::id id;
};
template<>
struct BOOST_LOCALE_DECL base_message_format<wchar_t> : public std::locale::facet
{
base_message_format(size_t refs = 0) : std::locale::facet(refs)
{
}
static std::locale::id id;
};
#ifdef BOOST_HAS_CHAR16_T
template<>
struct BOOST_LOCALE_DECL base_message_format<char16_t> : public std::locale::facet
{
base_message_format(size_t refs = 0) : std::locale::facet(refs)
{
}
static std::locale::id id;
};
#endif
#ifdef BOOST_HAS_CHAR32_T
template<>
struct BOOST_LOCALE_DECL base_message_format<char32_t> : public std::locale::facet
{
base_message_format(size_t refs = 0) : std::locale::facet(refs)
{
}
static std::locale::id id;
};
#endif
/// \endcond
///
/// @}
///
namespace as {
/// \cond INTERNAL
namespace details {
struct set_domain {
std::string domain_id;
};
template<typename CharType>
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);
ios_info::get(out).domain_id(id);
return out;
}
} // details
/// \endcond
///
/// \addtogroup manipulators
///
/// @{
///
/// Manipulator for switching message domain in ostream,
///
/// \note The returned object throws std::bad_cast if the I/O stream does not have \ref message_format facet installed
///
inline
#ifdef BOOST_LOCALE_DOXYGEN
unspecified_type
#else
details::set_domain
#endif
domain(std::string const &id)
{
details::set_domain tmp = { id };
return tmp;
}
/// @}
} // as
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View File

@@ -0,0 +1,54 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_TIME_ZONE_HPP_INCLUDED
#define BOOST_LOCALE_TIME_ZONE_HPP_INCLUDED
#include <boost/locale/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4275 4251 4231 4660)
#endif
#include <string>
namespace boost {
namespace locale {
///
/// \addtogroup date_time
///
/// @{
///
/// \brief namespace that holds functions for operating with global
/// time zone
///
namespace time_zone {
///
/// Get global time zone identifier. If empty, system time zone is used
///
BOOST_LOCALE_DECL std::string global();
///
/// Set global time zone identifier returning previous one. If empty, system time zone is used
///
BOOST_LOCALE_DECL std::string global(std::string const &new_tz);
}
/// @}
} // locale
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

454
test/external/boost/locale/utf.hpp vendored Normal file
View File

@@ -0,0 +1,454 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_UTF_HPP_INCLUDED
#define BOOST_LOCALE_UTF_HPP_INCLUDED
#include <boost/cstdint.hpp>
namespace boost {
namespace locale {
///
/// \brief Namespace that holds basic operations on UTF encoded sequences
///
/// All functions defined in this namespace do not require linking with Boost.Locale library
///
namespace utf {
/// \cond INTERNAL
#ifdef __GNUC__
# define BOOST_LOCALE_LIKELY(x) __builtin_expect((x),1)
# define BOOST_LOCALE_UNLIKELY(x) __builtin_expect((x),0)
#else
# define BOOST_LOCALE_LIKELY(x) (x)
# define BOOST_LOCALE_UNLIKELY(x) (x)
#endif
/// \endcond
///
/// \brief The integral type type that can hold a Unicode code point
///
typedef uint32_t code_point;
///
/// \brief Special constant that defines illegal code point
///
static const code_point illegal = 0xFFFFFFFFu;
///
/// \brief Special constant that defines incomplete code point
///
static const code_point incomplete = 0xFFFFFFFEu;
///
/// \brief the function checks if \a v is a valid code point
///
inline bool is_valid_codepoint(code_point v)
{
if(v>0x10FFFF)
return false;
if(0xD800 <=v && v<= 0xDFFF) // surragates
return false;
return true;
}
#ifdef BOOST_LOCALE_DOXYGEN
///
/// \brief UTF Traits class - functions to convert UTF sequences to and from Unicode code points
///
template<typename CharType,int size=sizeof(CharType)>
struct utf_traits {
///
/// The type of the character
///
typedef CharType char_type;
///
/// Read one code point from the range [p,e) and return it.
///
/// - If the sequence that was read is incomplete sequence returns \ref incomplete,
/// - If illegal sequence detected returns \ref illegal
///
/// Requirements
///
/// - Iterator is valid input iterator
///
/// Postconditions
///
/// - p points to the last consumed character
///
template<typename Iterator>
static code_point decode(Iterator &p,Iterator e);
///
/// Maximal width of valid sequence in the code units:
///
/// - UTF-8 - 4
/// - UTF-16 - 2
/// - UTF-32 - 1
///
static const int max_width;
///
/// The width of specific code point in the code units.
///
/// Requirement: value is a valid Unicode code point
/// Returns value in range [1..max_width]
///
static int width(code_point value);
///
/// Get the size of the trail part of variable length encoded sequence.
///
/// Returns -1 if C is not valid lead character
///
static int trail_length(char_type c);
///
/// Returns true if c is trail code unit, always false for UTF-32
///
static bool is_trail(char_type c);
///
/// Returns true if c is lead code unit, always true of UTF-32
///
static bool is_lead(char_type c);
///
/// Convert valid Unicode code point \a value to the UTF sequence.
///
/// Requirements:
///
/// - \a value is valid code point
/// - \a out is an output iterator should be able to accept at least width(value) units
///
/// Returns the iterator past the last written code unit.
///
template<typename Iterator>
static Iterator encode(code_point value,Iterator out);
///
/// Decodes valid UTF sequence that is pointed by p into code point.
///
/// If the sequence is invalid or points to end the behavior is undefined
///
template<typename Iterator>
static code_point decode_valid(Iterator &p);
};
#else
template<typename CharType,int size=sizeof(CharType)>
struct utf_traits;
template<typename CharType>
struct utf_traits<CharType,1> {
typedef CharType char_type;
static int trail_length(char_type ci)
{
unsigned char c = ci;
if(c < 128)
return 0;
if(BOOST_LOCALE_UNLIKELY(c < 194))
return -1;
if(c < 224)
return 1;
if(c < 240)
return 2;
if(BOOST_LOCALE_LIKELY(c <=244))
return 3;
return -1;
}
static const int max_width = 4;
static int width(code_point value)
{
if(value <=0x7F) {
return 1;
}
else if(value <=0x7FF) {
return 2;
}
else if(BOOST_LOCALE_LIKELY(value <=0xFFFF)) {
return 3;
}
else {
return 4;
}
}
static bool is_trail(char_type ci)
{
unsigned char c=ci;
return (c & 0xC0)==0x80;
}
static bool is_lead(char_type ci)
{
return !is_trail(ci);
}
template<typename Iterator>
static code_point decode(Iterator &p,Iterator e)
{
if(BOOST_LOCALE_UNLIKELY(p==e))
return incomplete;
unsigned char lead = *p++;
// First byte is fully validated here
int trail_size = trail_length(lead);
if(BOOST_LOCALE_UNLIKELY(trail_size < 0))
return illegal;
//
// Ok as only ASCII may be of size = 0
// also optimize for ASCII text
//
if(trail_size == 0)
return lead;
code_point c = lead & ((1<<(6-trail_size))-1);
// Read the rest
unsigned char tmp;
switch(trail_size) {
case 3:
if(BOOST_LOCALE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
c = (c << 6) | ( tmp & 0x3F);
case 2:
if(BOOST_LOCALE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
c = (c << 6) | ( tmp & 0x3F);
case 1:
if(BOOST_LOCALE_UNLIKELY(p==e))
return incomplete;
tmp = *p++;
c = (c << 6) | ( tmp & 0x3F);
}
// Check code point validity: no surrogates and
// valid range
if(BOOST_LOCALE_UNLIKELY(!is_valid_codepoint(c)))
return illegal;
// make sure it is the most compact representation
if(BOOST_LOCALE_UNLIKELY(width(c)!=trail_size + 1))
return illegal;
return c;
}
template<typename Iterator>
static code_point decode_valid(Iterator &p)
{
unsigned char lead = *p++;
if(lead < 192)
return lead;
int trail_size;
if(lead < 224)
trail_size = 1;
else if(BOOST_LOCALE_LIKELY(lead < 240)) // non-BMP rare
trail_size = 2;
else
trail_size = 3;
code_point c = lead & ((1<<(6-trail_size))-1);
switch(trail_size) {
case 3:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
case 2:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
case 1:
c = (c << 6) | ( static_cast<unsigned char>(*p++) & 0x3F);
}
return c;
}
template<typename Iterator>
static Iterator encode(code_point value,Iterator out)
{
if(value <=0x7F) {
*out++ = value;
}
else if(value <=0x7FF) {
*out++=(value >> 6) | 0xC0;
*out++=(value & 0x3F) | 0x80;
}
else if(BOOST_LOCALE_LIKELY(value <=0xFFFF)) {
*out++=(value >> 12) | 0xE0;
*out++=((value >> 6) & 0x3F) | 0x80;
*out++=(value & 0x3F) | 0x80;
}
else {
*out++=(value >> 18) | 0xF0;
*out++=((value >> 12) & 0x3F) | 0x80;
*out++=((value >> 6) & 0x3F) | 0x80;
*out++=(value & 0x3F) | 0x80;
}
return out;
}
}; // utf8
template<typename CharType>
struct utf_traits<CharType,2> {
typedef CharType char_type;
// See RFC 2781
static bool is_first_surrogate(uint16_t x)
{
return 0xD800 <=x && x<= 0xDBFF;
}
static bool is_second_surrogate(uint16_t x)
{
return 0xDC00 <=x && x<= 0xDFFF;
}
static code_point combine_surrogate(uint16_t w1,uint16_t w2)
{
return ((code_point(w1 & 0x3FF) << 10) | (w2 & 0x3FF)) + 0x10000;
}
static int trail_length(char_type c)
{
if(is_first_surrogate(c))
return 1;
if(is_second_surrogate(c))
return -1;
return 0;
}
///
/// Returns true if c is trail code unit, always false for UTF-32
///
static bool is_trail(char_type c)
{
return is_second_surrogate(c);
}
///
/// Returns true if c is lead code unit, always true of UTF-32
///
static bool is_lead(char_type c)
{
return !is_second_surrogate(c);
}
template<typename It>
static code_point decode(It &current,It last)
{
if(BOOST_LOCALE_UNLIKELY(current == last))
return incomplete;
uint16_t w1=*current++;
if(BOOST_LOCALE_LIKELY(w1 < 0xD800 || 0xDFFF < w1)) {
return w1;
}
if(w1 > 0xDBFF)
return illegal;
if(current==last)
return incomplete;
uint16_t w2=*current++;
if(w2 < 0xDC00 || 0xDFFF < w2)
return illegal;
return combine_surrogate(w1,w2);
}
template<typename It>
static code_point decode_valid(It &current)
{
uint16_t w1=*current++;
if(BOOST_LOCALE_LIKELY(w1 < 0xD800 || 0xDFFF < w1)) {
return w1;
}
uint16_t w2=*current++;
return combine_surrogate(w1,w2);
}
static const int max_width = 2;
static int width(code_point u)
{
return u>=0x10000 ? 2 : 1;
}
template<typename It>
static It encode(code_point u,It out)
{
if(BOOST_LOCALE_LIKELY(u<=0xFFFF)) {
*out++ = u;
}
else {
u-=0x10000;
*out++=0xD800 | (u>>10);
*out++=0xDC00 | (u & 0x3FF);
}
return out;
}
}; // utf16;
template<typename CharType>
struct utf_traits<CharType,4> {
typedef CharType char_type;
static int trail_length(char_type c)
{
if(is_valid_codepoint(c))
return 0;
return -1;
}
static bool is_trail(char_type /*c*/)
{
return false;
}
static bool is_lead(char_type /*c*/)
{
return true;
}
template<typename It>
static code_point decode_valid(It &current)
{
return *current++;
}
template<typename It>
static code_point decode(It &current,It last)
{
if(BOOST_LOCALE_UNLIKELY(current == last))
return boost::locale::utf::incomplete;
code_point c=*current++;
if(BOOST_LOCALE_UNLIKELY(!is_valid_codepoint(c)))
return boost::locale::utf::illegal;
return c;
}
static const int max_width = 1;
static int width(code_point /*u*/)
{
return 1;
}
template<typename It>
static It encode(code_point u,It out)
{
*out++ = u;
return out;
}
}; // utf32
#endif
} // utf
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

209
test/external/boost/locale/util.hpp vendored Normal file
View File

@@ -0,0 +1,209 @@
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_LOCALE_UTIL_HPP
#define BOOST_LOCALE_UTIL_HPP
#include <locale>
#include <typeinfo>
#include <boost/cstdint.hpp>
#include <boost/locale/utf.hpp>
#include <boost/locale/generator.hpp>
#include <boost/assert.hpp>
#include <vector>
namespace boost {
namespace locale {
///
/// \brief This namespace provides various utility function useful for Boost.Locale backends
/// implementations
///
namespace util {
///
/// \brief Return default system locale name in POSIX format.
///
/// This function tries to detect the locale using, LC_CTYPE, LC_ALL and LANG environment
/// variables in this order and if all of them unset, in POSIX platforms it returns "C"
///
/// On Windows additionally to check the above environment variables, this function
/// tries to creates locale name from ISO-339 and ISO-3199 country codes defined
/// for user default locale.
/// If \a use_utf8_on_windows is true it sets the encoding to UTF-8, otherwise, if system
/// locale supports ANSI code-page it defines the ANSI encoding like windows-1252, otherwise it fall-backs
/// to UTF-8 encoding if ANSI code-page is not available.
///
BOOST_LOCALE_DECL
std::string get_system_locale(bool use_utf8_on_windows = false);
///
/// \brief Installs information facet to locale in based on locale name \a name
///
/// This function installs boost::locale::info facet into the locale \a in and returns
/// newly created locale.
///
/// Note: all information is based only on parsing of string \a name;
///
/// The name has following format: language[_COUNTRY][.encoding][\@variant]
/// Where language is ISO-639 language code like "en" or "ru", COUNTRY is ISO-3166
/// country identifier like "US" or "RU". the Encoding is a charracter set name
/// like UTF-8 or ISO-8859-1. Variant is backend specific variant like \c euro or
/// calendar=hebrew.
///
/// If some parameters are missing they are specified as blanks, default encoding
/// is assumed to be US-ASCII and missing language is assumed to be "C"
///
BOOST_LOCALE_DECL
std::locale create_info(std::locale const &in,std::string const &name);
///
/// \brief This class represent a simple stateless converter from UCS-4 and to UCS-4 for
/// each single code point
///
/// This class is used for creation of std::codecvt facet for converting utf-16/utf-32 encoding
/// to encoding supported by this converter
///
/// Please note, this converter should be fully stateless. Fully stateless means it should
/// never assume that it is called in any specific order on the text. Even if the
/// encoding itself seems to be stateless like windows-1255 or shift-jis, some
/// encoders (most notably iconv) can actually compose several code-point into one or
/// decompose them in case composite characters are found. So be very careful when implementing
/// these converters for certain character set.
///
class base_converter {
public:
///
/// This value should be returned when an illegal input sequence or code-point is observed:
/// For example if a UCS-32 code-point is in the range reserved for UTF-16 surrogates
/// or an invalid UTF-8 sequence is found
///
static const uint32_t illegal=utf::illegal;
///
/// This value is returned in following cases: The of incomplete input sequence was found or
/// insufficient output buffer was provided so complete output could not be written.
///
static const uint32_t incomplete=utf::incomplete;
virtual ~base_converter()
{
}
///
/// Return the maximal length that one Unicode code-point can be converted to, for example
/// for UTF-8 it is 4, for Shift-JIS it is 2 and ISO-8859-1 is 1
///
virtual int max_len() const
{
return 1;
}
///
/// Returns true if calling the functions from_unicode, to_unicode, and max_len is thread safe.
///
/// Rule of thumb: if this class' implementation uses simple tables that are unchanged
/// or is purely algorithmic like UTF-8 - so it does not share any mutable bit for
/// independent to_unicode, from_unicode calls, you may set it to true, otherwise,
/// for example if you use iconv_t descriptor or UConverter as conversion object return false,
/// and this object will be cloned for each use.
///
virtual bool is_thread_safe() const
{
return false;
}
///
/// Create a polymorphic copy of this object, usually called only if is_thread_safe() return false
///
virtual base_converter *clone() const
{
BOOST_ASSERT(typeid(*this)==typeid(base_converter));
return new base_converter();
}
///
/// Convert a single character starting at begin and ending at most at end to Unicode code-point.
///
/// if valid input sequence found in [\a begin,\a code_point_end) such as \a begin < \a code_point_end && \a code_point_end <= \a end
/// it is converted to its Unicode code point equivalent, \a begin is set to \a code_point_end
///
/// if incomplete input sequence found in [\a begin,\a end), i.e. there my be such \a code_point_end that \a code_point_end > \a end
/// and [\a begin, \a code_point_end) would be valid input sequence, then \a incomplete is returned begin stays unchanged, for example
/// for UTF-8 conversion a *begin = 0xc2, \a begin +1 = \a end is such situation.
///
/// if invalid input sequence found, i.e. there there is a sequence [\a begin, \a code_point_end) such as \a code_point_end <= \a end
/// that is illegal for this encoding, \a illegal is returned and begin stays unchanged. For example if *begin = 0xFF and begin < end
/// for UTF-8, then \a illegal is returned.
///
///
virtual uint32_t to_unicode(char const *&begin,char const *end)
{
if(begin == end)
return incomplete;
unsigned char cp = *begin;
if(cp <= 0x7F) {
begin++;
return cp;
}
return illegal;
}
///
/// Convert a single code-point \a u into encoding and store it in [begin,end) range.
///
/// If u is invalid Unicode code-point, or it can not be mapped correctly to represented character set,
/// \a illegal should be returned
///
/// If u can be converted to a sequence of bytes c1, ... , cN (1<= N <= max_len() ) then
///
/// -# If end - begin >= N, c1, ... cN are written starting at begin and N is returned
/// -# If end - begin < N, incomplete is returned, it is unspecified what would be
/// stored in bytes in range [begin,end)
virtual uint32_t from_unicode(uint32_t u,char *begin,char const *end)
{
if(begin==end)
return incomplete;
if(u >= 0x80)
return illegal;
*begin = static_cast<char>(u);
return 1;
}
};
///
/// This function creates a \a base_converter that can be used for conversion between UTF-8 and
/// unicode code points
///
BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_utf8_converter();
///
/// This function creates a \a base_converter that can be used for conversion between single byte
/// character encodings like ISO-8859-1, koi8-r, windows-1255 and Unicode code points,
///
/// If \a encoding is not supported, empty pointer is returned. You should check if
/// std::auto_ptr<base_converter>::get() != 0
///
BOOST_LOCALE_DECL std::auto_ptr<base_converter> create_simple_converter(std::string const &encoding);
///
/// Install codecvt facet into locale \a in and return new locale that is based on \a in and uses new
/// facet.
///
/// codecvt facet would convert between narrow and wide/char16_t/char32_t encodings using \a cvt converter.
/// If \a cvt is null pointer, always failure conversion would be used that fails on every first input or output.
///
/// Note: the codecvt facet handles both UTF-16 and UTF-32 wide encodings, it knows to break and join
/// Unicode code-points above 0xFFFF to and from surrogate pairs correctly. \a cvt should be unaware
/// of wide encoding type
///
BOOST_LOCALE_DECL
std::locale create_codecvt(std::locale const &in,std::auto_ptr<base_converter> cvt,character_facet_type type);
} // util
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4