7 #ifndef BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED 8 #define BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED 10 #include <boost/locale/config.hpp> 11 #include <boost/locale/util/string.hpp> 18 # pragma warning(push) 19 # pragma warning(disable : 4275 4251 4231 4660) 22 namespace boost {
namespace locale {
namespace boundary {
25 template<
typename LeftIterator,
typename RightIterator>
26 int compare_text(LeftIterator l_begin, LeftIterator l_end, RightIterator r_begin, RightIterator r_end)
28 typedef LeftIterator left_iterator;
29 typedef typename std::iterator_traits<left_iterator>::value_type char_type;
30 typedef std::char_traits<char_type> traits;
31 while(l_begin != l_end && r_begin != r_end) {
32 char_type lchar = *l_begin++;
33 char_type rchar = *r_begin++;
34 if(traits::eq(lchar, rchar))
36 if(traits::lt(lchar, rchar))
41 if(l_begin == l_end && r_begin == r_end)
49 template<
typename Left,
typename Right>
50 int compare_text(
const Left& l,
const Right& r)
52 return compare_text(l.begin(), l.end(), r.begin(), r.end());
55 template<
typename Left,
typename Char>
56 int compare_string(
const Left& l,
const Char* begin)
58 return compare_text(l.begin(), l.end(), begin,
util::str_end(begin));
61 template<
typename Right,
typename Char>
62 int compare_string(
const Char* begin,
const Right& r)
64 return compare_text(begin,
util::str_end(begin), r.begin(), r.end());
90 template<
typename IteratorType>
91 class segment :
public std::pair<IteratorType, IteratorType> {
94 typedef typename std::iterator_traits<IteratorType>::value_type
char_type;
116 IteratorType
begin()
const {
return this->first; }
118 IteratorType
end()
const {
return this->second; }
121 template<
class T,
class A>
122 operator std::basic_string<char_type, T, A>()
const 124 return std::basic_string<char_type, T, A>(this->first, this->second);
153 template<
typename IteratorL,
typename IteratorR>
156 return detail::compare_text(l, r) == 0;
159 template<
typename IteratorL,
typename IteratorR>
162 return detail::compare_text(l, r) != 0;
166 template<
typename IteratorL,
typename IteratorR>
169 return detail::compare_text(l, r) < 0;
172 template<
typename IteratorL,
typename IteratorR>
175 return detail::compare_text(l, r) <= 0;
178 template<
typename IteratorL,
typename IteratorR>
181 return detail::compare_text(l, r) > 0;
184 template<
typename IteratorL,
typename IteratorR>
187 return detail::compare_text(l, r) >= 0;
191 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
194 return detail::compare_text(l, r) == 0;
197 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
200 return detail::compare_text(l, r) != 0;
204 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
207 return detail::compare_text(l, r) < 0;
210 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
213 return detail::compare_text(l, r) <= 0;
216 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
219 return detail::compare_text(l, r) > 0;
222 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
225 return detail::compare_text(l, r) >= 0;
229 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
232 return detail::compare_text(l, r) == 0;
235 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
238 return detail::compare_text(l, r) != 0;
242 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
245 return detail::compare_text(l, r) < 0;
248 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
251 return detail::compare_text(l, r) <= 0;
254 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
257 return detail::compare_text(l, r) > 0;
260 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
263 return detail::compare_text(l, r) >= 0;
267 template<
typename CharType,
typename IteratorR>
270 return detail::compare_string(l, r) == 0;
273 template<
typename CharType,
typename IteratorR>
276 return detail::compare_string(l, r) != 0;
280 template<
typename CharType,
typename IteratorR>
283 return detail::compare_string(l, r) < 0;
286 template<
typename CharType,
typename IteratorR>
289 return detail::compare_string(l, r) <= 0;
292 template<
typename CharType,
typename IteratorR>
295 return detail::compare_string(l, r) > 0;
298 template<
typename CharType,
typename IteratorR>
301 return detail::compare_string(l, r) >= 0;
305 template<
typename Iterator,
typename CharType>
308 return detail::compare_string(l, r) == 0;
311 template<
typename Iterator,
typename CharType>
314 return detail::compare_string(l, r) != 0;
318 template<
typename Iterator,
typename CharType>
321 return detail::compare_string(l, r) < 0;
324 template<
typename Iterator,
typename CharType>
327 return detail::compare_string(l, r) <= 0;
330 template<
typename Iterator,
typename CharType>
333 return detail::compare_string(l, r) > 0;
336 template<
typename Iterator,
typename CharType>
339 return detail::compare_string(l, r) >= 0;
344 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T 347 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T 353 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T 356 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T 361 template<
typename CharType,
typename TraitsType,
typename Iterator>
362 std::basic_ostream<CharType, TraitsType>&
operator<<(std::basic_ostream<CharType, TraitsType>& out,
365 for(Iterator p = tok.
begin(), e = tok.
end(); p != e; ++p)
375 # pragma warning(pop) IteratorType end() const
Set the end of the range.
Definition: segment.hpp:118
std::iterator_traits< IteratorType >::value_type char_type
The type of the underlying character.
Definition: segment.hpp:94
segment(iterator b, iterator e, rule_type r)
Create a segment using two iterators and a rule that represents this point.
Definition: segment.hpp:109
IteratorType begin() const
Get the start of the range.
Definition: segment.hpp:116
bool empty() const
Check if the segment is empty.
Definition: segment.hpp:134
a segment object that represents a pair of two iterators that define the range where this segment exi...
Definition: segment.hpp:91
rule_type rule() const
Get the rule that is used for selection of this segment.
Definition: segment.hpp:137
segment< std::u16string::const_iterator > u16ssegment
convenience typedef
Definition: segment.hpp:345
segment< std::string::const_iterator > ssegment
convenience typedef
Definition: segment.hpp:342
std::basic_string< char_type > string_type
The type of the string it is converted to.
Definition: segment.hpp:96
bool operator>(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:179
bool operator==(const BaseIterator &l, const boundary_point< BaseIterator > &r)
Check if the boundary point r points to same location as an iterator l.
Definition: boundary_point.hpp:88
string_type str() const
Create a string from the range explicitly.
Definition: segment.hpp:128
segment< const char * > csegment
convenience typedef
Definition: segment.hpp:351
bool operator<(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:167
uint32_t rule_type
Flags used with word boundary analysis – the type of the word, line or sentence boundary found.
Definition: types.hpp:40
void rule(rule_type r)
Set a rule that is used for segment selection.
Definition: segment.hpp:139
char_type value_type
The value that iterators return - the character itself.
Definition: segment.hpp:98
size_t length() const
Get the length of the text chunk.
Definition: segment.hpp:131
bool operator>=(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:185
bool operator!=(const BaseIterator &l, const boundary_point< BaseIterator > &r)
Check if the boundary point r points to different location from an iterator l.
Definition: boundary_point.hpp:94
Char * str_end(Char *str)
Return the end of a C-string, i.e. the pointer to the trailing NULL byte.
Definition: string.hpp:15
IteratorType const_iterator
The iterator that allows to iterate the range.
Definition: segment.hpp:102
bool operator==(const segment &other) const
Compare two segments.
Definition: segment.hpp:144
segment()
Default constructor.
Definition: segment.hpp:107
void begin(const iterator &v)
Set the start of the range.
Definition: segment.hpp:111
segment< std::wstring::const_iterator > wssegment
convenience typedef
Definition: segment.hpp:343
segment< std::u32string::const_iterator > u32ssegment
convenience typedef
Definition: segment.hpp:348
bool operator<=(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:173
bool operator!=(const segment &other) const
Compare two segments.
Definition: segment.hpp:146
std::basic_ostream< CharType, TraitsType > & operator<<(std::basic_ostream< CharType, TraitsType > &out, const segment< Iterator > &tok)
Write the segment to the stream character by character.
Definition: segment.hpp:362
IteratorType iterator
The iterator that allows to iterate the range.
Definition: segment.hpp:100
Generate boundary analysis facet.
segment< const wchar_t * > wcsegment
convenience typedef
Definition: segment.hpp:352
segment< const char32_t * > u32csegment
convenience typedef
Definition: segment.hpp:357
std::iterator_traits< IteratorType >::difference_type difference_type
The type that represent a difference between two iterators.
Definition: segment.hpp:104
void end(const iterator &v)
Set the end of the range.
Definition: segment.hpp:113
segment< const char16_t * > u16csegment
convenience typedef
Definition: segment.hpp:354