StringIterator.h 796 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Utf8View.h>
  9. #include <LibJS/Runtime/Object.h>
  10. namespace JS {
  11. class StringIterator final : public Object {
  12. JS_OBJECT(StringIterator, Object);
  13. JS_DECLARE_ALLOCATOR(StringIterator);
  14. public:
  15. static NonnullGCPtr<StringIterator> create(Realm&, String string);
  16. virtual ~StringIterator() override = default;
  17. Utf8CodePointIterator& iterator() { return m_iterator; }
  18. bool done() const { return m_done; }
  19. private:
  20. explicit StringIterator(String string, Object& prototype);
  21. friend class StringIteratorPrototype;
  22. String m_string;
  23. Utf8CodePointIterator m_iterator;
  24. bool m_done { false };
  25. };
  26. }