forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
55
Kha/Tools/macos/std/haxe/iterators/ArrayIterator.hx
Normal file
55
Kha/Tools/macos/std/haxe/iterators/ArrayIterator.hx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C)2005-2018 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator is used only when `Array<T>` is passed to `Iterable<T>`
|
||||
**/
|
||||
class ArrayIterator<T> {
|
||||
final array:Array<T>;
|
||||
var current:Int = 0;
|
||||
|
||||
/**
|
||||
Create a new `ArrayIterator`.
|
||||
**/
|
||||
#if !hl inline #end
|
||||
public function new(array:Array<T>) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
#if !hl inline #end
|
||||
public function hasNext() {
|
||||
return current < array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
#if !hl inline #end
|
||||
public function next() {
|
||||
return array[current++];
|
||||
}
|
||||
}
|
44
Kha/Tools/macos/std/haxe/iterators/ArrayKeyValueIterator.hx
Normal file
44
Kha/Tools/macos/std/haxe/iterators/ArrayKeyValueIterator.hx
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C)2005-2018 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
@:ifFeature("anon_read.keyValueIterator", "dynamic_read.keyValueIterator")
|
||||
class ArrayKeyValueIterator<T> {
|
||||
var current:Int = 0;
|
||||
var array:Array<T>;
|
||||
|
||||
#if !hl inline #end
|
||||
public function new(array:Array<T>) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
#if !hl inline #end
|
||||
public function hasNext():Bool {
|
||||
return current < array.length;
|
||||
}
|
||||
|
||||
#if !hl inline #end
|
||||
public function next():{key:Int,value:T} {
|
||||
return {value:array[current], key:current++};
|
||||
}
|
||||
}
|
52
Kha/Tools/macos/std/haxe/iterators/DynamicAccessIterator.hx
Normal file
52
Kha/Tools/macos/std/haxe/iterators/DynamicAccessIterator.hx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator can be used to iterate over the values of `haxe.DynamicAccess`.
|
||||
**/
|
||||
class DynamicAccessIterator<T> {
|
||||
final access:DynamicAccess<T>;
|
||||
final keys:Array<String>;
|
||||
var index:Int;
|
||||
|
||||
public inline function new(access:DynamicAccess<T>) {
|
||||
this.access = access;
|
||||
this.keys = access.keys();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext():Bool {
|
||||
return index < keys.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
public inline function next():T {
|
||||
return access[keys[index++]];
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This Key/Value iterator can be used to iterate over `haxe.DynamicAccess`.
|
||||
**/
|
||||
class DynamicAccessKeyValueIterator<T> {
|
||||
final access:DynamicAccess<T>;
|
||||
final keys:Array<String>;
|
||||
var index:Int;
|
||||
|
||||
public inline function new(access:DynamicAccess<T>) {
|
||||
this.access = access;
|
||||
this.keys = access.keys();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext():Bool {
|
||||
return index < keys.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
public inline function next():{key:String, value:T} {
|
||||
var key = keys[index++];
|
||||
return {value: (access[key] : T), key: key};
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package haxe.iterators;
|
||||
|
||||
import haxe.ds.HashMap;
|
||||
|
||||
class HashMapKeyValueIterator<K:{function hashCode():Int;}, V> {
|
||||
final map:HashMap<K, V>;
|
||||
final keys:Iterator<K>;
|
||||
|
||||
public inline function new(map:HashMap<K, V>) {
|
||||
this.map = map;
|
||||
this.keys = map.keys();
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext():Bool {
|
||||
return keys.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
public inline function next():{key:K, value:V} {
|
||||
var key = keys.next();
|
||||
return {value: map.get(key), key: key};
|
||||
}
|
||||
}
|
54
Kha/Tools/macos/std/haxe/iterators/MapKeyValueIterator.hx
Normal file
54
Kha/Tools/macos/std/haxe/iterators/MapKeyValueIterator.hx
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
import haxe.ds.IntMap;
|
||||
|
||||
/**
|
||||
This Key/Value iterator can be used to iterate across maps.
|
||||
**/
|
||||
@:ifFeature("anon_read.keyValueIterator", "dynamic_read.keyValueIterator")
|
||||
class MapKeyValueIterator<K, V> {
|
||||
var map:haxe.Constraints.IMap<K, V>;
|
||||
var keys:Iterator<K>;
|
||||
|
||||
public inline function new(map:haxe.Constraints.IMap<K, V>) {
|
||||
this.map = map;
|
||||
this.keys = map.keys();
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext():Bool {
|
||||
return keys.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
public inline function next():{key:K, value:V} {
|
||||
var key = keys.next();
|
||||
return {value: @:nullSafety(Off) (map.get(key) : V), key: key};
|
||||
}
|
||||
}
|
19
Kha/Tools/macos/std/haxe/iterators/RestIterator.hx
Normal file
19
Kha/Tools/macos/std/haxe/iterators/RestIterator.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package haxe.iterators;
|
||||
|
||||
class RestIterator<T> {
|
||||
final args:Rest<T>;
|
||||
var current:Int = 0;
|
||||
|
||||
@:allow(haxe.Rest)
|
||||
inline function new(args:Any) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public inline function hasNext():Bool {
|
||||
return current < args.length;
|
||||
}
|
||||
|
||||
public inline function next():T {
|
||||
return args[current++];
|
||||
}
|
||||
}
|
19
Kha/Tools/macos/std/haxe/iterators/RestKeyValueIterator.hx
Normal file
19
Kha/Tools/macos/std/haxe/iterators/RestKeyValueIterator.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package haxe.iterators;
|
||||
|
||||
class RestKeyValueIterator<T> {
|
||||
final args:Rest<T>;
|
||||
var current:Int = 0;
|
||||
|
||||
@:allow(haxe.Rest)
|
||||
inline function new(args:Any) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public inline function hasNext():Bool {
|
||||
return current < args.length;
|
||||
}
|
||||
|
||||
public inline function next():{key:Int, value:T} {
|
||||
return {key:current, value:args[current++]};
|
||||
}
|
||||
}
|
55
Kha/Tools/macos/std/haxe/iterators/StringIterator.hx
Normal file
55
Kha/Tools/macos/std/haxe/iterators/StringIterator.hx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C)2005-2018 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator can be used to iterate over char codes in a string.
|
||||
|
||||
Note that char codes may differ across platforms because of different
|
||||
internal encoding of strings in different of runtimes.
|
||||
**/
|
||||
class StringIterator {
|
||||
var offset = 0;
|
||||
var s:String;
|
||||
|
||||
/**
|
||||
Create a new `StringIterator` over String `s`.
|
||||
**/
|
||||
public inline function new(s:String) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext() {
|
||||
return offset < s.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
public inline function next() {
|
||||
return StringTools.unsafeCodeAt(s, offset++);
|
||||
}
|
||||
}
|
73
Kha/Tools/macos/std/haxe/iterators/StringIteratorUnicode.hx
Normal file
73
Kha/Tools/macos/std/haxe/iterators/StringIteratorUnicode.hx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator can be used to iterate across strings in a cross-platform
|
||||
way. It handles surrogate pairs on platforms that require it. On each
|
||||
iteration, it returns the next character code.
|
||||
|
||||
Note that this has different semantics than a standard for-loop over the
|
||||
String's length due to the fact that it deals with surrogate pairs.
|
||||
**/
|
||||
class StringIteratorUnicode {
|
||||
var offset = 0;
|
||||
var s:String;
|
||||
|
||||
/**
|
||||
Create a new `StringIteratorUnicode` over String `s`.
|
||||
**/
|
||||
public inline function new(s:String) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext() {
|
||||
return offset < s.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
@:access(StringTools)
|
||||
public inline function next() {
|
||||
#if utf16
|
||||
var c = StringTools.utf16CodePointAt(s, offset++);
|
||||
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
|
||||
offset++;
|
||||
}
|
||||
return c;
|
||||
#else
|
||||
return StringTools.unsafeCodeAt(s, offset++);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Convenience function which can be used as a static extension.
|
||||
**/
|
||||
static public inline function unicodeIterator(s:String) {
|
||||
return new StringIteratorUnicode(s);
|
||||
}
|
||||
}
|
55
Kha/Tools/macos/std/haxe/iterators/StringKeyValueIterator.hx
Normal file
55
Kha/Tools/macos/std/haxe/iterators/StringKeyValueIterator.hx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C)2005-2018 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator can be used to iterate over char indexes and char codes in a string.
|
||||
|
||||
Note that char codes may differ across platforms because of different
|
||||
internal encoding of strings in different runtimes.
|
||||
**/
|
||||
class StringKeyValueIterator {
|
||||
var offset = 0;
|
||||
var s:String;
|
||||
|
||||
/**
|
||||
Create a new `StringKeyValueIterator` over String `s`.
|
||||
**/
|
||||
public inline function new(s:String) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
See `KeyValueIterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext() {
|
||||
return offset < s.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `KeyValueIterator.next`
|
||||
**/
|
||||
public inline function next() {
|
||||
return {key: offset, value: StringTools.fastCodeAt(s, offset++)};
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.iterators;
|
||||
|
||||
/**
|
||||
This iterator can be used to iterate across strings in a cross-platform
|
||||
way. It handles surrogate pairs on platforms that require it. On each
|
||||
iteration, it returns the next character offset as key and the next
|
||||
character code as value.
|
||||
|
||||
Note that in the general case, because of surrogate pairs, the key values
|
||||
should not be used as offsets for various String API operations. For the
|
||||
same reason, the last key value returned might be less than `s.length - 1`.
|
||||
**/
|
||||
class StringKeyValueIteratorUnicode {
|
||||
var byteOffset = 0;
|
||||
var charOffset = 0;
|
||||
var s:String;
|
||||
|
||||
/**
|
||||
Create a new `StringKeyValueIteratorUnicode` over String `s`.
|
||||
**/
|
||||
public inline function new(s:String) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.hasNext`
|
||||
**/
|
||||
public inline function hasNext() {
|
||||
return byteOffset < s.length;
|
||||
}
|
||||
|
||||
/**
|
||||
See `Iterator.next`
|
||||
**/
|
||||
@:access(StringTools)
|
||||
public inline function next() {
|
||||
#if utf16
|
||||
var c = StringTools.utf16CodePointAt(s, byteOffset++);
|
||||
if (c >= StringTools.MIN_SURROGATE_CODE_POINT) {
|
||||
byteOffset++;
|
||||
}
|
||||
return {key: charOffset++, value: c};
|
||||
#else
|
||||
return {key: charOffset++, value: StringTools.fastCodeAt(s, byteOffset++)};
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Convenience function which can be used as a static extension.
|
||||
**/
|
||||
static public inline function unicodeKeyValueIterator(s:String) {
|
||||
return new StringKeyValueIteratorUnicode(s);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user