Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <set>
- #include "utils.h"
- inline bool is_vowel(const char c) noexcept{return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';}
- class IterableString{
- const std::string _data;
- class StringIterator{
- const char* const _end;
- const char* _data;
- public:
- StringIterator(const char* begin, const char* end)noexcept: _end(end){_data = begin;}
- friend const StringIterator& operator++(StringIterator& s_it) noexcept{
- s_it._data++;
- while(s_it._data != s_it._end && !is_vowel(*s_it._data)){s_it._data++;}
- return s_it;
- }
- friend const StringIterator operator++(StringIterator& s_it, int) noexcept{
- auto res = s_it;
- s_it._data++;
- while(s_it._data != s_it._end && !is_vowel(*s_it._data)){s_it._data++;}
- return res;
- }
- inline bool operator!=(const StringIterator& s_it)const noexcept{return _data != s_it._data;}
- inline char operator*() const noexcept{return *_data;}
- };
- public:
- IterableString() = default;
- explicit IterableString(std::string str): _data(move(str)){}
- [[nodiscard]] inline auto begin() const noexcept{return StringIterator(_data.data(),_data.data()+_data.size());}
- [[nodiscard]] inline auto end() const noexcept{return StringIterator(_data.data()+_data.size(),_data.data()+_data.size());}
- };
- static void IterableStringTest(){
- LOG("IterableStringTest")
- IterableString a("agbgbgbgbgbb gb gb gbgb gbgbegbgbgbbgb b gbgbg gbgbgbgb gbgb gb bgbgbgbi");
- std::string expected("aei");
- std::string result;
- for(char c: a){result.push_back(c);}
- ASSERT(expected == result)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement