Commit MetaInfo

Revisãof6d5836b3609890a1f0af72c70d4085165495ceb (tree)
Hora2017-10-27 00:19:09
Autor <exeal@user...>

Mensagem de Log

Added two constructors take kernel.locations.PointProxy in DocumentCharacterIterator class.

Mudança Sumário

Diff

diff -r a9baf7790833 -r f6d5836b3609 ascension/ascension/kernel/document-character-iterator.hpp
--- a/ascension/ascension/kernel/document-character-iterator.hpp Mon Oct 23 21:05:05 2017 +0900
+++ b/ascension/ascension/kernel/document-character-iterator.hpp Fri Oct 27 00:19:09 2017 +0900
@@ -18,6 +18,10 @@
1818 namespace kernel {
1919 class Document;
2020
21+ namespace locations {
22+ struct PointProxy;
23+ }
24+
2125 class DocumentCharacterIterator : public boost::iterators::iterator_facade<
2226 DocumentCharacterIterator, CodePoint,
2327 boost::iterators::bidirectional_traversal_tag, const CodePoint, std::ptrdiff_t
@@ -25,8 +29,10 @@
2529 public:
2630 DocumentCharacterIterator() BOOST_NOEXCEPT;
2731 DocumentCharacterIterator(const Document& document, const Position& position);
32+ explicit DocumentCharacterIterator(const locations::PointProxy& point);
2833 DocumentCharacterIterator(const Document& document, const Region& region);
2934 DocumentCharacterIterator(const Document& document, const Region& region, const Position& position);
35+ DocumentCharacterIterator(const locations::PointProxy& point, const Region& region);
3036 DocumentCharacterIterator(const DocumentCharacterIterator& other) BOOST_NOEXCEPT;
3137
3238 /// @name Position
diff -r a9baf7790833 -r f6d5836b3609 ascension/src/kernel/document-character-iterator.cpp
--- a/ascension/src/kernel/document-character-iterator.cpp Mon Oct 23 21:05:05 2017 +0900
+++ b/ascension/src/kernel/document-character-iterator.cpp Fri Oct 27 00:19:09 2017 +0900
@@ -10,6 +10,7 @@
1010 #include <ascension/corelib/numeric-range-algorithm/encompasses.hpp>
1111 #include <ascension/kernel/document.hpp>
1212 #include <ascension/kernel/document-character-iterator.hpp>
13+#include <ascension/kernel/point-proxy.hpp>
1314
1415 namespace ascension {
1516 namespace kernel {
@@ -37,7 +38,7 @@
3738 * @param document The document to iterate
3839 * @param position The position at which the iteration starts
3940 * @throw BadPositionException @a position is outside of the @c #region of the @a document
40- * @post &amp;document() == &document
41+ * @post &amp;document() == &amp;document
4142 * @post region() == document.region()
4243 * @post tell() == position
4344 * @post offset() == 0
@@ -49,11 +50,26 @@
4950 }
5051
5152 /**
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 &amp;document() == &amp;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+ /**
5268 * Constructor. The iteration is started at `*boost#const_begin(region)`.
5369 * @param document The document to iterate
5470 * @param region The region to iterate
5571 * @throw BadRegionException @a region intersects outside of the document
56- * @post &amp;document() == &document
72+ * @post &amp;document() == &amp;document
5773 * @post region() == region
5874 * @post tell() == *boost::const_begin(region)
5975 * @post offset() == 0
@@ -71,7 +87,7 @@
7187 * @param position The position at which the iteration starts
7288 * @throw BadRegionException @a region intersects outside of the document
7389 * @throw BadPositionException @a position is outside of @a region
74- * @post &amp;document() == &document
90+ * @post &amp;document() == &amp;document
7591 * @post region() == region
7692 * @post tell() == position
7793 * @post offset() == 0
@@ -85,6 +101,25 @@
85101 }
86102
87103 /**
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 &amp;document() == &amp;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+ /**
88123 * Copy-constructor.
89124 * @param other The source object
90125 * @post &amp;document() == &other.document()
@@ -133,14 +168,8 @@
133168 const String& s = lineString();
134169 if(kernel::offsetInLine(tell()) == s.length())
135170 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));
144173 }
145174
146175 /**
Show on old repository browser