diff --git a/unifill/CodePointIter.hx b/unifill/CodePointIter.hx new file mode 100644 index 0000000..cc267ff --- /dev/null +++ b/unifill/CodePointIter.hx @@ -0,0 +1,19 @@ +package unifill; + +class CodePointIter { + var s : String; + var itr : InternalEncodingIter; + + public inline function new(s : String) { + this.s = s; + this.itr = new InternalEncodingIter(s, 0, s.length); + } + + public inline function hasNext() : Bool { + return itr.hasNext(); + } + + public inline function next() : CodePoint { + return cast InternalEncoding.codePointAt(s, itr.next()); + } +} diff --git a/unifill/Unifill.hx b/unifill/Unifill.hx index 41d84ab..2fe2d54 100644 --- a/unifill/Unifill.hx +++ b/unifill/Unifill.hx @@ -110,11 +110,7 @@ class Unifill { Returns an iterator of the code points of String `s`. **/ public static inline function uIterator(s : String) : Iterator { - var itr = new InternalEncodingIter(s, 0, s.length); - return { - hasNext: itr.hasNext, - next: function() return cast InternalEncoding.codePointAt(s, itr.next()) - }; + return new CodePointIter(s); } /**