7#ifndef BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED
8#define BOOST_LOCALE_BOUNDARY_SEGMENT_HPP_INCLUDED
10#include <boost/locale/util/string.hpp>
18# pragma warning(disable : 4275 4251 4231 4660)
21namespace boost {
namespace locale {
namespace boundary {
24 template<
typename LeftIterator,
typename RightIterator>
25 int compare_text(LeftIterator l_begin, LeftIterator l_end, RightIterator r_begin, RightIterator r_end)
27 typedef LeftIterator left_iterator;
28 typedef typename std::iterator_traits<left_iterator>::value_type char_type;
29 typedef std::char_traits<char_type> traits;
30 while(l_begin != l_end && r_begin != r_end) {
31 char_type lchar = *l_begin++;
32 char_type rchar = *r_begin++;
33 if(traits::eq(lchar, rchar))
35 if(traits::lt(lchar, rchar))
40 if(l_begin == l_end && r_begin == r_end)
48 template<
typename Left,
typename Right>
49 int compare_text(
const Left& l,
const Right& r)
51 return compare_text(l.begin(), l.end(), r.begin(), r.end());
54 template<
typename Left,
typename Char>
55 int compare_string(
const Left& l,
const Char* begin)
57 return compare_text(l.begin(), l.end(), begin, util::str_end(begin));
60 template<
typename Right,
typename Char>
61 int compare_string(
const Char* begin,
const Right& r)
63 return compare_text(begin, util::str_end(begin), r.begin(), r.end());
89 template<
typename IteratorType>
90 class segment :
public std::pair<IteratorType, IteratorType> {
93 typedef typename std::iterator_traits<IteratorType>::value_type
char_type;
115 IteratorType
begin()
const {
return this->first; }
117 IteratorType
end()
const {
return this->second; }
120 template<
class T,
class A>
121 operator std::basic_string<char_type, T, A>()
const
123 return std::basic_string<char_type, T, A>(this->first, this->second);
152 template<
typename IteratorL,
typename IteratorR>
155 return detail::compare_text(l, r) == 0;
158 template<
typename IteratorL,
typename IteratorR>
161 return detail::compare_text(l, r) != 0;
165 template<
typename IteratorL,
typename IteratorR>
168 return detail::compare_text(l, r) < 0;
171 template<
typename IteratorL,
typename IteratorR>
174 return detail::compare_text(l, r) <= 0;
177 template<
typename IteratorL,
typename IteratorR>
180 return detail::compare_text(l, r) > 0;
183 template<
typename IteratorL,
typename IteratorR>
186 return detail::compare_text(l, r) >= 0;
190 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
193 return detail::compare_text(l, r) == 0;
196 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
199 return detail::compare_text(l, r) != 0;
203 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
206 return detail::compare_text(l, r) < 0;
209 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
212 return detail::compare_text(l, r) <= 0;
215 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
218 return detail::compare_text(l, r) > 0;
221 template<
typename CharType,
typename Traits,
typename Alloc,
typename IteratorR>
224 return detail::compare_text(l, r) >= 0;
228 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
231 return detail::compare_text(l, r) == 0;
234 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
237 return detail::compare_text(l, r) != 0;
241 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
244 return detail::compare_text(l, r) < 0;
247 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
250 return detail::compare_text(l, r) <= 0;
253 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
256 return detail::compare_text(l, r) > 0;
259 template<
typename Iterator,
typename CharType,
typename Traits,
typename Alloc>
262 return detail::compare_text(l, r) >= 0;
266 template<
typename CharType,
typename IteratorR>
269 return detail::compare_string(l, r) == 0;
272 template<
typename CharType,
typename IteratorR>
275 return detail::compare_string(l, r) != 0;
279 template<
typename CharType,
typename IteratorR>
282 return detail::compare_string(l, r) < 0;
285 template<
typename CharType,
typename IteratorR>
288 return detail::compare_string(l, r) <= 0;
291 template<
typename CharType,
typename IteratorR>
294 return detail::compare_string(l, r) > 0;
297 template<
typename CharType,
typename IteratorR>
300 return detail::compare_string(l, r) >= 0;
304 template<
typename Iterator,
typename CharType>
307 return detail::compare_string(l, r) == 0;
310 template<
typename Iterator,
typename CharType>
313 return detail::compare_string(l, r) != 0;
317 template<
typename Iterator,
typename CharType>
320 return detail::compare_string(l, r) < 0;
323 template<
typename Iterator,
typename CharType>
326 return detail::compare_string(l, r) <= 0;
329 template<
typename Iterator,
typename CharType>
332 return detail::compare_string(l, r) > 0;
335 template<
typename Iterator,
typename CharType>
338 return detail::compare_string(l, r) >= 0;
343#ifndef BOOST_LOCALE_NO_CXX20_STRING8
346#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
349#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
358#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
361#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
366 template<
typename CharType,
typename TraitsType,
typename Iterator>
367 std::basic_ostream<CharType, TraitsType>&
operator<<(std::basic_ostream<CharType, TraitsType>& out,
370 for(
const auto& p : seg)
a segment object that represents a pair of two iterators that define the range where this segment exi...
Definition: segment.hpp:90
IteratorType begin() const
Get the start of the range.
Definition: segment.hpp:115
IteratorType iterator
The iterator that allows to iterate the range.
Definition: segment.hpp:99
void begin(const iterator &v)
Set the start of the range.
Definition: segment.hpp:110
bool operator!=(const segment &other) const
Compare two segments.
Definition: segment.hpp:145
size_t length() const
Get the length of the text chunk.
Definition: segment.hpp:130
void end(const iterator &v)
Set the end of the range.
Definition: segment.hpp:112
segment()
Default constructor.
Definition: segment.hpp:106
std::basic_string< char_type > string_type
The type of the string it is converted to.
Definition: segment.hpp:95
std::iterator_traits< IteratorType >::difference_type difference_type
The type that represent a difference between two iterators.
Definition: segment.hpp:103
IteratorType end() const
Set the end of the range.
Definition: segment.hpp:117
void rule(rule_type r)
Set a rule that is used for segment selection.
Definition: segment.hpp:138
IteratorType const_iterator
The iterator that allows to iterate the range.
Definition: segment.hpp:101
char_type value_type
The value that iterators return - the character itself.
Definition: segment.hpp:97
std::iterator_traits< IteratorType >::value_type char_type
The type of the underlying character.
Definition: segment.hpp:93
bool empty() const
Check if the segment is empty.
Definition: segment.hpp:133
bool operator==(const segment &other) const
Compare two segments.
Definition: segment.hpp:143
segment(iterator b, iterator e, rule_type r)
Create a segment using two iterators and a rule that represents this point.
Definition: segment.hpp:108
rule_type rule() const
Get the rule that is used for selection of this segment.
Definition: segment.hpp:136
string_type str() const
Create a string from the range explicitly.
Definition: segment.hpp:127
bool operator<=(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:172
bool operator<(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:166
uint32_t rule_type
Flags used with word boundary analysis – the type of the word, line or sentence boundary found.
Definition: types.hpp:40
segment< std::u8string::const_iterator > u8ssegment
convenience typedef
Definition: segment.hpp:344
bool operator>=(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:184
segment< std::u16string::const_iterator > u16ssegment
convenience typedef
Definition: segment.hpp:347
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
segment< const wchar_t * > wcsegment
convenience typedef
Definition: segment.hpp:354
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
segment< const char32_t * > u32csegment
convenience typedef
Definition: segment.hpp:362
segment< std::string::const_iterator > ssegment
convenience typedef
Definition: segment.hpp:341
bool operator>(const segment< IteratorL > &l, const segment< IteratorR > &r)
Compare two segments.
Definition: segment.hpp:178
std::basic_ostream< CharType, TraitsType > & operator<<(std::basic_ostream< CharType, TraitsType > &out, const segment< Iterator > &seg)
Write the segment to the stream character by character.
Definition: segment.hpp:367
segment< std::wstring::const_iterator > wssegment
convenience typedef
Definition: segment.hpp:342
segment< const char * > csegment
convenience typedef
Definition: segment.hpp:353
segment< const char16_t * > u16csegment
convenience typedef
Definition: segment.hpp:359
segment< std::u32string::const_iterator > u32ssegment
convenience typedef
Definition: segment.hpp:350
@ boundary
Generate boundary analysis facet.