Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2016-06-08 17:36:46 +0300
committerYuri Gorshenin <y@maps.me>2016-06-08 23:29:26 +0300
commit033e4094cb602190ab1a8854e319f8ae42e17580 (patch)
treec89d53b8c161eab6f3b6644cd02e8a8e7c1f0c57 /indexer/string_slice.cpp
parent36bcceb1d559d4e0e400c75400b0b21711c03c58 (diff)
[indexer] StringSet.
Diffstat (limited to 'indexer/string_slice.cpp')
-rw-r--r--indexer/string_slice.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/indexer/string_slice.cpp b/indexer/string_slice.cpp
new file mode 100644
index 0000000000..ed4a881e8e
--- /dev/null
+++ b/indexer/string_slice.cpp
@@ -0,0 +1,70 @@
+#include "indexer/string_slice.hpp"
+
+namespace search
+{
+JoinIterator::JoinIterator(StringSliceBase const & slice, Position position) : m_slice(slice)
+{
+ if (position == Position::Begin)
+ {
+ m_string = 0;
+ m_offset = 0;
+ Normalize();
+ }
+ else
+ {
+ m_string = GetMaxSize();
+ m_offset = 0;
+ }
+}
+
+// static
+JoinIterator JoinIterator::Begin(StringSliceBase const & slice)
+{
+ return JoinIterator(slice, Position::Begin);
+}
+
+// static
+JoinIterator JoinIterator::End(StringSliceBase const & slice)
+{
+ return JoinIterator(slice, Position::End);
+}
+
+JoinIterator & JoinIterator::operator++()
+{
+ ++m_offset;
+ Normalize();
+ return *this;
+}
+
+void JoinIterator::Normalize()
+{
+ while (m_string != GetMaxSize() && m_offset >= GetSize(m_string))
+ {
+ ++m_string;
+ m_offset = 0;
+ }
+}
+
+size_t JoinIterator::GetSize(size_t string) const
+{
+ if (string >= GetMaxSize())
+ return 0;
+ if (string & 1)
+ return 1;
+ return m_slice.Get(string >> 1).size();
+}
+
+strings::UniChar JoinIterator::GetChar(size_t string, size_t offset) const
+{
+ if (string >= GetMaxSize())
+ return 0;
+ if (string & 1)
+ {
+ ASSERT_EQUAL(offset, 0, ());
+ return ' ';
+ }
+ auto const & s = m_slice.Get(string >> 1);
+ ASSERT_LESS(offset, s.size(), ());
+ return s[offset];
+}
+} // namespace search