StringIterator.cpp 683 B

123456789101112131415161718192021222324252627
  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. JS_DEFINE_ALLOCATOR(StringIterator);
  11. NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string)
  12. {
  13. return realm.heap().allocate<StringIterator>(realm, move(string), realm.intrinsics().string_iterator_prototype());
  14. }
  15. StringIterator::StringIterator(String string, Object& prototype)
  16. : Object(ConstructWithPrototypeTag::Tag, prototype)
  17. , m_string(move(string))
  18. , m_iterator(Utf8View(m_string).begin())
  19. {
  20. }
  21. }