StringIterator.cpp 645 B

12345678910111213141516171819202122232425
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Utf8View.h>
  7. #include <LibJS/Runtime/GlobalObject.h>
  8. #include <LibJS/Runtime/StringIterator.h>
  9. namespace JS {
  10. NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string)
  11. {
  12. return realm.heap().allocate<StringIterator>(realm, move(string), realm.intrinsics().string_iterator_prototype());
  13. }
  14. StringIterator::StringIterator(String string, Object& prototype)
  15. : Object(ConstructWithPrototypeTag::Tag, prototype)
  16. , m_string(move(string))
  17. , m_iterator(Utf8View(m_string).begin())
  18. {
  19. }
  20. }