Revision | f6d5836b3609890a1f0af72c70d4085165495ceb (tree) |
---|---|
Time | 2017-10-27 00:19:09 |
Author | <exeal@user...> |
Added two constructors take kernel.locations.PointProxy in DocumentCharacterIterator class.
@@ -18,6 +18,10 @@ | ||
18 | 18 | namespace kernel { |
19 | 19 | class Document; |
20 | 20 | |
21 | + namespace locations { | |
22 | + struct PointProxy; | |
23 | + } | |
24 | + | |
21 | 25 | class DocumentCharacterIterator : public boost::iterators::iterator_facade< |
22 | 26 | DocumentCharacterIterator, CodePoint, |
23 | 27 | boost::iterators::bidirectional_traversal_tag, const CodePoint, std::ptrdiff_t |
@@ -25,8 +29,10 @@ | ||
25 | 29 | public: |
26 | 30 | DocumentCharacterIterator() BOOST_NOEXCEPT; |
27 | 31 | DocumentCharacterIterator(const Document& document, const Position& position); |
32 | + explicit DocumentCharacterIterator(const locations::PointProxy& point); | |
28 | 33 | DocumentCharacterIterator(const Document& document, const Region& region); |
29 | 34 | DocumentCharacterIterator(const Document& document, const Region& region, const Position& position); |
35 | + DocumentCharacterIterator(const locations::PointProxy& point, const Region& region); | |
30 | 36 | DocumentCharacterIterator(const DocumentCharacterIterator& other) BOOST_NOEXCEPT; |
31 | 37 | |
32 | 38 | /// @name Position |
@@ -10,6 +10,7 @@ | ||
10 | 10 | #include <ascension/corelib/numeric-range-algorithm/encompasses.hpp> |
11 | 11 | #include <ascension/kernel/document.hpp> |
12 | 12 | #include <ascension/kernel/document-character-iterator.hpp> |
13 | +#include <ascension/kernel/point-proxy.hpp> | |
13 | 14 | |
14 | 15 | namespace ascension { |
15 | 16 | namespace kernel { |
@@ -37,7 +38,7 @@ | ||
37 | 38 | * @param document The document to iterate |
38 | 39 | * @param position The position at which the iteration starts |
39 | 40 | * @throw BadPositionException @a position is outside of the @c #region of the @a document |
40 | - * @post &document() == &document | |
41 | + * @post &document() == &document | |
41 | 42 | * @post region() == document.region() |
42 | 43 | * @post tell() == position |
43 | 44 | * @post offset() == 0 |
@@ -49,11 +50,26 @@ | ||
49 | 50 | } |
50 | 51 | |
51 | 52 | /** |
53 | + * Constructor. The iteration area is the @c #region of the document. | |
54 | + * @param point The document to iterate and the position at which the iteration starts | |
55 | + * @throw BadPositionException The given position is outside of the @c #region of the given document | |
56 | + * @post &document() == &document(point) | |
57 | + * @post region() == document(point).region() | |
58 | + * @post tell() == position(point) | |
59 | + * @post offset() == 0 | |
60 | + */ | |
61 | + DocumentCharacterIterator::DocumentCharacterIterator(const locations::PointProxy& point) | |
62 | + : document_(&kernel::document(point)), region_(kernel::document(point).region()), position_(position(point)) { | |
63 | + if(!encompasses(region_, position_)) | |
64 | + throw BadPositionException(position_); | |
65 | + } | |
66 | + | |
67 | + /** | |
52 | 68 | * Constructor. The iteration is started at `*boost#const_begin(region)`. |
53 | 69 | * @param document The document to iterate |
54 | 70 | * @param region The region to iterate |
55 | 71 | * @throw BadRegionException @a region intersects outside of the document |
56 | - * @post &document() == &document | |
72 | + * @post &document() == &document | |
57 | 73 | * @post region() == region |
58 | 74 | * @post tell() == *boost::const_begin(region) |
59 | 75 | * @post offset() == 0 |
@@ -71,7 +87,7 @@ | ||
71 | 87 | * @param position The position at which the iteration starts |
72 | 88 | * @throw BadRegionException @a region intersects outside of the document |
73 | 89 | * @throw BadPositionException @a position is outside of @a region |
74 | - * @post &document() == &document | |
90 | + * @post &document() == &document | |
75 | 91 | * @post region() == region |
76 | 92 | * @post tell() == position |
77 | 93 | * @post offset() == 0 |
@@ -85,6 +101,25 @@ | ||
85 | 101 | } |
86 | 102 | |
87 | 103 | /** |
104 | + * Constructor. | |
105 | + * @param point The document to iterate and the position at which the iteration starts | |
106 | + * @param region The region to iterate | |
107 | + * @throw BadRegionException @a region intersects outside of the document | |
108 | + * @throw BadPositionException The given position is outside of @a region | |
109 | + * @post &document() == &document(point) | |
110 | + * @post region() == region | |
111 | + * @post tell() == position(point) | |
112 | + * @post offset() == 0 | |
113 | + */ | |
114 | + DocumentCharacterIterator::DocumentCharacterIterator(const locations::PointProxy& point, const Region& region) | |
115 | + : document_(&kernel::document(point)), region_(region), position_(position(point)) { | |
116 | + if(!encompasses(document_->region(), region_)) | |
117 | + throw BadRegionException(region_); | |
118 | + else if(!encompasses(region_, position_)) | |
119 | + throw BadPositionException(position_); | |
120 | + } | |
121 | + | |
122 | + /** | |
88 | 123 | * Copy-constructor. |
89 | 124 | * @param other The source object |
90 | 125 | * @post &document() == &other.document() |
@@ -133,14 +168,8 @@ | ||
133 | 168 | const String& s = lineString(); |
134 | 169 | if(kernel::offsetInLine(tell()) == s.length()) |
135 | 170 | return text::LINE_SEPARATOR; |
136 | - else { | |
137 | - const auto p(std::begin(s) + offsetInLine(tell())); | |
138 | - if(line(tell()) == line(*boost::const_end(region()))) { | |
139 | - if(offsetInLine(tell()) + 1 == offsetInLine(*boost::const_end(region()))) | |
140 | - return text::utf::decodeFirst(p, std::next(p)); | |
141 | - } | |
142 | - return text::utf::decodeFirst(p, std::end(s)); | |
143 | - } | |
171 | + else | |
172 | + return text::utf::decodeFirst(std::begin(s) + offsetInLine(tell()), std::end(s)); | |
144 | 173 | } |
145 | 174 | |
146 | 175 | /** |