Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,85 @@
package haxe;
@:coreApi
class Exception {
public var message(get,never):String;
public var stack(get,never):CallStack;
public var previous(get,never):Null<Exception>;
public var native(get,never):Any;
@:noCompletion var __exceptionMessage:String;
@:noCompletion var __exceptionStack:Null<CallStack>;
@:noCompletion var __nativeStack:Any;
@:noCompletion @:ifFeature("haxe.Exception.get_stack") var __skipStack:Int = 0;
@:noCompletion var __nativeException:Any;
@:noCompletion var __previousException:Null<Exception>;
static function caught(value:Any):Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
}
}
static function thrown(value:Any):Any {
if(Std.isOfType(value, Exception)) {
return (value:Exception).native;
} else {
var e = new ValueException(value);
e.__shiftStack();
return e;
}
}
public function new(message:String, ?previous:Exception, ?native:Any) {
__exceptionMessage = message;
__previousException = previous;
if(native != null) {
__nativeStack = NativeStackTrace.exceptionStack();
__nativeException = native;
} else {
__nativeStack = NativeStackTrace.callStack();
__shiftStack();
__nativeException = this;
}
}
function unwrap():Any {
return __nativeException;
}
public function toString():String {
return message;
}
public function details():String {
return inline CallStack.exceptionToString(this);
}
@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __shiftStack():Void {
__skipStack++;
}
function get_message():String {
return __exceptionMessage;
}
function get_previous():Null<Exception> {
return __previousException;
}
final function get_native():Any {
return __nativeException;
}
function get_stack():CallStack {
return switch __exceptionStack {
case null:
__exceptionStack = NativeStackTrace.toHaxe(__nativeStack, __skipStack);
case s: s;
}
}
}

View File

@ -0,0 +1,51 @@
package haxe;
import haxe.CallStack.StackItem;
private typedef NativeTrace = {
final skip:Int;
final stack:Dynamic;
}
/**
Do not use manually.
**/
@:dox(hide)
@:noCompletion
class NativeStackTrace {
@:ifFeature('haxe.NativeStackTrace.exceptionStack')
static public inline function saveStack(exception:Any):Void {
}
static public inline function callStack():NativeTrace {
return { skip:1, stack:untyped __dollar__callstack() };
}
static public function exceptionStack():NativeTrace {
return { skip:0, stack:untyped __dollar__excstack() };
}
static public function toHaxe(native:NativeTrace, skip:Int = 0):Array<StackItem> {
skip += native.skip;
var a = new Array();
var l = untyped __dollar__asize(native.stack);
var i = 0;
while (i < l) {
var x = native.stack[l - i - 1];
//skip all CFunctions until we skip required amount of hx entries
if(x == null && skip > i) {
skip++;
}
if(skip > i++) {
continue;
}
if (x == null)
a.push(CFunction);
else if (untyped __dollar__typeof(x) == __dollar__tstring)
a.push(Module(new String(x)));
else
a.push(FilePos(null, new String(untyped x[0]), untyped x[1]));
}
return a;
}
}

View File

@ -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;
@:coreApi
class Resource {
static var content:Array<{name:String, data:String, str:String}>;
public static function listNames():Array<String> {
return [for (x in content) x.name];
}
public static function getString(name:String):String {
for (x in content)
if (x.name == name) {
return new String(x.data);
}
return null;
}
public static function getBytes(name:String):haxe.io.Bytes {
for (x in content)
if (x.name == name) {
return haxe.io.Bytes.ofData(cast x.data);
}
return null;
}
static function __init__() : Void {
var tmp = untyped __resources__();
content = untyped Array.new1(tmp, __dollar__asize(tmp));
}
}

View File

@ -0,0 +1,107 @@
/*
* 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;
@:coreApi
@:deprecated('haxe.Utf8 is deprecated. Use UnicodeString instead.')
class Utf8 {
var __b:Dynamic;
public function new(?size:Int):Void {
__b = utf8_buf_alloc(if (size == null) 1 else size);
}
public function addChar(c:Int):Void {
utf8_buf_add(__b, c);
}
public function toString():String {
return new String(utf8_buf_content(__b));
}
public static function encode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var buf:Dynamic = utf8_buf_alloc(sl);
var i = 0;
while (i < sl) {
utf8_buf_add(buf, untyped __dollar__sget(s, i));
i += 1;
}
return new String(utf8_buf_content(buf));
}
public static function decode(s:String):String {
s = untyped s.__s;
var sl = untyped __dollar__ssize(s);
var ret = untyped __dollar__smake(sl);
var i = 0;
utf8_iter(s, function(c) {
if (c == 8364) // euro symbol
c = 164;
else if (c == 0xFEFF) // BOM
return;
else if (c > 255)
throw "Utf8::decode invalid character (" + c + ")";
untyped __dollar__sset(ret, i, c);
i += 1;
});
return new String(untyped __dollar__ssub(ret, 0, i));
}
public static function iter(s:String, chars:Int->Void):Void {
utf8_iter(untyped s.__s, chars);
}
public static function charCodeAt(s:String, index:Int):Int {
return utf8_get(untyped s.__s, index);
}
public static function validate(s:String):Bool {
return utf8_validate(untyped s.__s);
}
public static function length(s:String):Int {
return utf8_length(untyped s.__s);
}
public static function compare(a:String, b:String):Int {
return utf8_compare(untyped a.__s, untyped b.__s);
}
public static function sub(s:String, pos:Int, len:Int):String {
return new String(utf8_sub(untyped s.__s, pos, len));
}
static var utf8_buf_alloc = neko.Lib.load("std", "utf8_buf_alloc", 1);
static var utf8_buf_add = neko.Lib.load("std", "utf8_buf_add", 2);
static var utf8_buf_content = neko.Lib.load("std", "utf8_buf_content", 1);
static var utf8_buf_length = neko.Lib.load("std", "utf8_buf_length", 1);
static var utf8_iter = neko.Lib.load("std", "utf8_iter", 2);
static var utf8_get = neko.Lib.load("std", "utf8_get", 2);
static var utf8_validate = neko.Lib.load("std", "utf8_validate", 1);
static var utf8_length = neko.Lib.load("std", "utf8_length", 1);
static var utf8_compare = neko.Lib.load("std", "utf8_compare", 2);
static var utf8_sub = neko.Lib.load("std", "utf8_sub", 3);
}

View File

@ -0,0 +1,36 @@
/*
* 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.crypto;
class Md5 {
public static function encode(s:String):String {
return untyped new String(base_encode(make_md5(s.__s), "0123456789abcdef".__s));
}
public static function make(b:haxe.io.Bytes):haxe.io.Bytes {
return haxe.io.Bytes.ofData(make_md5(b.getData()));
}
static var base_encode = neko.Lib.load("std", "base_encode", 2);
static var make_md5 = neko.Lib.load("std", "make_md5", 1);
}

View File

@ -0,0 +1,93 @@
/*
* 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.ds;
@:coreApi class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
private var h:Dynamic;
public function new():Void {
h = untyped __dollar__hnew(0);
}
public inline function set(key:Int, value:T):Void {
untyped __dollar__hset(h, key, value, null);
}
public function get(key:Int):Null<T> {
return untyped __dollar__hget(h, key, null);
}
public inline function exists(key:Int):Bool {
return untyped __dollar__hmem(h, key, null);
}
public inline function remove(key:Int):Bool {
return untyped __dollar__hremove(h, key, null);
}
public function keys():Iterator<Int> {
var l = new List<Int>();
untyped __dollar__hiter(h, function(k, _) {
l.push(k);
});
return l.iterator();
}
public function iterator():Iterator<T> {
var l = new List<T>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<Int, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():IntMap<T> {
var copied = new IntMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(i);
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of h 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 h 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.ds;
@:coreApi
class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
static var count = 0;
static inline function assignId(obj:{}):Int {
var newId = count++;
untyped obj.__id__ = newId;
return newId;
}
static inline function getId(obj:{}):Int {
return untyped obj.__id__;
}
var h:{};
var k:{};
public function new():Void {
h = untyped __dollar__hnew(0);
k = untyped __dollar__hnew(0);
}
public inline function set(key:K, value:V):Void
untyped {
var id = key.__id__ != null ? key.__id__ : assignId(key);
untyped __dollar__hset(h, id, value, null);
untyped __dollar__hset(k, id, key, null);
}
public function get(key:K):Null<V> {
return untyped __dollar__hget(h, getId(key), null);
}
public inline function exists(key:K):Bool {
return untyped __dollar__hmem(h, getId(key), null);
}
public function remove(key:K):Bool {
var id = getId(key);
untyped __dollar__hremove(h, id, null);
return untyped __dollar__hremove(k, id, null);
}
public function keys():Iterator<K> {
var l = new List<K>();
untyped __dollar__hiter(k, function(_, v) {
l.push(v);
});
return l.iterator();
}
public function iterator():Iterator<V> {
var l = new List<V>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<K, V> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():ObjectMap<K, V> {
var copied = new ObjectMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(Std.string(i));
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
k = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,93 @@
/*
* 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.ds;
@:coreApi class StringMap<T> implements haxe.Constraints.IMap<String, T> {
private var h:Dynamic;
public function new():Void {
h = untyped __dollar__hnew(0);
}
public inline function set(key:String, value:T):Void {
untyped __dollar__hset(h, key.__s, value, null);
}
public inline function get(key:String):Null<T> {
return untyped __dollar__hget(h, key.__s, null);
}
public inline function exists(key:String):Bool {
return untyped __dollar__hmem(h, key.__s, null);
}
public inline function remove(key:String):Bool {
return untyped __dollar__hremove(h, key.__s, null);
}
public function keys():Iterator<String> {
var l = new List<String>();
untyped __dollar__hiter(h, function(k, _) {
l.push(new String(k));
});
return l.iterator();
}
public function iterator():Iterator<T> {
var l = new List<T>();
untyped __dollar__hiter(h, function(_, v) {
l.push(v);
});
return l.iterator();
}
@:runtime public inline function keyValueIterator():KeyValueIterator<String, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():StringMap<T> {
var copied = new StringMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(i);
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = untyped __dollar__hnew(0);
}
}

View File

@ -0,0 +1,29 @@
/*
* 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.io;
class StringInput extends BytesInput {
public function new(s:String) {
super(neko.Lib.bytesReference(s));
}
}

View File

@ -0,0 +1,64 @@
/*
* 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;
class StringIteratorUnicode {
var byteOffset:Int = 0;
var s:String;
public inline function new(s:String) {
this.s = s;
}
public inline function hasNext() {
return byteOffset < s.length;
}
public inline function next() {
var code:Int = codeAt(byteOffset);
if (code < 0xC0) {
byteOffset++;
} else if (code < 0xE0) {
code = ((code - 0xC0) << 6) + codeAt(byteOffset + 1) - 0x80;
byteOffset += 2;
} else if (code < 0xF0) {
code = ((code - 0xE0) << 12) + ((codeAt(byteOffset + 1) - 0x80) << 6) + codeAt(byteOffset + 2) - 0x80;
byteOffset += 3;
} else {
code = ((code - 0xF0) << 18)
+ ((codeAt(byteOffset + 1) - 0x80) << 12)
+ ((codeAt(byteOffset + 2) - 0x80) << 6)
+ codeAt(byteOffset + 3)
- 0x80;
byteOffset += 4;
}
return code;
}
inline function codeAt(index:Int):Int {
return untyped $sget(s.__s, index);
}
static public inline function unicodeIterator(s:String) {
return new StringIteratorUnicode(s);
}
}

View File

@ -0,0 +1,65 @@
/*
* 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;
class StringKeyValueIteratorUnicode {
var byteOffset:Int = 0;
var charOffset:Int = 0;
var s:String;
public inline function new(s:String) {
this.s = s;
}
public inline function hasNext() {
return byteOffset < s.length;
}
public inline function next() {
var code:Int = codeAt(byteOffset);
if (code < 0xC0) {
byteOffset++;
} else if (code < 0xE0) {
code = ((code - 0xC0) << 6) + codeAt(byteOffset + 1) - 0x80;
byteOffset += 2;
} else if (code < 0xF0) {
code = ((code - 0xE0) << 12) + ((codeAt(byteOffset + 1) - 0x80) << 6) + codeAt(byteOffset + 2) - 0x80;
byteOffset += 3;
} else {
code = ((code - 0xF0) << 18)
+ ((codeAt(byteOffset + 1) - 0x80) << 12)
+ ((codeAt(byteOffset + 2) - 0x80) << 6)
+ codeAt(byteOffset + 3)
- 0x80;
byteOffset += 4;
}
return {key: charOffset++, value: code};
}
inline function codeAt(index:Int):Int {
return untyped $sget(s.__s, index);
}
static public inline function unicodeKeyValueIterator(s:String) {
return new StringKeyValueIteratorUnicode(s);
}
}

View File

@ -0,0 +1,61 @@
/*
* 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.zip;
@:coreApi
class Compress {
var s:Dynamic;
public function new(level:Int):Void {
s = _deflate_init(level);
}
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
return _deflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, untyped Std.string(f).__s);
}
public function close():Void {
_deflate_end(s);
}
public static function run(s:haxe.io.Bytes, level:Int):haxe.io.Bytes {
var c = new Compress(level);
c.setFlushMode(FlushMode.FINISH);
var out = haxe.io.Bytes.alloc(_deflate_bound(c.s, s.length));
var r = c.execute(s, 0, out, 0);
c.close();
if (!r.done || r.read != s.length)
throw "Compression failed";
return out.sub(0, r.write);
}
static var _deflate_init = neko.Lib.load("zlib", "deflate_init", 1);
static var _deflate_bound = neko.Lib.load("zlib", "deflate_bound", 2);
static var _deflate_buffer = neko.Lib.load("zlib", "deflate_buffer", 5);
static var _deflate_end = neko.Lib.load("zlib", "deflate_end", 1);
static var _set_flush_mode = neko.Lib.load("zlib", "set_flush_mode", 2);
}

View File

@ -0,0 +1,68 @@
/*
* 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.zip;
@:coreApi
class Uncompress {
var s:Dynamic;
public function new(?windowBits:Int):Void {
s = _inflate_init(windowBits);
}
public function execute(src:haxe.io.Bytes, srcPos:Int, dst:haxe.io.Bytes, dstPos:Int):{done:Bool, read:Int, write:Int} {
return _inflate_buffer(s, src.getData(), srcPos, dst.getData(), dstPos);
}
public function setFlushMode(f:FlushMode):Void {
_set_flush_mode(s, untyped Std.string(f).__s);
}
public function close():Void {
_inflate_end(s);
}
public static function run(src:haxe.io.Bytes, ?bufsize:Int):haxe.io.Bytes {
var u = new Uncompress(null);
if (bufsize == null)
bufsize = 1 << 16; // 64K
var tmp = haxe.io.Bytes.alloc(bufsize);
var b = new haxe.io.BytesBuffer();
var pos = 0;
u.setFlushMode(FlushMode.SYNC);
while (true) {
var r = u.execute(src, pos, tmp, 0);
b.addBytes(tmp, 0, r.write);
pos += r.read;
if (r.done)
break;
}
u.close();
return b.getBytes();
}
static var _inflate_init = neko.Lib.load("zlib", "inflate_init", 1);
static var _inflate_buffer = neko.Lib.load("zlib", "inflate_buffer", 5);
static var _inflate_end = neko.Lib.load("zlib", "inflate_end", 1);
static var _set_flush_mode = neko.Lib.load("zlib", "set_flush_mode", 2);
}