forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
96
Kha/Tools/macos/std/haxe/io/ArrayBufferView.hx
Normal file
96
Kha/Tools/macos/std/haxe/io/ArrayBufferView.hx
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef ArrayBufferViewData = ArrayBufferViewImpl;
|
||||
|
||||
class ArrayBufferViewImpl {
|
||||
public var bytes:haxe.io.Bytes;
|
||||
public var byteOffset:Int;
|
||||
public var byteLength:Int;
|
||||
|
||||
public function new(bytes, pos, length) {
|
||||
this.bytes = bytes;
|
||||
this.byteOffset = pos;
|
||||
this.byteLength = length;
|
||||
}
|
||||
|
||||
public function sub(begin:Int, ?length:Int) {
|
||||
if (length == null)
|
||||
length = byteLength - begin;
|
||||
if (begin < 0 || length < 0 || begin + length > byteLength)
|
||||
throw Error.OutsideBounds;
|
||||
return new ArrayBufferViewImpl(bytes, byteOffset + begin, length);
|
||||
}
|
||||
|
||||
public function subarray(?begin:Int, ?end:Int) {
|
||||
if (begin == null)
|
||||
begin = 0;
|
||||
if (end == null)
|
||||
end = byteLength - begin;
|
||||
return sub(begin, end - begin);
|
||||
}
|
||||
}
|
||||
|
||||
abstract ArrayBufferView(ArrayBufferViewData) {
|
||||
public var buffer(get, never):haxe.io.Bytes;
|
||||
public var byteOffset(get, never):Int;
|
||||
public var byteLength(get, never):Int;
|
||||
|
||||
public inline function new(size:Int) {
|
||||
this = new ArrayBufferViewData(haxe.io.Bytes.alloc(size), 0, size);
|
||||
}
|
||||
|
||||
inline function get_byteOffset():Int
|
||||
return this.byteOffset;
|
||||
|
||||
inline function get_byteLength():Int
|
||||
return this.byteLength;
|
||||
|
||||
inline function get_buffer():haxe.io.Bytes
|
||||
return this.bytes;
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):ArrayBufferView {
|
||||
return fromData(this.sub(begin, length));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):ArrayBufferView {
|
||||
return fromData(this.subarray(begin, end));
|
||||
}
|
||||
|
||||
public inline function getData():ArrayBufferViewData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static inline function fromData(a:ArrayBufferViewData):ArrayBufferView {
|
||||
return cast a;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, pos = 0, ?length:Int):ArrayBufferView {
|
||||
if (length == null)
|
||||
length = bytes.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > bytes.length)
|
||||
throw Error.OutsideBounds;
|
||||
return fromData(new ArrayBufferViewData(bytes, pos, length));
|
||||
}
|
||||
}
|
64
Kha/Tools/macos/std/haxe/io/BufferInput.hx
Normal file
64
Kha/Tools/macos/std/haxe/io/BufferInput.hx
Normal 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.io;
|
||||
|
||||
class BufferInput extends haxe.io.Input {
|
||||
public var i:haxe.io.Input;
|
||||
public var buf:haxe.io.Bytes;
|
||||
public var available:Int;
|
||||
public var pos:Int;
|
||||
|
||||
public function new(i, buf, ?pos = 0, ?available = 0) {
|
||||
this.i = i;
|
||||
this.buf = buf;
|
||||
this.pos = pos;
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public function refill() {
|
||||
if (pos > 0) {
|
||||
buf.blit(0, buf, pos, available);
|
||||
pos = 0;
|
||||
}
|
||||
available += i.readBytes(buf, available, buf.length - available);
|
||||
}
|
||||
|
||||
override function readByte() {
|
||||
if (available == 0)
|
||||
refill();
|
||||
var c = buf.get(pos);
|
||||
pos++;
|
||||
available--;
|
||||
return c;
|
||||
}
|
||||
|
||||
override function readBytes(buf:haxe.io.Bytes, pos:Int, len:Int) {
|
||||
if (available == 0)
|
||||
refill();
|
||||
var size = if (len > available) available else len;
|
||||
buf.blit(pos, this.buf, this.pos, size);
|
||||
this.pos += size;
|
||||
this.available -= size;
|
||||
return size;
|
||||
}
|
||||
}
|
707
Kha/Tools/macos/std/haxe/io/Bytes.hx
Normal file
707
Kha/Tools/macos/std/haxe/io/Bytes.hx
Normal file
@ -0,0 +1,707 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
#if cpp
|
||||
using cpp.NativeArray;
|
||||
#end
|
||||
|
||||
class Bytes {
|
||||
public var length(default, null):Int;
|
||||
|
||||
var b:BytesData;
|
||||
|
||||
function new(length, b) {
|
||||
this.length = length;
|
||||
this.b = b;
|
||||
#if flash
|
||||
b.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the byte at index `pos`.
|
||||
**/
|
||||
public inline function get(pos:Int):Int {
|
||||
#if neko
|
||||
return untyped $sget(b, pos);
|
||||
#elseif flash
|
||||
return b[pos];
|
||||
#elseif cpp
|
||||
return untyped b[pos];
|
||||
#elseif java
|
||||
return untyped b[pos] & 0xFF;
|
||||
#elseif python
|
||||
return python.Syntax.arrayAccess(b, pos);
|
||||
#else
|
||||
return b[pos];
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given byte `v` at the given position `pos`.
|
||||
**/
|
||||
public inline function set(pos:Int, v:Int):Void {
|
||||
#if neko
|
||||
untyped $sset(b, pos, v);
|
||||
#elseif flash
|
||||
b[pos] = v;
|
||||
#elseif cpp
|
||||
untyped b[pos] = v;
|
||||
#elseif java
|
||||
b[pos] = cast v;
|
||||
#elseif cs
|
||||
b[pos] = cast v;
|
||||
#elseif python
|
||||
python.Syntax.arraySet(b, pos, v & 0xFF);
|
||||
#else
|
||||
b[pos] = v & 0xFF;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Copies `len` bytes from `src` into this instance.
|
||||
@param pos Zero-based location in `this` instance at which to start writing
|
||||
bytes.
|
||||
@param src Source `Bytes` instance from which to copy bytes.
|
||||
@param srcpos Zero-based location at `src` from which bytes will be copied.
|
||||
@param len Number of bytes to be copied.
|
||||
**/
|
||||
public function blit(pos:Int, src:Bytes, srcpos:Int, len:Int):Void {
|
||||
#if !neko
|
||||
if (pos < 0 || srcpos < 0 || len < 0 || pos + len > length || srcpos + len > src.length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
#if neko
|
||||
try
|
||||
untyped $sblit(b, pos, src.b, srcpos, len)
|
||||
catch (e:Dynamic)
|
||||
throw Error.OutsideBounds;
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
if (len > 0)
|
||||
b.writeBytes(src.b, srcpos, len);
|
||||
#elseif java
|
||||
java.lang.System.arraycopy(src.b, srcpos, b, pos, len);
|
||||
#elseif cs
|
||||
cs.system.Array.Copy(src.b, srcpos, b, pos, len);
|
||||
#elseif python
|
||||
python.Syntax.code("self.b[{0}:{0}+{1}] = src.b[srcpos:srcpos+{1}]", pos, len);
|
||||
#elseif cpp
|
||||
b.blit(pos, src.b, srcpos, len);
|
||||
#else
|
||||
var b1 = b;
|
||||
var b2 = src.b;
|
||||
if (b1 == b2 && pos > srcpos) {
|
||||
var i = len;
|
||||
while (i > 0) {
|
||||
i--;
|
||||
b1[i + pos] = b2[i + srcpos];
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (i in 0...len)
|
||||
b1[i + pos] = b2[i + srcpos];
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Sets `len` consecutive bytes starting from index `pos` of `this` instance
|
||||
to `value`.
|
||||
**/
|
||||
public function fill(pos:Int, len:Int, value:Int) {
|
||||
#if flash
|
||||
var v4 = value & 0xFF;
|
||||
v4 |= v4 << 8;
|
||||
v4 |= v4 << 16;
|
||||
b.position = pos;
|
||||
for (i in 0...len >> 2)
|
||||
b.writeUnsignedInt(v4);
|
||||
pos += len & ~3;
|
||||
for (i in 0...len & 3)
|
||||
set(pos++, value);
|
||||
#elseif cpp
|
||||
untyped __global__.__hxcpp_memory_memset(b, pos, len, value);
|
||||
#else
|
||||
for (i in 0...len)
|
||||
set(pos++, value);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a new `Bytes` instance that contains a copy of `len` bytes of
|
||||
`this` instance, starting at index `pos`.
|
||||
**/
|
||||
public function sub(pos:Int, len:Int):Bytes {
|
||||
#if !neko
|
||||
if (pos < 0 || len < 0 || pos + len > length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
#if neko
|
||||
return try new Bytes(len, untyped __dollar__ssub(b, pos, len)) catch (e:Dynamic) throw Error.OutsideBounds;
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
var b2 = new flash.utils.ByteArray();
|
||||
b.readBytes(b2, 0, len);
|
||||
return new Bytes(len, b2);
|
||||
#elseif java
|
||||
var newarr = new java.NativeArray(len);
|
||||
java.lang.System.arraycopy(b, pos, newarr, 0, len);
|
||||
return new Bytes(len, newarr);
|
||||
#elseif cs
|
||||
var newarr = new cs.NativeArray(len);
|
||||
cs.system.Array.Copy(b, pos, newarr, 0, len);
|
||||
return new Bytes(len, newarr);
|
||||
#elseif python
|
||||
return new Bytes(len, python.Syntax.arrayAccess(b, pos, pos + len));
|
||||
#else
|
||||
return new Bytes(len, b.slice(pos, pos + len));
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns `0` if the bytes of `this` instance and the bytes of `other` are
|
||||
identical.
|
||||
|
||||
Returns a negative value if the `length` of `this` instance is less than
|
||||
the `length` of `other`, or a positive value if the `length` of `this`
|
||||
instance is greater than the `length` of `other`.
|
||||
|
||||
In case of equal `length`s, returns a negative value if the first different
|
||||
value in `other` is greater than the corresponding value in `this`
|
||||
instance; otherwise returns a positive value.
|
||||
**/
|
||||
public function compare(other:Bytes):Int {
|
||||
#if neko
|
||||
return untyped __dollar__compare(b, other.b);
|
||||
#elseif flash
|
||||
var len = (length < other.length) ? length : other.length;
|
||||
var b1 = b;
|
||||
var b2 = other.b;
|
||||
b1.position = 0;
|
||||
b2.position = 0;
|
||||
b1.endian = flash.utils.Endian.BIG_ENDIAN;
|
||||
b2.endian = flash.utils.Endian.BIG_ENDIAN;
|
||||
for (i in 0...len >> 2)
|
||||
if (b1.readUnsignedInt() != b2.readUnsignedInt()) {
|
||||
b1.position -= 4;
|
||||
b2.position -= 4;
|
||||
var d = b1.readUnsignedInt() - b2.readUnsignedInt();
|
||||
b1.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
b2.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
return d;
|
||||
}
|
||||
for (i in 0...len & 3)
|
||||
if (b1.readUnsignedByte() != b2.readUnsignedByte()) {
|
||||
b1.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
b2.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
return b1[b1.position - 1] - b2[b2.position - 1];
|
||||
}
|
||||
b1.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
b2.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
return length - other.length;
|
||||
// #elseif cs
|
||||
// TODO: memcmp if unsafe flag is on
|
||||
#elseif cpp
|
||||
return b.memcmp(other.b);
|
||||
#else
|
||||
var b1 = b;
|
||||
var b2 = other.b;
|
||||
var len = (length < other.length) ? length : other.length;
|
||||
for (i in 0...len)
|
||||
if (b1[i] != b2[i])
|
||||
return untyped b1[i] - b2[i];
|
||||
return length - other.length;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the IEEE double-precision value at the given position `pos` (in
|
||||
little-endian encoding). Result is unspecified if `pos` is outside the
|
||||
bounds.
|
||||
**/
|
||||
#if (neko_v21 || (cpp && !cppia) || flash)
|
||||
inline
|
||||
#end
|
||||
public function getDouble(pos:Int):Float {
|
||||
#if neko_v21
|
||||
return untyped $sgetd(b, pos, false);
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
return b.readDouble();
|
||||
#elseif cpp
|
||||
if (pos < 0 || pos + 8 > length)
|
||||
throw Error.OutsideBounds;
|
||||
return untyped __global__.__hxcpp_memory_get_double(b, pos);
|
||||
#else
|
||||
return FPHelper.i64ToDouble(getInt32(pos), getInt32(pos + 4));
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the IEEE single-precision value at the given position `pos` (in
|
||||
little-endian encoding). Result is unspecified if `pos` is outside the
|
||||
bounds.
|
||||
**/
|
||||
#if (neko_v21 || (cpp && !cppia) || flash)
|
||||
inline
|
||||
#end
|
||||
public function getFloat(pos:Int):Float {
|
||||
#if neko_v21
|
||||
return untyped $sgetf(b, pos, false);
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
return b.readFloat();
|
||||
#elseif cpp
|
||||
if (pos < 0 || pos + 4 > length)
|
||||
throw Error.OutsideBounds;
|
||||
return untyped __global__.__hxcpp_memory_get_float(b, pos);
|
||||
#else
|
||||
return FPHelper.i32ToFloat(getInt32(pos));
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given IEEE double-precision value `v` at the given position
|
||||
`pos` in little-endian encoding. Result is unspecified if writing outside
|
||||
of bounds.
|
||||
**/
|
||||
#if (neko_v21 || flash)
|
||||
inline
|
||||
#end
|
||||
public function setDouble(pos:Int, v:Float):Void {
|
||||
#if neko_v21
|
||||
untyped $ssetd(b, pos, v, false);
|
||||
#elseif neko
|
||||
untyped $sblit(b, pos, FPHelper._double_bytes(v, false), 0, 8);
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
b.writeDouble(v);
|
||||
#elseif cpp
|
||||
if (pos < 0 || pos + 8 > length)
|
||||
throw Error.OutsideBounds;
|
||||
untyped __global__.__hxcpp_memory_set_double(b, pos, v);
|
||||
#else
|
||||
var i = FPHelper.doubleToI64(v);
|
||||
setInt32(pos, i.low);
|
||||
setInt32(pos + 4, i.high);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given IEEE single-precision value `v` at the given position
|
||||
`pos` in little-endian encoding. Result is unspecified if writing outside
|
||||
of bounds.
|
||||
**/
|
||||
#if (neko_v21 || flash)
|
||||
inline
|
||||
#end
|
||||
public function setFloat(pos:Int, v:Float):Void {
|
||||
#if neko_v21
|
||||
untyped $ssetf(b, pos, v, false);
|
||||
#elseif neko
|
||||
untyped $sblit(b, pos, FPHelper._float_bytes(v, false), 0, 4);
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
b.writeFloat(v);
|
||||
#elseif cpp
|
||||
if (pos < 0 || pos + 4 > length)
|
||||
throw Error.OutsideBounds;
|
||||
untyped __global__.__hxcpp_memory_set_float(b, pos, v);
|
||||
#else
|
||||
setInt32(pos, FPHelper.floatToI32(v));
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the 16-bit unsigned integer at the given position `pos` (in
|
||||
little-endian encoding).
|
||||
**/
|
||||
public inline function getUInt16(pos:Int):Int {
|
||||
#if neko_v21
|
||||
return untyped $sget16(b, pos, false);
|
||||
#else
|
||||
return get(pos) | (get(pos + 1) << 8);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given 16-bit unsigned integer `v` at the given position `pos`
|
||||
(in little-endian encoding).
|
||||
**/
|
||||
public inline function setUInt16(pos:Int, v:Int):Void {
|
||||
#if neko_v21
|
||||
untyped $sset16(b, pos, v, false);
|
||||
#else
|
||||
set(pos, v);
|
||||
set(pos + 1, v >> 8);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the 32-bit integer at the given position `pos` (in little-endian
|
||||
encoding).
|
||||
**/
|
||||
public inline function getInt32(pos:Int):Int {
|
||||
#if neko_v21
|
||||
return untyped $sget32(b, pos, false);
|
||||
#elseif python
|
||||
var v = get(pos) | (get(pos + 1) << 8) | (get(pos + 2) << 16) | (get(pos + 3) << 24);
|
||||
return if (v & 0x80000000 != 0) v | 0x80000000 else v;
|
||||
#elseif lua
|
||||
var v = get(pos) | (get(pos + 1) << 8) | (get(pos + 2) << 16) | (get(pos + 3) << 24);
|
||||
return lua.Boot.clampInt32(if (v & 0x80000000 != 0) v | 0x80000000 else v);
|
||||
#else
|
||||
return get(pos) | (get(pos + 1) << 8) | (get(pos + 2) << 16) | (get(pos + 3) << 24);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the 64-bit integer at the given position `pos` (in little-endian
|
||||
encoding).
|
||||
**/
|
||||
public inline function getInt64(pos:Int):haxe.Int64 {
|
||||
return haxe.Int64.make(getInt32(pos + 4), getInt32(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given 32-bit integer `v` at the given position `pos` (in
|
||||
little-endian encoding).
|
||||
**/
|
||||
public inline function setInt32(pos:Int, v:Int):Void {
|
||||
#if neko_v21
|
||||
untyped $sset32(b, pos, v, false);
|
||||
#else
|
||||
set(pos, v);
|
||||
set(pos + 1, v >> 8);
|
||||
set(pos + 2, v >> 16);
|
||||
set(pos + 3, v >>> 24);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Stores the given 64-bit integer `v` at the given position `pos` (in
|
||||
little-endian encoding).
|
||||
**/
|
||||
public inline function setInt64(pos:Int, v:haxe.Int64):Void {
|
||||
setInt32(pos, v.low);
|
||||
setInt32(pos + 4, v.high);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `len`-bytes long string stored at the given position `pos`,
|
||||
interpreted with the given `encoding` (UTF-8 by default).
|
||||
**/
|
||||
public function getString(pos:Int, len:Int, ?encoding:Encoding):String {
|
||||
if (encoding == null)
|
||||
encoding == UTF8;
|
||||
#if !neko
|
||||
if (pos < 0 || len < 0 || pos + len > length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
#if neko
|
||||
return try new String(untyped __dollar__ssub(b, pos, len)) catch (e:Dynamic) throw Error.OutsideBounds;
|
||||
#elseif flash
|
||||
b.position = pos;
|
||||
return encoding == RawNative ? b.readMultiByte(len, "unicode") : b.readUTFBytes(len);
|
||||
#elseif cpp
|
||||
var result:String = "";
|
||||
untyped __global__.__hxcpp_string_of_bytes(b, result, pos, len);
|
||||
return result;
|
||||
#elseif cs
|
||||
switch (encoding) {
|
||||
case UTF8 | null:
|
||||
return cs.system.text.Encoding.UTF8.GetString(b, pos, len);
|
||||
case RawNative:
|
||||
return cs.system.text.Encoding.Unicode.GetString(b, pos, len);
|
||||
}
|
||||
#elseif java
|
||||
try {
|
||||
switch (encoding) {
|
||||
case UTF8 | null:
|
||||
return new String(b, pos, len, "UTF-8");
|
||||
case RawNative:
|
||||
return new String(b, pos, len, "UTF-16LE");
|
||||
}
|
||||
} catch (e:Dynamic) {
|
||||
throw e;
|
||||
}
|
||||
#elseif python
|
||||
return python.Syntax.code("self.b[{0}:{0}+{1}].decode('UTF-8','replace')", pos, len);
|
||||
#elseif lua
|
||||
if (b.length - pos <= lua.Boot.MAXSTACKSIZE) {
|
||||
var end:Int = cast Math.min(b.length, pos + len) - 1;
|
||||
return lua.NativeStringTools.char(lua.TableTools.unpack(untyped b, pos, end));
|
||||
} else {
|
||||
var tbl:lua.Table<Int, String> = lua.Table.create();
|
||||
for (idx in pos...pos + len) {
|
||||
lua.Table.insert(tbl, lua.NativeStringTools.char(b[idx]));
|
||||
}
|
||||
return lua.Table.concat(tbl, '');
|
||||
}
|
||||
#else
|
||||
var s = "";
|
||||
var b = b;
|
||||
var fcc = String.fromCharCode;
|
||||
var i = pos;
|
||||
var max = pos + len;
|
||||
// utf8-decode and utf16-encode
|
||||
while (i < max) {
|
||||
var c = b[i++];
|
||||
if (c < 0x80) {
|
||||
if (c == 0)
|
||||
break;
|
||||
s += fcc(c);
|
||||
} else if (c < 0xE0)
|
||||
s += fcc(((c & 0x3F) << 6) | (b[i++] & 0x7F));
|
||||
else if (c < 0xF0) {
|
||||
var c2 = b[i++];
|
||||
s += fcc(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (b[i++] & 0x7F));
|
||||
} else {
|
||||
var c2 = b[i++];
|
||||
var c3 = b[i++];
|
||||
var u = ((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 & 0x7F) << 6) | (b[i++] & 0x7F);
|
||||
// surrogate pair
|
||||
s += fcc((u >> 10) + 0xD7C0);
|
||||
s += fcc((u & 0x3FF) | 0xDC00);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
#end
|
||||
}
|
||||
|
||||
@:deprecated("readString is deprecated, use getString instead")
|
||||
@:noCompletion
|
||||
public inline function readString(pos:Int, len:Int):String {
|
||||
return getString(pos, len);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a `String` representation of the bytes interpreted as UTF-8.
|
||||
**/
|
||||
public function toString():String {
|
||||
#if neko
|
||||
return new String(untyped __dollar__ssub(b, 0, length));
|
||||
#elseif flash
|
||||
b.position = 0;
|
||||
return b.toString();
|
||||
#elseif cs
|
||||
return cs.system.text.Encoding.UTF8.GetString(b, 0, length);
|
||||
#elseif java
|
||||
try {
|
||||
return new String(b, 0, length, "UTF-8");
|
||||
} catch (e:Dynamic)
|
||||
throw e;
|
||||
#else
|
||||
return getString(0, length);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a hexadecimal `String` representation of the bytes of `this`
|
||||
instance.
|
||||
**/
|
||||
public function toHex():String {
|
||||
var s = new StringBuf();
|
||||
var chars = [];
|
||||
var str = "0123456789abcdef";
|
||||
for (i in 0...str.length)
|
||||
chars.push(str.charCodeAt(i));
|
||||
for (i in 0...length) {
|
||||
var c = get(i);
|
||||
s.addChar(chars[c >> 4]);
|
||||
s.addChar(chars[c & 15]);
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the bytes of `this` instance as `BytesData`.
|
||||
**/
|
||||
public inline function getData():BytesData {
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a new `Bytes` instance with the given `length`. The values of the
|
||||
bytes are not initialized and may not be zero.
|
||||
**/
|
||||
public static function alloc(length:Int):Bytes {
|
||||
#if neko
|
||||
return new Bytes(length, untyped __dollar__smake(length));
|
||||
#elseif flash
|
||||
var b = new flash.utils.ByteArray();
|
||||
b.length = length;
|
||||
return new Bytes(length, b);
|
||||
#elseif cpp
|
||||
var a = new BytesData();
|
||||
if (length > 0)
|
||||
cpp.NativeArray.setSize(a, length);
|
||||
return new Bytes(length, a);
|
||||
#elseif cs
|
||||
return new Bytes(length, new cs.NativeArray(length));
|
||||
#elseif java
|
||||
return new Bytes(length, new java.NativeArray(length));
|
||||
#elseif python
|
||||
return new Bytes(length, new python.Bytearray(length));
|
||||
#else
|
||||
var a = new Array();
|
||||
for (i in 0...length)
|
||||
a.push(0);
|
||||
return new Bytes(length, a);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `Bytes` representation of the given `String`, using the
|
||||
specified encoding (UTF-8 by default).
|
||||
**/
|
||||
@:pure
|
||||
public static function ofString(s:String, ?encoding:Encoding):Bytes {
|
||||
#if neko
|
||||
return new Bytes(s.length, untyped __dollar__ssub(s.__s, 0, s.length));
|
||||
#elseif flash
|
||||
var b = new flash.utils.ByteArray();
|
||||
if (encoding == RawNative)
|
||||
b.writeMultiByte(s, "unicode")
|
||||
else
|
||||
b.writeUTFBytes(s);
|
||||
return new Bytes(b.length, b);
|
||||
#elseif cpp
|
||||
var a = new BytesData();
|
||||
untyped __global__.__hxcpp_bytes_of_string(a, s);
|
||||
return new Bytes(a.length, a);
|
||||
#elseif cs
|
||||
var b = switch (encoding) {
|
||||
case UTF8 | null:
|
||||
cs.system.text.Encoding.UTF8.GetBytes(s);
|
||||
case RawNative:
|
||||
cs.system.text.Encoding.Unicode.GetBytes(s);
|
||||
};
|
||||
return new Bytes(b.Length, b);
|
||||
#elseif java
|
||||
try {
|
||||
var b:BytesData = switch (encoding) {
|
||||
case UTF8 | null:
|
||||
@:privateAccess s.getBytes("UTF-8");
|
||||
case RawNative:
|
||||
@:privateAccess s.getBytes("UTF-16LE");
|
||||
};
|
||||
return new Bytes(b.length, b);
|
||||
} catch (e:Dynamic) {
|
||||
throw e;
|
||||
}
|
||||
#elseif python
|
||||
var b:BytesData = new python.Bytearray(s, "UTF-8");
|
||||
return new Bytes(b.length, b);
|
||||
#elseif lua
|
||||
var bytes = [
|
||||
for (i in 0...lua.NativeStringTools.len(s)) {
|
||||
lua.NativeStringTools.byte(s, i + 1);
|
||||
}
|
||||
];
|
||||
return new Bytes(bytes.length, bytes);
|
||||
#else
|
||||
var a = new Array();
|
||||
// utf16-decode and utf8-encode
|
||||
var i = 0;
|
||||
while (i < s.length) {
|
||||
var c:Int = StringTools.fastCodeAt(s, i++);
|
||||
// surrogate pair
|
||||
if (0xD800 <= c && c <= 0xDBFF)
|
||||
c = (c - 0xD7C0 << 10) | (StringTools.fastCodeAt(s, i++) & 0x3FF);
|
||||
if (c <= 0x7F)
|
||||
a.push(c);
|
||||
else if (c <= 0x7FF) {
|
||||
a.push(0xC0 | (c >> 6));
|
||||
a.push(0x80 | (c & 63));
|
||||
} else if (c <= 0xFFFF) {
|
||||
a.push(0xE0 | (c >> 12));
|
||||
a.push(0x80 | ((c >> 6) & 63));
|
||||
a.push(0x80 | (c & 63));
|
||||
} else {
|
||||
a.push(0xF0 | (c >> 18));
|
||||
a.push(0x80 | ((c >> 12) & 63));
|
||||
a.push(0x80 | ((c >> 6) & 63));
|
||||
a.push(0x80 | (c & 63));
|
||||
}
|
||||
}
|
||||
return new Bytes(a.length, a);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `Bytes` representation of the given `BytesData`.
|
||||
**/
|
||||
public static function ofData(b:BytesData) {
|
||||
#if flash
|
||||
return new Bytes(b.length, b);
|
||||
#elseif neko
|
||||
return new Bytes(untyped __dollar__ssize(b), b);
|
||||
#elseif cs
|
||||
return new Bytes(b.Length, b);
|
||||
#else
|
||||
return new Bytes(b.length, b);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Converts the given hexadecimal `String` to `Bytes`. `s` must be a string of
|
||||
even length consisting only of hexadecimal digits. For example:
|
||||
`"0FDA14058916052309"`.
|
||||
**/
|
||||
public static function ofHex(s:String):Bytes {
|
||||
var len:Int = s.length;
|
||||
if ((len & 1) != 0)
|
||||
throw "Not a hex string (odd number of digits)";
|
||||
var ret:Bytes = Bytes.alloc(len >> 1);
|
||||
for (i in 0...ret.length) {
|
||||
var high = StringTools.fastCodeAt(s, i * 2);
|
||||
var low = StringTools.fastCodeAt(s, i * 2 + 1);
|
||||
high = (high & 0xF) + ((high & 0x40) >> 6) * 9;
|
||||
low = (low & 0xF) + ((low & 0x40) >> 6) * 9;
|
||||
ret.set(i, ((high << 4) | low) & 0xFF);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
Reads the `pos`-th byte of the given `b` bytes, in the most efficient way
|
||||
possible. Behavior when reading outside of the available data is
|
||||
unspecified.
|
||||
**/
|
||||
public inline static function fastGet(b:BytesData, pos:Int):Int {
|
||||
#if neko
|
||||
return untyped __dollar__sget(b, pos);
|
||||
#elseif flash
|
||||
return b[pos];
|
||||
#elseif cpp
|
||||
return untyped b.unsafeGet(pos);
|
||||
#elseif java
|
||||
return untyped b[pos] & 0xFF;
|
||||
#else
|
||||
return b[pos];
|
||||
#end
|
||||
}
|
||||
}
|
225
Kha/Tools/macos/std/haxe/io/BytesBuffer.hx
Normal file
225
Kha/Tools/macos/std/haxe/io/BytesBuffer.hx
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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 BytesBuffer {
|
||||
#if neko
|
||||
var b:Dynamic; // neko string buffer
|
||||
#elseif flash
|
||||
var b:flash.utils.ByteArray;
|
||||
#elseif cpp
|
||||
var b:BytesData;
|
||||
#elseif cs
|
||||
var b:cs.system.io.MemoryStream;
|
||||
#elseif java
|
||||
var b:java.io.ByteArrayOutputStream;
|
||||
#elseif python
|
||||
var b:python.Bytearray;
|
||||
#else
|
||||
var b:Array<Int>;
|
||||
#end
|
||||
|
||||
/** The length of the buffer in bytes. **/
|
||||
public var length(get, never):Int;
|
||||
|
||||
public function new() {
|
||||
#if neko
|
||||
b = untyped StringBuf.__make();
|
||||
#elseif flash
|
||||
b = new flash.utils.ByteArray();
|
||||
b.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
#elseif cpp
|
||||
b = new BytesData();
|
||||
#elseif cs
|
||||
b = new cs.system.io.MemoryStream();
|
||||
#elseif java
|
||||
b = new java.io.ByteArrayOutputStream();
|
||||
#elseif python
|
||||
b = new python.Bytearray();
|
||||
#else
|
||||
b = new Array();
|
||||
#end
|
||||
}
|
||||
|
||||
inline function get_length():Int {
|
||||
#if neko
|
||||
return untyped __dollar__ssize(StringBuf.__to_string(b));
|
||||
#elseif cs
|
||||
return haxe.Int64.toInt(b.Length);
|
||||
#elseif java
|
||||
return b.size();
|
||||
#else
|
||||
return b.length;
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function addByte(byte:Int) {
|
||||
#if neko
|
||||
untyped StringBuf.__add_char(b, byte);
|
||||
#elseif flash
|
||||
b.writeByte(byte);
|
||||
#elseif cpp
|
||||
b.push(untyped byte);
|
||||
#elseif cs
|
||||
b.WriteByte(cast byte);
|
||||
#elseif java
|
||||
b.write(byte);
|
||||
#elseif python
|
||||
b.append(byte);
|
||||
#else
|
||||
b.push(byte);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function add(src:Bytes) {
|
||||
#if neko
|
||||
untyped StringBuf.__add(b, src.getData());
|
||||
#elseif flash
|
||||
b.writeBytes(src.getData());
|
||||
#elseif cs
|
||||
b.Write(src.getData(), 0, src.length);
|
||||
#elseif java
|
||||
b.write(src.getData(), 0, src.length);
|
||||
#elseif js
|
||||
var b1 = b;
|
||||
var b2 = @:privateAccess src.b;
|
||||
for (i in 0...src.length)
|
||||
b.push(b2[i]);
|
||||
#elseif python
|
||||
b.extend(src.getData());
|
||||
#else
|
||||
var b1 = b;
|
||||
var b2 = src.getData();
|
||||
for (i in 0...src.length)
|
||||
b.push(b2[i]);
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function addString(v:String, ?encoding:Encoding) {
|
||||
#if neko
|
||||
untyped StringBuf.__add(b, v.__s);
|
||||
#elseif flash
|
||||
if (encoding == RawNative)
|
||||
b.writeMultiByte(v, "unicode")
|
||||
else
|
||||
b.writeUTFBytes(v);
|
||||
#elseif python
|
||||
b.extend(new python.Bytearray(v, "UTF-8"));
|
||||
#else
|
||||
add(Bytes.ofString(v, encoding));
|
||||
#end
|
||||
}
|
||||
|
||||
public #if flash inline #end function addInt32(v:Int) {
|
||||
#if flash
|
||||
b.writeUnsignedInt(v);
|
||||
#else
|
||||
addByte(v & 0xFF);
|
||||
addByte((v >> 8) & 0xFF);
|
||||
addByte((v >> 16) & 0xFF);
|
||||
addByte(v >>> 24);
|
||||
#end
|
||||
}
|
||||
|
||||
public #if flash inline #end function addInt64(v:haxe.Int64) {
|
||||
addInt32(v.low);
|
||||
addInt32(v.high);
|
||||
}
|
||||
|
||||
public inline function addFloat(v:Float) {
|
||||
#if flash
|
||||
b.writeFloat(v);
|
||||
#else
|
||||
addInt32(FPHelper.floatToI32(v));
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function addDouble(v:Float) {
|
||||
#if flash
|
||||
b.writeDouble(v);
|
||||
#else
|
||||
addInt64(FPHelper.doubleToI64(v));
|
||||
#end
|
||||
}
|
||||
|
||||
public inline function addBytes(src:Bytes, pos:Int, len:Int) {
|
||||
#if !neko
|
||||
if (pos < 0 || len < 0 || pos + len > src.length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
#if neko
|
||||
try
|
||||
untyped StringBuf.__add_sub(b, src.getData(), pos, len)
|
||||
catch (e:Dynamic)
|
||||
throw Error.OutsideBounds;
|
||||
#elseif flash
|
||||
if (len > 0)
|
||||
b.writeBytes(src.getData(), pos, len);
|
||||
#elseif cs
|
||||
b.Write(src.getData(), pos, len);
|
||||
#elseif java
|
||||
b.write(src.getData(), pos, len);
|
||||
#elseif js
|
||||
var b1 = b;
|
||||
var b2 = @:privateAccess src.b;
|
||||
for (i in pos...pos + len)
|
||||
b.push(b2[i]);
|
||||
#elseif python
|
||||
b.extend(python.Syntax.code("{0}[{1}:{2}]", src.getData(), pos, pos + len));
|
||||
#else
|
||||
var b1 = b;
|
||||
var b2 = src.getData();
|
||||
for (i in pos...pos + len)
|
||||
b.push(b2[i]);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns either a copy or a reference of the current bytes.
|
||||
Once called, the buffer should no longer be used.
|
||||
**/
|
||||
public function getBytes():Bytes
|
||||
untyped {
|
||||
#if neko
|
||||
var str = StringBuf.__to_string(b);
|
||||
var bytes = new Bytes(__dollar__ssize(str), str);
|
||||
#elseif flash
|
||||
var bytes = new Bytes(b.length, b);
|
||||
b.position = 0;
|
||||
#elseif cs
|
||||
var buf = b.GetBuffer();
|
||||
var bytes = new Bytes(cast b.Length, buf);
|
||||
#elseif java
|
||||
var buf = b.toByteArray();
|
||||
var bytes = new Bytes(buf.length, buf);
|
||||
#elseif python
|
||||
var bytes = new Bytes(b.length, b);
|
||||
#elseif js
|
||||
var bytes = new Bytes(new js.lib.Uint8Array(b).buffer);
|
||||
#else
|
||||
var bytes = new Bytes(b.length, b);
|
||||
#end
|
||||
b = null;
|
||||
return bytes;
|
||||
}
|
||||
}
|
70
Kha/Tools/macos/std/haxe/io/BytesData.hx
Normal file
70
Kha/Tools/macos/std/haxe/io/BytesData.hx
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
#if neko
|
||||
typedef BytesData = neko.NativeString;
|
||||
#elseif flash
|
||||
typedef BytesData = flash.utils.ByteArray;
|
||||
#elseif cpp
|
||||
typedef BytesData = Array<cpp.UInt8>;
|
||||
#elseif java
|
||||
typedef BytesData = java.NativeArray<java.StdTypes.Int8>;
|
||||
#elseif cs
|
||||
typedef BytesData = cs.NativeArray<cs.StdTypes.UInt8>;
|
||||
#elseif python
|
||||
typedef BytesData = python.Bytearray;
|
||||
#elseif js
|
||||
typedef BytesData = js.lib.ArrayBuffer;
|
||||
#elseif hl
|
||||
class BytesDataImpl {
|
||||
public var bytes:hl.Bytes;
|
||||
public var length:Int;
|
||||
|
||||
public function new(b, length) {
|
||||
this.bytes = b;
|
||||
this.length = length;
|
||||
}
|
||||
}
|
||||
|
||||
@:forward(bytes, length)
|
||||
abstract BytesDataAbstract(BytesDataImpl) {
|
||||
public inline function new(b, length) {
|
||||
this = new BytesDataImpl(b, length);
|
||||
}
|
||||
|
||||
@:arrayAccess inline function get(i:Int)
|
||||
return this.bytes[i];
|
||||
|
||||
@:arrayAccess inline function set(i:Int, v:Int)
|
||||
return this.bytes[i] = v;
|
||||
|
||||
@:to inline function toBytes():hl.Bytes {
|
||||
return this == null ? null : this.bytes;
|
||||
}
|
||||
}
|
||||
|
||||
typedef BytesData = BytesDataAbstract;
|
||||
#else
|
||||
typedef BytesData = Array<Int>;
|
||||
#end
|
217
Kha/Tools/macos/std/haxe/io/BytesInput.hx
Normal file
217
Kha/Tools/macos/std/haxe/io/BytesInput.hx
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* 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 BytesInput extends Input {
|
||||
var b:#if js js.lib.Uint8Array #elseif hl hl.Bytes #else BytesData #end;
|
||||
#if !flash
|
||||
var pos:Int;
|
||||
var len:Int;
|
||||
var totlen:Int;
|
||||
#end
|
||||
|
||||
/** The current position in the stream in bytes. */
|
||||
public var position(get, set):Int;
|
||||
|
||||
/** The length of the stream in bytes. */
|
||||
public var length(get, never):Int;
|
||||
|
||||
public function new(b:Bytes, ?pos:Int, ?len:Int) {
|
||||
if (pos == null)
|
||||
pos = 0;
|
||||
if (len == null)
|
||||
len = b.length - pos;
|
||||
if (pos < 0 || len < 0 || pos + len > b.length)
|
||||
throw Error.OutsideBounds;
|
||||
#if flash
|
||||
var ba = b.getData();
|
||||
ba.position = pos;
|
||||
if (len != ba.bytesAvailable) {
|
||||
// truncate
|
||||
this.b = new flash.utils.ByteArray();
|
||||
ba.readBytes(this.b, 0, len);
|
||||
} else
|
||||
this.b = ba;
|
||||
this.b.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
#else
|
||||
this.b = #if (js || hl) @:privateAccess b.b #else b.getData() #end;
|
||||
this.pos = pos;
|
||||
this.len = len;
|
||||
this.totlen = len;
|
||||
#end
|
||||
#if python
|
||||
bigEndian = false;
|
||||
#end
|
||||
}
|
||||
|
||||
inline function get_position():Int {
|
||||
#if flash
|
||||
return b.position;
|
||||
#else
|
||||
return pos;
|
||||
#end
|
||||
}
|
||||
|
||||
inline function get_length():Int {
|
||||
#if flash
|
||||
return b.length;
|
||||
#else
|
||||
return totlen;
|
||||
#end
|
||||
}
|
||||
|
||||
function set_position(p:Int):Int {
|
||||
if (p < 0)
|
||||
p = 0;
|
||||
else if (p > length)
|
||||
p = length;
|
||||
#if flash
|
||||
return b.position = p;
|
||||
#else
|
||||
len = totlen - p;
|
||||
return pos = p;
|
||||
#end
|
||||
}
|
||||
|
||||
public override function readByte():Int {
|
||||
#if flash
|
||||
return try b.readUnsignedByte() catch (e:Dynamic) throw new Eof();
|
||||
#else
|
||||
if (this.len == 0)
|
||||
throw new Eof();
|
||||
len--;
|
||||
#if neko
|
||||
return untyped __dollar__sget(b, pos++);
|
||||
#elseif cpp
|
||||
return untyped b[pos++];
|
||||
#elseif java
|
||||
return untyped b[pos++] & 0xFF;
|
||||
#elseif python // dodge https://github.com/HaxeFoundation/haxe/issues/5080
|
||||
var b = b[pos];
|
||||
pos++;
|
||||
return b;
|
||||
#else
|
||||
return b[pos++];
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
public override function readBytes(buf:Bytes, pos:Int, len:Int):Int {
|
||||
#if !neko
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
#if flash
|
||||
var avail:Int = b.bytesAvailable;
|
||||
if (len > avail && avail > 0)
|
||||
len = avail;
|
||||
try
|
||||
b.readBytes(buf.getData(), pos, len)
|
||||
catch (e:Dynamic)
|
||||
throw new Eof();
|
||||
#elseif java
|
||||
var avail:Int = this.len;
|
||||
if (len > avail)
|
||||
len = avail;
|
||||
if (len == 0)
|
||||
throw new Eof();
|
||||
java.lang.System.arraycopy(this.b, this.pos, buf.getData(), pos, len);
|
||||
this.pos += len;
|
||||
this.len -= len;
|
||||
#elseif cs
|
||||
var avail:Int = this.len;
|
||||
if (len > avail)
|
||||
len = avail;
|
||||
if (len == 0)
|
||||
throw new Eof();
|
||||
cs.system.Array.Copy(this.b, this.pos, buf.getData(), pos, len);
|
||||
this.pos += len;
|
||||
this.len -= len;
|
||||
#else
|
||||
if (this.len == 0 && len > 0)
|
||||
throw new Eof();
|
||||
if (this.len < len)
|
||||
len = this.len;
|
||||
#if neko
|
||||
try
|
||||
untyped __dollar__sblit(buf.getData(), pos, b, this.pos, len)
|
||||
catch (e:Dynamic)
|
||||
throw Error.OutsideBounds;
|
||||
#elseif hl
|
||||
@:privateAccess buf.b.blit(pos, b, this.pos, len);
|
||||
#else
|
||||
var b1 = b;
|
||||
var b2 = #if js @:privateAccess buf.b #else buf.getData() #end;
|
||||
for (i in 0...len)
|
||||
b2[pos + i] = b1[this.pos + i];
|
||||
#end
|
||||
this.pos += len;
|
||||
this.len -= len;
|
||||
#end
|
||||
return len;
|
||||
}
|
||||
|
||||
#if flash
|
||||
@:dox(hide)
|
||||
override function set_bigEndian(e) {
|
||||
bigEndian = e;
|
||||
b.endian = e ? flash.utils.Endian.BIG_ENDIAN : flash.utils.Endian.LITTLE_ENDIAN;
|
||||
return e;
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readFloat() {
|
||||
return try b.readFloat() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readDouble() {
|
||||
return try b.readDouble() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readInt8() {
|
||||
return try b.readByte() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readInt16() {
|
||||
return try b.readShort() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readUInt16():Int {
|
||||
return try b.readUnsignedShort() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readInt32():Int {
|
||||
return try b.readInt() catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function readString(len:Int, ?encoding:Encoding) {
|
||||
return try encoding == RawNative ? b.readMultiByte(len, "unicode") : b.readUTFBytes(len) catch (e:Dynamic) throw new Eof();
|
||||
}
|
||||
#end
|
||||
}
|
146
Kha/Tools/macos/std/haxe/io/BytesOutput.hx
Normal file
146
Kha/Tools/macos/std/haxe/io/BytesOutput.hx
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 BytesOutput extends Output {
|
||||
#if flash
|
||||
var b:flash.utils.ByteArray;
|
||||
#else
|
||||
var b:BytesBuffer;
|
||||
#end
|
||||
|
||||
/** The length of the stream in bytes. **/
|
||||
public var length(get, never):Int;
|
||||
|
||||
public function new() {
|
||||
#if flash
|
||||
b = new flash.utils.ByteArray();
|
||||
b.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
#else
|
||||
b = new BytesBuffer();
|
||||
#end
|
||||
#if python
|
||||
bigEndian = false;
|
||||
#end
|
||||
}
|
||||
|
||||
inline function get_length():Int {
|
||||
return b.length;
|
||||
}
|
||||
|
||||
override function writeByte(c) {
|
||||
#if flash
|
||||
b.writeByte(c);
|
||||
#else
|
||||
b.addByte(c);
|
||||
#end
|
||||
}
|
||||
|
||||
override function writeBytes(buf:Bytes, pos, len):Int {
|
||||
#if flash
|
||||
if (pos < 0 || len < 0 || pos + len > buf.length)
|
||||
throw Error.OutsideBounds;
|
||||
b.writeBytes(buf.getData(), pos, len);
|
||||
#else
|
||||
b.addBytes(buf, pos, len);
|
||||
#end
|
||||
return len;
|
||||
}
|
||||
|
||||
#if flash
|
||||
// optimized operations
|
||||
|
||||
@:dox(hide)
|
||||
override function set_bigEndian(e) {
|
||||
bigEndian = e;
|
||||
b.endian = e ? flash.utils.Endian.BIG_ENDIAN : flash.utils.Endian.LITTLE_ENDIAN;
|
||||
return e;
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeFloat(f:Float) {
|
||||
b.writeFloat(f);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeDouble(f:Float) {
|
||||
b.writeDouble(f);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeInt8(x:Int) {
|
||||
if (x < -0x80 || x >= 0x80)
|
||||
throw Error.Overflow;
|
||||
b.writeByte(x);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeInt16(x:Int) {
|
||||
if (x < -0x8000 || x >= 0x8000)
|
||||
throw Error.Overflow;
|
||||
b.writeShort(x);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeUInt16(x:Int) {
|
||||
if (x < 0 || x >= 0x10000)
|
||||
throw Error.Overflow;
|
||||
b.writeShort(x);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeInt32(x:Int) {
|
||||
b.writeInt(x);
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function prepare(size:Int) {
|
||||
if (size > 0)
|
||||
b[size - 1] = b[size - 1];
|
||||
}
|
||||
|
||||
@:dox(hide)
|
||||
override function writeString(s:String, ?encoding:Encoding) {
|
||||
if (encoding == RawNative)
|
||||
b.writeMultiByte(s, "unicode");
|
||||
else
|
||||
b.writeUTFBytes(s);
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
Returns the `Bytes` of this output.
|
||||
|
||||
This function should not be called more than once on a given
|
||||
`BytesOutput` instance.
|
||||
**/
|
||||
public function getBytes():Bytes {
|
||||
#if flash
|
||||
var bytes = b;
|
||||
b = null;
|
||||
return untyped new Bytes(bytes.length, bytes);
|
||||
#else
|
||||
return b.getBytes();
|
||||
#end
|
||||
}
|
||||
}
|
35
Kha/Tools/macos/std/haxe/io/Encoding.hx
Normal file
35
Kha/Tools/macos/std/haxe/io/Encoding.hx
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
String binary encoding supported by Haxe I/O
|
||||
**/
|
||||
enum Encoding {
|
||||
UTF8;
|
||||
|
||||
/**
|
||||
Output the string the way the platform represent it in memory. This is the most efficient but is platform-specific
|
||||
**/
|
||||
RawNative;
|
||||
}
|
35
Kha/Tools/macos/std/haxe/io/Eof.hx
Normal file
35
Kha/Tools/macos/std/haxe/io/Eof.hx
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
This exception is raised when reading while data is no longer available in the `haxe.io.Input`.
|
||||
**/
|
||||
class Eof {
|
||||
public function new() {}
|
||||
|
||||
@:ifFeature("haxe.io.Eof.*")
|
||||
function toString() {
|
||||
return "Eof";
|
||||
}
|
||||
}
|
43
Kha/Tools/macos/std/haxe/io/Error.hx
Normal file
43
Kha/Tools/macos/std/haxe/io/Error.hx
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
The possible IO errors that can occur
|
||||
**/
|
||||
#if eval
|
||||
@:keep
|
||||
#end
|
||||
enum Error {
|
||||
/** The IO is set into nonblocking mode and some data cannot be read or written **/
|
||||
Blocked;
|
||||
|
||||
/** An integer value is outside its allowed range **/
|
||||
Overflow;
|
||||
|
||||
/** An operation on Bytes is outside of its valid range **/
|
||||
OutsideBounds;
|
||||
|
||||
/** Other errors **/
|
||||
Custom(e:Dynamic);
|
||||
}
|
362
Kha/Tools/macos/std/haxe/io/FPHelper.hx
Normal file
362
Kha/Tools/macos/std/haxe/io/FPHelper.hx
Normal file
@ -0,0 +1,362 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
Helper that converts between floating point and binary representation.
|
||||
Always works in low-endian encoding.
|
||||
**/
|
||||
class FPHelper {
|
||||
#if neko_v21
|
||||
// stored in helper
|
||||
#elseif neko
|
||||
static var i64tmp = new sys.thread.Tls<Int64>();
|
||||
#elseif !(java || cs || cpp)
|
||||
static var i64tmp = Int64.ofInt(0);
|
||||
|
||||
static inline var LN2 = 0.6931471805599453; // Math.log(2)
|
||||
|
||||
static inline function _i32ToFloat(i:Int):Float {
|
||||
var sign = 1 - ((i >>> 31) << 1);
|
||||
var e = (i >> 23) & 0xff;
|
||||
if (e == 255)
|
||||
return i & 0x7fffff == 0 ? (sign > 0 ? Math.POSITIVE_INFINITY : Math.NEGATIVE_INFINITY) : Math.NaN;
|
||||
var m = e == 0 ? (i & 0x7fffff) << 1 : (i & 0x7fffff) | 0x800000;
|
||||
return sign * m * Math.pow(2, e - 150);
|
||||
}
|
||||
|
||||
static inline function _i64ToDouble(lo:Int, hi:Int):Float {
|
||||
var sign = 1 - ((hi >>> 31) << 1);
|
||||
var e = (hi >> 20) & 0x7ff;
|
||||
if (e == 2047)
|
||||
return lo == 0 && (hi & 0xFFFFF) == 0 ? (sign > 0 ? Math.POSITIVE_INFINITY : Math.NEGATIVE_INFINITY) : Math.NaN;
|
||||
var m = 2.220446049250313e-16 * ((hi & 0xFFFFF) * 4294967296. + (lo >>> 31) * 2147483648. + (lo & 0x7FFFFFFF));
|
||||
m = e == 0 ? m * 2.0 : m + 1.0;
|
||||
return sign * m * Math.pow(2, e - 1023);
|
||||
}
|
||||
|
||||
static inline function _floatToI32(f:Float):Int {
|
||||
if (f == 0)
|
||||
return 0;
|
||||
var af = f < 0 ? -f : f;
|
||||
var exp = Math.floor(Math.log(af) / LN2);
|
||||
if (exp > 127) {
|
||||
return 0x7F800000;
|
||||
} else {
|
||||
if (exp <= -127) {
|
||||
exp = -127;
|
||||
af *= 7.1362384635298e+44; // af * 0.5 * 0x800000 / Math.pow(2, -127)
|
||||
} else {
|
||||
af = (af / Math.pow(2, exp) - 1.0) * 0x800000;
|
||||
}
|
||||
return (f < 0 ? 0x80000000 : 0) | ((exp + 127) << 23) | Math.round(af);
|
||||
}
|
||||
}
|
||||
|
||||
static inline function _doubleToI64(v:Float):Int64@:privateAccess {
|
||||
var i64 = i64tmp;
|
||||
if (v == 0) {
|
||||
i64.set_low(0);
|
||||
i64.set_high(0);
|
||||
} else if (!Math.isFinite(v)) {
|
||||
i64.set_low(0);
|
||||
i64.set_high(v > 0 ? 0x7FF00000 : 0xFFF00000);
|
||||
} else {
|
||||
var av = v < 0 ? -v : v;
|
||||
var exp = Math.floor(Math.log(av) / LN2);
|
||||
if (exp > 1023) {
|
||||
i64.set_low(0xFFFFFFFF);
|
||||
i64.set_high(0x7FEFFFFF);
|
||||
} else {
|
||||
if (exp <= -1023) {
|
||||
exp = -1023;
|
||||
av = av / 2.2250738585072014e-308;
|
||||
} else {
|
||||
av = av / Math.pow(2, exp) - 1.0;
|
||||
}
|
||||
var sig = Math.fround(av * 4503599627370496.); // 2^52
|
||||
// Note: If "sig" is outside of the signed Int32 range, the result is unspecified in HL, C#, Java and Neko,
|
||||
var sig_l = Std.int(sig);
|
||||
var sig_h = Std.int(sig / 4294967296.0);
|
||||
i64.set_low(sig_l);
|
||||
i64.set_high((v < 0 ? 0x80000000 : 0) | ((exp + 1023) << 20) | sig_h);
|
||||
}
|
||||
}
|
||||
return i64;
|
||||
}
|
||||
#end
|
||||
|
||||
#if neko
|
||||
#if neko_v21
|
||||
static var helpers = new sys.thread.Tls<neko.NativeArray<Dynamic>>();
|
||||
#else
|
||||
static var helperf = new sys.thread.Tls<neko.NativeString>();
|
||||
static var helperd = new sys.thread.Tls<neko.NativeString>();
|
||||
static var _float_of_bytes = neko.Lib.load("std", "float_of_bytes", 2);
|
||||
static var _double_of_bytes = neko.Lib.load("std", "double_of_bytes", 2);
|
||||
static var _float_bytes = neko.Lib.load("std", "float_bytes", 2);
|
||||
static var _double_bytes = neko.Lib.load("std", "double_bytes", 2);
|
||||
#end
|
||||
#elseif flash
|
||||
static var helper = {
|
||||
var b = new flash.utils.ByteArray();
|
||||
b.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
b;
|
||||
}
|
||||
#elseif js
|
||||
static var helper = new js.lib.DataView(new js.lib.ArrayBuffer(8));
|
||||
#end
|
||||
|
||||
#if neko_v21
|
||||
inline
|
||||
#end
|
||||
public static function i32ToFloat(i:Int):Float {
|
||||
#if neko
|
||||
#if neko_v21
|
||||
return untyped $itof(i, false);
|
||||
#else
|
||||
var helper = helperf.value;
|
||||
if (helper == null)
|
||||
helperf.value = helper = neko.NativeString.alloc(4);
|
||||
untyped $sset(helper, 0, i & 0xFF);
|
||||
untyped $sset(helper, 1, (i >> 8) & 0xFF);
|
||||
untyped $sset(helper, 2, (i >> 16) & 0xFF);
|
||||
untyped $sset(helper, 3, i >>> 24);
|
||||
return _float_of_bytes(helper, false);
|
||||
#end
|
||||
#elseif cpp
|
||||
return untyped __global__.__hxcpp_reinterpret_le_int32_as_float32(i);
|
||||
#elseif cs
|
||||
var helper = new SingleHelper(0);
|
||||
if (cs.system.BitConverter.IsLittleEndian) {
|
||||
helper.i = i;
|
||||
} else {
|
||||
helper.i = ((i >>> 24) & 0xFF) | (((i >> 16) & 0xFF) << 8) | (((i >> 8) & 0xFF) << 16) | ((i & 0xFF) << 24);
|
||||
}
|
||||
|
||||
return helper.f;
|
||||
#elseif java
|
||||
return java.lang.Float.FloatClass.intBitsToFloat(i);
|
||||
#elseif flash
|
||||
var helper = helper;
|
||||
helper.position = 0;
|
||||
helper.writeUnsignedInt(i);
|
||||
helper.position = 0;
|
||||
return helper.readFloat();
|
||||
#elseif js
|
||||
helper.setInt32(0, i, true);
|
||||
return helper.getFloat32(0, true);
|
||||
#else
|
||||
return _i32ToFloat(i);
|
||||
#end
|
||||
}
|
||||
|
||||
#if neko_v21
|
||||
inline
|
||||
#end
|
||||
public static function floatToI32(f:Float):Int {
|
||||
#if neko
|
||||
#if neko_v21
|
||||
return untyped $ftoi(f, false);
|
||||
#else
|
||||
var r = _float_bytes(f, false);
|
||||
return untyped $sget(r, 0) | ($sget(r, 1) << 8) | ($sget(r, 2) << 16) | ($sget(r, 3) << 24);
|
||||
#end
|
||||
#elseif cpp
|
||||
return untyped __global__.__hxcpp_reinterpret_float32_as_le_int32(f);
|
||||
#elseif cs
|
||||
var helper = new SingleHelper(f);
|
||||
if (cs.system.BitConverter.IsLittleEndian) {
|
||||
return helper.i;
|
||||
} else {
|
||||
var i = helper.i;
|
||||
return ((i >>> 24) & 0xFF) | (((i >> 16) & 0xFF) << 8) | (((i >> 8) & 0xFF) << 16) | ((i & 0xFF) << 24);
|
||||
}
|
||||
#elseif java
|
||||
return java.lang.Float.FloatClass.floatToRawIntBits(f);
|
||||
#elseif flash
|
||||
var helper = helper;
|
||||
helper.position = 0;
|
||||
helper.writeFloat(f);
|
||||
helper.position = 0;
|
||||
return helper.readUnsignedInt();
|
||||
#elseif js
|
||||
helper.setFloat32(0, f, true);
|
||||
return helper.getInt32(0, true);
|
||||
#else
|
||||
return _floatToI32(f);
|
||||
#end
|
||||
}
|
||||
|
||||
#if neko_v21
|
||||
inline
|
||||
#end
|
||||
public static function i64ToDouble(low:Int, high:Int):Float {
|
||||
#if neko
|
||||
#if neko_v21
|
||||
return untyped $itod(low, high, false);
|
||||
#else
|
||||
var helper = helperd.value;
|
||||
if (helper == null)
|
||||
helperd.value = helper = neko.NativeString.alloc(8);
|
||||
untyped $sset(helper, 0, low & 0xFF);
|
||||
untyped $sset(helper, 1, (low >> 8) & 0xFF);
|
||||
untyped $sset(helper, 2, (low >> 16) & 0xFF);
|
||||
untyped $sset(helper, 3, low >>> 24);
|
||||
untyped $sset(helper, 4, high & 0xFF);
|
||||
untyped $sset(helper, 5, (high >> 8) & 0xFF);
|
||||
untyped $sset(helper, 6, (high >> 16) & 0xFF);
|
||||
untyped $sset(helper, 7, high >>> 24);
|
||||
return _double_of_bytes(helper, false);
|
||||
#end
|
||||
#elseif cpp
|
||||
return untyped __global__.__hxcpp_reinterpret_le_int32s_as_float64(low, high);
|
||||
#elseif cs
|
||||
var helper = new FloatHelper(0);
|
||||
if (cs.system.BitConverter.IsLittleEndian) {
|
||||
helper.i = haxe.Int64.make(high, low);
|
||||
} else {
|
||||
var i1 = high, i2 = low;
|
||||
var j2 = ((i1 >>> 24) & 0xFF) | (((i1 >> 16) & 0xFF) << 8) | (((i1 >> 8) & 0xFF) << 16) | ((i1 & 0xFF) << 24);
|
||||
var j1 = ((i2 >>> 24) & 0xFF) | (((i2 >> 16) & 0xFF) << 8) | (((i2 >> 8) & 0xFF) << 16) | ((i2 & 0xFF) << 24);
|
||||
helper.i = haxe.Int64.make(j1, j2);
|
||||
}
|
||||
return helper.f;
|
||||
#elseif java
|
||||
return java.lang.Double.DoubleClass.longBitsToDouble(Int64.make(high, low));
|
||||
#elseif flash
|
||||
var helper = helper;
|
||||
helper.position = 0;
|
||||
helper.writeUnsignedInt(low);
|
||||
helper.writeUnsignedInt(high);
|
||||
helper.position = 0;
|
||||
return helper.readDouble();
|
||||
#elseif js
|
||||
helper.setInt32(0, low, true);
|
||||
helper.setInt32(4, high, true);
|
||||
return helper.getFloat64(0, true);
|
||||
#else
|
||||
return _i64ToDouble(low, high);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an Int64 representing the bytes representation of the double precision IEEE float value.
|
||||
WARNING : for performance reason, the same Int64 value might be reused every time. Copy its low/high values before calling again.
|
||||
We still ensure that this is safe to use in a multithread environment
|
||||
**/
|
||||
public static function doubleToI64(v:Float):Int64 {
|
||||
#if neko
|
||||
#if neko_v21
|
||||
var helper = helpers.value;
|
||||
if (helper == null) {
|
||||
helpers.value = helper = neko.NativeArray.alloc(2);
|
||||
helper[0] = neko.NativeArray.alloc(2);
|
||||
helper[1] = haxe.Int64.ofInt(0);
|
||||
}
|
||||
var i64:haxe.Int64 = helper[1], int2 = helper[0];
|
||||
untyped $dtoi(v, int2, false);
|
||||
@:privateAccess {
|
||||
i64.set_low(int2[0]);
|
||||
i64.set_high(int2[1]);
|
||||
}
|
||||
return i64;
|
||||
#else
|
||||
var r = _double_bytes(v, false), i64 = i64tmp.value;
|
||||
if (i64 == null)
|
||||
i64 = i64tmp.value = haxe.Int64.ofInt(0);
|
||||
@:privateAccess {
|
||||
i64.set_low(untyped $sget(r, 0) | ($sget(r, 1) << 8) | ($sget(r, 2) << 16) | ($sget(r, 3) << 24));
|
||||
i64.set_high(untyped $sget(r, 4) | ($sget(r, 5) << 8) | ($sget(r, 6) << 16) | ($sget(r, 7) << 24));
|
||||
}
|
||||
return i64;
|
||||
#end
|
||||
#elseif cpp
|
||||
return Int64.make(untyped __global__.__hxcpp_reinterpret_float64_as_le_int32_high(v),
|
||||
untyped __global__.__hxcpp_reinterpret_float64_as_le_int32_low(v));
|
||||
#elseif java
|
||||
return java.lang.Double.DoubleClass.doubleToRawLongBits(v);
|
||||
#elseif cs
|
||||
var helper = new FloatHelper(v);
|
||||
if (cs.system.BitConverter.IsLittleEndian) {
|
||||
return helper.i;
|
||||
} else {
|
||||
var i = helper.i;
|
||||
var i1 = haxe.Int64.getHigh(i), i2 = haxe.Int64.getLow(i);
|
||||
var j2 = ((i1 >>> 24) & 0xFF) | (((i1 >> 16) & 0xFF) << 8) | (((i1 >> 8) & 0xFF) << 16) | ((i1 & 0xFF) << 24);
|
||||
var j1 = ((i2 >>> 24) & 0xFF) | (((i2 >> 16) & 0xFF) << 8) | (((i2 >> 8) & 0xFF) << 16) | ((i2 & 0xFF) << 24);
|
||||
|
||||
return haxe.Int64.make(j1, j2);
|
||||
}
|
||||
#elseif flash
|
||||
var helper = helper;
|
||||
helper.position = 0;
|
||||
helper.writeDouble(v);
|
||||
helper.position = 0;
|
||||
var i64 = i64tmp;
|
||||
@:privateAccess {
|
||||
i64.set_low(cast helper.readUnsignedInt());
|
||||
i64.set_high(cast helper.readUnsignedInt());
|
||||
}
|
||||
return i64;
|
||||
#elseif js
|
||||
var i64 = i64tmp;
|
||||
helper.setFloat64(0, v, true);
|
||||
@:privateAccess {
|
||||
i64.set_low(helper.getInt32(0, true));
|
||||
i64.set_high(helper.getInt32(4, true));
|
||||
}
|
||||
return i64;
|
||||
#else
|
||||
return _doubleToI64(v);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
#if cs
|
||||
@:meta(System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit))
|
||||
@:nativeGen @:struct private class SingleHelper {
|
||||
@:meta(System.Runtime.InteropServices.FieldOffset(0))
|
||||
public var i:Int;
|
||||
@:meta(System.Runtime.InteropServices.FieldOffset(0))
|
||||
public var f:Single;
|
||||
|
||||
public function new(f:Single) {
|
||||
this.i = 0;
|
||||
this.f = f;
|
||||
}
|
||||
}
|
||||
|
||||
@:meta(System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit))
|
||||
@:nativeGen @:struct private class FloatHelper {
|
||||
@:meta(System.Runtime.InteropServices.FieldOffset(0))
|
||||
public var i:haxe.Int64;
|
||||
@:meta(System.Runtime.InteropServices.FieldOffset(0))
|
||||
public var f:Float;
|
||||
|
||||
public function new(f:Float) {
|
||||
this.i = haxe.Int64.ofInt(0);
|
||||
this.f = f;
|
||||
}
|
||||
}
|
||||
#end
|
87
Kha/Tools/macos/std/haxe/io/Float32Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/Float32Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef Float32ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract Float32Array(Float32ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 4;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength >> 2;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int):Float {
|
||||
return this.bytes.getFloat((index << 2) + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:Float):Float {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.setFloat((index << 2) + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):Float32Array {
|
||||
return fromData(this.sub(begin << 2, length == null ? null : length << 2));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):Float32Array {
|
||||
return fromData(this.subarray(begin == null ? null : begin << 2, end == null ? null : end << 2));
|
||||
}
|
||||
|
||||
public inline function getData():Float32ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:Float32ArrayData):Float32Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<Float>, pos = 0, ?length:Int):Float32Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new Float32Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos = 0, ?length:Int):Float32Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, (length == null ? (bytes.length - bytePos) >> 2 : length) << 2).getData());
|
||||
}
|
||||
}
|
87
Kha/Tools/macos/std/haxe/io/Float64Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/Float64Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef Float64ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract Float64Array(Float64ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 8;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength >> 3;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int):Float {
|
||||
return this.bytes.getDouble((index << 3) + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:Float):Float {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.setDouble((index << 3) + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):Float64Array {
|
||||
return fromData(this.sub(begin << 3, length == null ? null : length << 3));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):Float64Array {
|
||||
return fromData(this.subarray(begin == null ? null : begin << 3, end == null ? null : end << 3));
|
||||
}
|
||||
|
||||
public inline function getData():Float64ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:Float64ArrayData):Float64Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<Float>, pos = 0, ?length:Int):Float64Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new Float64Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos = 0, ?length:Int):Float64Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, (length == null ? (bytes.length - bytePos) >> 3 : length) << 3).getData());
|
||||
}
|
||||
}
|
331
Kha/Tools/macos/std/haxe/io/Input.hx
Normal file
331
Kha/Tools/macos/std/haxe/io/Input.hx
Normal file
@ -0,0 +1,331 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
An Input is an abstract reader. See other classes in the `haxe.io` package
|
||||
for several possible implementations.
|
||||
|
||||
All functions which read data throw `Eof` when the end of the stream
|
||||
is reached.
|
||||
**/
|
||||
class Input {
|
||||
/**
|
||||
Endianness (word byte order) used when reading numbers.
|
||||
|
||||
If `true`, big-endian is used, otherwise `little-endian` is used.
|
||||
**/
|
||||
public var bigEndian(default, set):Bool;
|
||||
|
||||
#if cs
|
||||
private var helper:BytesData;
|
||||
#elseif java
|
||||
private var helper:java.nio.ByteBuffer;
|
||||
#end
|
||||
|
||||
/**
|
||||
Read and return one byte.
|
||||
**/
|
||||
public function readByte():Int {
|
||||
#if cpp
|
||||
throw new haxe.exceptions.NotImplementedException();
|
||||
#else
|
||||
return throw new haxe.exceptions.NotImplementedException();
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Read `len` bytes and write them into `s` to the position specified by `pos`.
|
||||
|
||||
Returns the actual length of read data that can be smaller than `len`.
|
||||
|
||||
See `readFullBytes` that tries to read the exact amount of specified bytes.
|
||||
**/
|
||||
public function readBytes(s:Bytes, pos:Int, len:Int):Int {
|
||||
var k = len;
|
||||
var b = #if (js || hl) @:privateAccess s.b #else s.getData() #end;
|
||||
if (pos < 0 || len < 0 || pos + len > s.length)
|
||||
throw Error.OutsideBounds;
|
||||
try {
|
||||
while (k > 0) {
|
||||
#if neko
|
||||
untyped __dollar__sset(b, pos, readByte());
|
||||
#elseif php
|
||||
b.set(pos, readByte());
|
||||
#elseif cpp
|
||||
b[pos] = untyped readByte();
|
||||
#else
|
||||
b[pos] = cast readByte();
|
||||
#end
|
||||
pos++;
|
||||
k--;
|
||||
}
|
||||
} catch (eof:haxe.io.Eof) {}
|
||||
return len - k;
|
||||
}
|
||||
|
||||
/**
|
||||
Close the input source.
|
||||
|
||||
Behaviour while reading after calling this method is unspecified.
|
||||
**/
|
||||
public function close():Void {}
|
||||
|
||||
function set_bigEndian(b:Bool):Bool {
|
||||
bigEndian = b;
|
||||
return b;
|
||||
}
|
||||
|
||||
/* ------------------ API ------------------ */
|
||||
/**
|
||||
Read and return all available data.
|
||||
|
||||
The `bufsize` optional argument specifies the size of chunks by
|
||||
which data is read. Its default value is target-specific.
|
||||
**/
|
||||
public function readAll(?bufsize:Int):Bytes {
|
||||
if (bufsize == null)
|
||||
#if php
|
||||
bufsize = 8192; // default value for PHP and max under certain circumstances
|
||||
#else
|
||||
bufsize = (1 << 14); // 16 Ko
|
||||
#end
|
||||
|
||||
var buf = Bytes.alloc(bufsize);
|
||||
var total = new haxe.io.BytesBuffer();
|
||||
try {
|
||||
while (true) {
|
||||
var len = readBytes(buf, 0, bufsize);
|
||||
if (len == 0)
|
||||
throw Error.Blocked;
|
||||
total.addBytes(buf, 0, len);
|
||||
}
|
||||
} catch (e:Eof) {}
|
||||
return total.getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
Read `len` bytes and write them into `s` to the position specified by `pos`.
|
||||
|
||||
Unlike `readBytes`, this method tries to read the exact `len` amount of bytes.
|
||||
**/
|
||||
public function readFullBytes(s:Bytes, pos:Int, len:Int):Void {
|
||||
while (len > 0) {
|
||||
var k = readBytes(s, pos, len);
|
||||
if (k == 0)
|
||||
throw Error.Blocked;
|
||||
pos += k;
|
||||
len -= k;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Read and return `nbytes` bytes.
|
||||
**/
|
||||
public function read(nbytes:Int):Bytes {
|
||||
var s = Bytes.alloc(nbytes);
|
||||
var p = 0;
|
||||
while (nbytes > 0) {
|
||||
var k = readBytes(s, p, nbytes);
|
||||
if (k == 0)
|
||||
throw Error.Blocked;
|
||||
p += k;
|
||||
nbytes -= k;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
Read a string until a character code specified by `end` is occurred.
|
||||
|
||||
The final character is not included in the resulting string.
|
||||
**/
|
||||
public function readUntil(end:Int):String {
|
||||
var buf = new BytesBuffer();
|
||||
var last:Int;
|
||||
while ((last = readByte()) != end)
|
||||
buf.addByte(last);
|
||||
return buf.getBytes().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Read a line of text separated by CR and/or LF bytes.
|
||||
|
||||
The CR/LF characters are not included in the resulting string.
|
||||
**/
|
||||
public function readLine():String {
|
||||
var buf = new BytesBuffer();
|
||||
var last:Int;
|
||||
var s;
|
||||
try {
|
||||
while ((last = readByte()) != 10)
|
||||
buf.addByte(last);
|
||||
s = buf.getBytes().toString();
|
||||
if (s.charCodeAt(s.length - 1) == 13)
|
||||
s = s.substr(0, -1);
|
||||
} catch (e:Eof) {
|
||||
s = buf.getBytes().toString();
|
||||
if (s.length == 0)
|
||||
#if neko neko.Lib.rethrow #else throw #end (e);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 32-bit floating point number.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readFloat():Float {
|
||||
return FPHelper.i32ToFloat(readInt32());
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 64-bit double-precision floating point number.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readDouble():Float {
|
||||
var i1 = readInt32();
|
||||
var i2 = readInt32();
|
||||
return bigEndian ? FPHelper.i64ToDouble(i2, i1) : FPHelper.i64ToDouble(i1, i2);
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 8-bit signed integer.
|
||||
**/
|
||||
public function readInt8():Int {
|
||||
var n = readByte();
|
||||
if (n >= 128)
|
||||
return n - 256;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 16-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readInt16():Int {
|
||||
var ch1 = readByte();
|
||||
var ch2 = readByte();
|
||||
var n = bigEndian ? ch2 | (ch1 << 8) : ch1 | (ch2 << 8);
|
||||
if (n & 0x8000 != 0)
|
||||
return n - 0x10000;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 16-bit unsigned integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readUInt16():Int {
|
||||
var ch1 = readByte();
|
||||
var ch2 = readByte();
|
||||
return bigEndian ? ch2 | (ch1 << 8) : ch1 | (ch2 << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 24-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readInt24():Int {
|
||||
var ch1 = readByte();
|
||||
var ch2 = readByte();
|
||||
var ch3 = readByte();
|
||||
var n = bigEndian ? ch3 | (ch2 << 8) | (ch1 << 16) : ch1 | (ch2 << 8) | (ch3 << 16);
|
||||
if (n & 0x800000 != 0)
|
||||
return n - 0x1000000;
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 24-bit unsigned integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readUInt24():Int {
|
||||
var ch1 = readByte();
|
||||
var ch2 = readByte();
|
||||
var ch3 = readByte();
|
||||
return bigEndian ? ch3 | (ch2 << 8) | (ch1 << 16) : ch1 | (ch2 << 8) | (ch3 << 16);
|
||||
}
|
||||
|
||||
/**
|
||||
Read a 32-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function readInt32():Int {
|
||||
var ch1 = readByte();
|
||||
var ch2 = readByte();
|
||||
var ch3 = readByte();
|
||||
var ch4 = readByte();
|
||||
#if (php || python)
|
||||
// php will overflow integers. Convert them back to signed 32-bit ints.
|
||||
var n = bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
|
||||
if (n & 0x80000000 != 0)
|
||||
return (n | 0x80000000);
|
||||
else
|
||||
return n;
|
||||
#elseif lua
|
||||
var n = bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
|
||||
return lua.Boot.clampInt32(n);
|
||||
#else
|
||||
return bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Read and `len` bytes as a string.
|
||||
**/
|
||||
public function readString(len:Int, ?encoding:Encoding):String {
|
||||
var b = Bytes.alloc(len);
|
||||
readFullBytes(b, 0, len);
|
||||
#if neko
|
||||
return neko.Lib.stringReference(b);
|
||||
#else
|
||||
return b.getString(0, len, encoding);
|
||||
#end
|
||||
}
|
||||
|
||||
#if neko
|
||||
static var _float_of_bytes = neko.Lib.load("std", "float_of_bytes", 2);
|
||||
static var _double_of_bytes = neko.Lib.load("std", "double_of_bytes", 2);
|
||||
|
||||
static function __init__()
|
||||
untyped {
|
||||
Input.prototype.bigEndian = false;
|
||||
}
|
||||
#end
|
||||
|
||||
#if (flash || js || python)
|
||||
function getDoubleSig(bytes:Array<Int>) {
|
||||
return (((bytes[1] & 0xF) << 16) | (bytes[2] << 8) | bytes[3]) * 4294967296.
|
||||
+ (bytes[4] >> 7) * 2147483648
|
||||
+ (((bytes[4] & 0x7F) << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]);
|
||||
}
|
||||
#end
|
||||
}
|
87
Kha/Tools/macos/std/haxe/io/Int32Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/Int32Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef Int32ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract Int32Array(Int32ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 4;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength >> 2;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int):Int {
|
||||
return this.bytes.getInt32((index << 2) + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:Int):Int {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.setInt32((index << 2) + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):Int32Array {
|
||||
return fromData(this.sub(begin << 2, length == null ? null : length << 2));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):Int32Array {
|
||||
return fromData(this.subarray(begin == null ? null : begin << 2, end == null ? null : end << 2));
|
||||
}
|
||||
|
||||
public inline function getData():Int32ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:Int32ArrayData):Int32Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<Int>, pos = 0, ?length:Int):Int32Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new Int32Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos = 0, ?length:Int):Int32Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, (length == null ? (bytes.length - bytePos) >> 2 : length) << 2).getData());
|
||||
}
|
||||
}
|
321
Kha/Tools/macos/std/haxe/io/Mime.hx
Normal file
321
Kha/Tools/macos/std/haxe/io/Mime.hx
Normal file
@ -0,0 +1,321 @@
|
||||
package haxe.io;
|
||||
|
||||
/**
|
||||
HTML MimeType Enum
|
||||
@see http://www.sitepoint.com/web-foundations/mime-types-complete-list/
|
||||
**/
|
||||
enum abstract Mime(String) from String to String {
|
||||
var XWorldX3dmf = 'x-world/x-3dmf';
|
||||
var ApplicationOctetStream = 'application/octet-stream';
|
||||
var ApplicationXAuthorwareBin = 'application/x-authorware-bin';
|
||||
var ApplicationXAuthorwareMap = 'application/x-authorware-map';
|
||||
var ApplicationXAuthorwareSeg = 'application/x-authorware-seg';
|
||||
var TextVndAbc = 'text/vnd.abc';
|
||||
var TextHtml = 'text/html';
|
||||
var VideoAnimaflex = 'video/animaflex';
|
||||
var ApplicationPostscript = 'application/postscript';
|
||||
var AudioAiff = 'audio/aiff';
|
||||
var AudioXAiff = 'audio/x-aiff';
|
||||
var ApplicationXAim = 'application/x-aim';
|
||||
var TextXAudiosoftIntra = 'text/x-audiosoft-intra';
|
||||
var ApplicationXNaviAnimation = 'application/x-navi-animation';
|
||||
var ApplicationXNokia9000CommunicatorAddOnSoftware = 'application/x-nokia-9000-communicator-add-on-software';
|
||||
var ApplicationMime = 'application/mime';
|
||||
var ApplicationArj = 'application/arj';
|
||||
var ImageXJg = 'image/x-jg';
|
||||
var VideoXMsAsf = 'video/x-ms-asf';
|
||||
var TextXAsm = 'text/x-asm';
|
||||
var TextAsp = 'text/asp';
|
||||
var ApplicationXMplayer2 = 'application/x-mplayer2';
|
||||
var AudioBasic = 'audio/basic';
|
||||
var ApplicationXTroffMsvideo = 'application/x-troff-msvideo';
|
||||
var VideoAvi = 'video/avi';
|
||||
var VideoMsvideo = 'video/msvideo';
|
||||
var VideoXMsvideo = 'video/x-msvideo';
|
||||
var VideoAvsVideo = 'video/avs-video';
|
||||
var ApplicationXBcpio = 'application/x-bcpio';
|
||||
var ApplicationMacBinary = 'application/mac-binary';
|
||||
var ApplicationMacbinary = 'application/macbinary';
|
||||
var ApplicationXBinary = 'application/x-binary';
|
||||
var ApplicationXMacbinary = 'application/x-macbinary';
|
||||
var ImageBmp = 'image/bmp';
|
||||
var ImageXWindowsBmp = 'image/x-windows-bmp';
|
||||
var ApplicationBook = 'application/book';
|
||||
var ApplicationXBzip2 = 'application/x-bzip2';
|
||||
var ApplicationXBsh = 'application/x-bsh';
|
||||
var ApplicationXBzip = 'application/x-bzip';
|
||||
var TextPlain = 'text/plain';
|
||||
var TextXC = 'text/x-c';
|
||||
var ApplicationVndMsPkiSeccat = 'application/vnd.ms-pki.seccat';
|
||||
var ApplicationClariscad = 'application/clariscad';
|
||||
var ApplicationXCocoa = 'application/x-cocoa';
|
||||
var ApplicationCdf = 'application/cdf';
|
||||
var ApplicationXCdf = 'application/x-cdf';
|
||||
var ApplicationXNetcdf = 'application/x-netcdf';
|
||||
var ApplicationPkixCert = 'application/pkix-cert';
|
||||
var ApplicationXX509CaCert = 'application/x-x509-ca-cert';
|
||||
var ApplicationXChat = 'application/x-chat';
|
||||
var ApplicationJava = 'application/java';
|
||||
var ApplicationJavaByteCode = 'application/java-byte-code';
|
||||
var ApplicationXJavaClass = 'application/x-java-class';
|
||||
var ApplicationXCpio = 'application/x-cpio';
|
||||
var ApplicationMacCompactpro = 'application/mac-compactpro';
|
||||
var ApplicationPkcsCrl = 'application/pkcs-crl';
|
||||
var ApplicationXCsh = 'application/x-csh';
|
||||
var TextCss = 'text/css';
|
||||
var ApplicationXDirector = 'application/x-director';
|
||||
var ApplicationXDeepv = 'application/x-deepv';
|
||||
var VideoXDv = 'video/x-dv';
|
||||
var VideoDl = 'video/dl';
|
||||
var ApplicationMsword = 'application/msword';
|
||||
var ApplicationCommonground = 'application/commonground';
|
||||
var ApplicationDrafting = 'application/drafting';
|
||||
var ApplicationXDvi = 'application/x-dvi';
|
||||
var DrawingXDwf = 'drawing/x-dwf (old)';
|
||||
var ApplicationAcad = 'application/acad';
|
||||
var ApplicationDxf = 'application/dxf';
|
||||
var TextXScriptElisp = 'text/x-script.elisp';
|
||||
var ApplicationXBytecodeElisp = 'application/x-bytecode.elisp (compiled elisp)';
|
||||
var ApplicationXEnvoy = 'application/x-envoy';
|
||||
var ApplicationXEsrehber = 'application/x-esrehber';
|
||||
var TextXSetext = 'text/x-setext';
|
||||
var ApplicationEnvoy = 'application/envoy';
|
||||
var TextXFortran = 'text/x-fortran';
|
||||
var ApplicationVndFdf = 'application/vnd.fdf';
|
||||
var ImageFif = 'image/fif';
|
||||
var VideoFli = 'video/fli';
|
||||
var ImageFlorian = 'image/florian';
|
||||
var TextVndFmiFlexstor = 'text/vnd.fmi.flexstor';
|
||||
var VideoXAtomic3dFeature = 'video/x-atomic3d-feature';
|
||||
var ImageVndFpx = 'image/vnd.fpx';
|
||||
var ApplicationFreeloader = 'application/freeloader';
|
||||
var AudioMake = 'audio/make';
|
||||
var ImageG3fax = 'image/g3fax';
|
||||
var ImageGif = 'image/gif';
|
||||
var VideoGl = 'video/gl';
|
||||
var AudioXGsm = 'audio/x-gsm';
|
||||
var ApplicationXGsp = 'application/x-gsp';
|
||||
var ApplicationXGss = 'application/x-gss';
|
||||
var ApplicationXGtar = 'application/x-gtar';
|
||||
var ApplicationXCompressed = 'application/x-compressed';
|
||||
var ApplicationXGzip = 'application/x-gzip';
|
||||
var ApplicationXHdf = 'application/x-hdf';
|
||||
var ApplicationXHelpfile = 'application/x-helpfile';
|
||||
var TextXScript = 'text/x-script';
|
||||
var ApplicationHlp = 'application/hlp';
|
||||
var ApplicationVndHpHpgl = 'application/vnd.hp-hpgl';
|
||||
var ApplicationBinhex = 'application/binhex';
|
||||
var ApplicationHta = 'application/hta';
|
||||
var TextXComponent = 'text/x-component';
|
||||
var TextWebviewhtml = 'text/webviewhtml';
|
||||
var XConferenceXCooltalk = 'x-conference/x-cooltalk';
|
||||
var ImageXIcon = 'image/x-icon';
|
||||
var ImageIef = 'image/ief';
|
||||
var ApplicationIges = 'application/iges';
|
||||
var ApplicationXIma = 'application/x-ima';
|
||||
var ApplicationXHttpdImap = 'application/x-httpd-imap';
|
||||
var ApplicationInf = 'application/inf';
|
||||
var ApplicationXInternettSignup = 'application/x-internett-signup';
|
||||
var ApplicationXIp2 = 'application/x-ip2';
|
||||
var VideoXIsvideo = 'video/x-isvideo';
|
||||
var AudioIt = 'audio/it';
|
||||
var ApplicationXInventor = 'application/x-inventor';
|
||||
var IWorldIVrml = 'i-world/i-vrml';
|
||||
var ApplicationXLivescreen = 'application/x-livescreen';
|
||||
var AudioXJam = 'audio/x-jam';
|
||||
var ApplicationXJavaCommerce = 'application/x-java-commerce';
|
||||
var ImageJpeg = 'image/jpeg';
|
||||
var ImageXJps = 'image/x-jps';
|
||||
var TextJavascript = 'text/javascript';
|
||||
var ApplicationJson = 'application/json';
|
||||
var ApplicationJavascript = 'application/javascript';
|
||||
var ImageJutvision = 'image/jutvision';
|
||||
var AudioMidi = 'audio/midi';
|
||||
var ApplicationXKsh = 'application/x-ksh';
|
||||
var AudioNspaudio = 'audio/nspaudio';
|
||||
var AudioXLiveaudio = 'audio/x-liveaudio';
|
||||
var ApplicationXLatex = 'application/x-latex';
|
||||
var ApplicationXLisp = 'application/x-lisp';
|
||||
var TextXLaAsf = 'text/x-la-asf';
|
||||
var ApplicationLzx = 'application/lzx';
|
||||
var VideoMpeg = 'video/mpeg';
|
||||
var AudioMpeg = 'audio/mpeg';
|
||||
var AudioXMpequrl = 'audio/x-mpequrl';
|
||||
var ApplicationXTroffMan = 'application/x-troff-man';
|
||||
var ApplicationXNavimap = 'application/x-navimap';
|
||||
var ApplicationMbedlet = 'application/mbedlet';
|
||||
var ApplicationXMagicCapPackage10 = 'application/x-magic-cap-package-1.0';
|
||||
var ApplicationMcad = 'application/mcad';
|
||||
var ImageVasa = 'image/vasa';
|
||||
var ApplicationNetmc = 'application/netmc';
|
||||
var ApplicationXTroffMe = 'application/x-troff-me';
|
||||
var MessageRfc822 = 'message/rfc822';
|
||||
var ApplicationXMif = 'application/x-mif';
|
||||
var WwwMime = 'www/mime';
|
||||
var AudioXVndAudioexplosionMjuicemediafile = 'audio/x-vnd.audioexplosion.mjuicemediafile';
|
||||
var VideoXMotionJpeg = 'video/x-motion-jpeg';
|
||||
var ApplicationBase64 = 'application/base64';
|
||||
var AudioMod = 'audio/mod';
|
||||
var VideoQuicktime = 'video/quicktime';
|
||||
var VideoXSgiMovie = 'video/x-sgi-movie';
|
||||
var AudioMpeg3 = 'audio/mpeg3';
|
||||
var ApplicationXProject = 'application/x-project';
|
||||
var ApplicationVndMsProject = 'application/vnd.ms-project';
|
||||
var ApplicationMarc = 'application/marc';
|
||||
var ApplicationXTroffMs = 'application/x-troff-ms';
|
||||
var ApplicationXVndAudioexplosionMzz = 'application/x-vnd.audioexplosion.mzz';
|
||||
var ImageNaplps = 'image/naplps';
|
||||
var ApplicationVndNokiaConfigurationMessage = 'application/vnd.nokia.configuration-message';
|
||||
var ImageXNiff = 'image/x-niff';
|
||||
var ApplicationXMixTransfer = 'application/x-mix-transfer';
|
||||
var ApplicationXConference = 'application/x-conference';
|
||||
var ApplicationXNavidoc = 'application/x-navidoc';
|
||||
var ApplicationOda = 'application/oda';
|
||||
var ApplicationXOmc = 'application/x-omc';
|
||||
var ApplicationXOmcdatamaker = 'application/x-omcdatamaker';
|
||||
var ApplicationXOmcregerator = 'application/x-omcregerator';
|
||||
var TextXPascal = 'text/x-pascal';
|
||||
var ApplicationPkcs10 = 'application/pkcs10';
|
||||
var ApplicationPkcs12 = 'application/pkcs-12';
|
||||
var ApplicationXPkcs7Signature = 'application/x-pkcs7-signature';
|
||||
var ApplicationPkcs7Mime = 'application/pkcs7-mime';
|
||||
var ApplicationXPkcs7Certreqresp = 'application/x-pkcs7-certreqresp';
|
||||
var ApplicationPkcs7Signature = 'application/pkcs7-signature';
|
||||
var ApplicationPro_eng = 'application/pro_eng';
|
||||
var TextPascal = 'text/pascal';
|
||||
var ImageXPortableBitmap = 'image/x-portable-bitmap';
|
||||
var ApplicationVndHpPcl = 'application/vnd.hp-pcl';
|
||||
var ImageXPict = 'image/x-pict';
|
||||
var ImageXPcx = 'image/x-pcx';
|
||||
var ChemicalXPdb = 'chemical/x-pdb';
|
||||
var ApplicationPdf = 'application/pdf';
|
||||
var ImageXPortableGraymap = 'image/x-portable-graymap';
|
||||
var ImagePict = 'image/pict';
|
||||
var ApplicationXNewtonCompatiblePkg = 'application/x-newton-compatible-pkg';
|
||||
var ApplicationVndMsPkiPko = 'application/vnd.ms-pki.pko';
|
||||
var ApplicationXPixclscript = 'application/x-pixclscript';
|
||||
var ImageXXpixmap = 'image/x-xpixmap';
|
||||
var ApplicationXPagemaker = 'application/x-pagemaker';
|
||||
var ImagePng = 'image/png';
|
||||
var ApplicationXPortableAnymap = 'application/x-portable-anymap';
|
||||
var ApplicationMspowerpoint = 'application/mspowerpoint';
|
||||
var ModelXPov = 'model/x-pov';
|
||||
var ApplicationVndMsPowerpoint = 'application/vnd.ms-powerpoint';
|
||||
var ImageXPortablePixmap = 'image/x-portable-pixmap';
|
||||
var ApplicationXFreelance = 'application/x-freelance';
|
||||
var PaleovuXPv = 'paleovu/x-pv';
|
||||
var TextXScriptPhyton = 'text/x-script.phyton';
|
||||
var ApplicationXBytecodePython = 'application/x-bytecode.python';
|
||||
var AudioVndQcelp = 'audio/vnd.qcelp';
|
||||
var ImageXQuicktime = 'image/x-quicktime';
|
||||
var VideoXQtc = 'video/x-qtc';
|
||||
var AudioXPnRealaudio = 'audio/x-pn-realaudio';
|
||||
var ApplicationXCmuRaster = 'application/x-cmu-raster';
|
||||
var ImageCmuRaster = 'image/cmu-raster';
|
||||
var TextXScriptRexx = 'text/x-script.rexx';
|
||||
var ImageVndRnRealflash = 'image/vnd.rn-realflash';
|
||||
var ImageXRgb = 'image/x-rgb';
|
||||
var ApplicationVndRnRealmedia = 'application/vnd.rn-realmedia';
|
||||
var AudioMid = 'audio/mid';
|
||||
var ApplicationRingingTones = 'application/ringing-tones';
|
||||
var ApplicationVndRnRealplayer = 'application/vnd.rn-realplayer';
|
||||
var ApplicationXTroff = 'application/x-troff';
|
||||
var ImageVndRnRealpix = 'image/vnd.rn-realpix';
|
||||
var AudioXPnRealaudioPlugin = 'audio/x-pn-realaudio-plugin';
|
||||
var TextRichtext = 'text/richtext';
|
||||
var ApplicationRtf = 'application/rtf';
|
||||
var VideoVndRnRealvideo = 'video/vnd.rn-realvideo';
|
||||
var AudioS3m = 'audio/s3m';
|
||||
var ApplicationXTbook = 'application/x-tbook';
|
||||
var ApplicationXLotusscreencam = 'application/x-lotusscreencam';
|
||||
var ApplicationSdp = 'application/sdp';
|
||||
var ApplicationSounder = 'application/sounder';
|
||||
var ApplicationSea = 'application/sea';
|
||||
var ApplicationSet = 'application/set';
|
||||
var AudioXPsid = 'audio/x-psid';
|
||||
var ApplicationXSit = 'application/x-sit';
|
||||
var ApplicationXKoan = 'application/x-koan';
|
||||
var ApplicationXSeelogo = 'application/x-seelogo';
|
||||
var ApplicationSmil = 'application/smil';
|
||||
var ApplicationSolids = 'application/solids';
|
||||
var ApplicationXPkcs7Certificates = 'application/x-pkcs7-certificates';
|
||||
var ApplicationFuturesplash = 'application/futuresplash';
|
||||
var ApplicationXSprite = 'application/x-sprite';
|
||||
var ApplicationXWaisSource = 'application/x-wais-source';
|
||||
var TextXServerParsedHtml = 'text/x-server-parsed-html';
|
||||
var ApplicationStreamingmedia = 'application/streamingmedia';
|
||||
var ApplicationVndMsPkiCertstore = 'application/vnd.ms-pki.certstore';
|
||||
var ApplicationStep = 'application/step';
|
||||
var ApplicationSla = 'application/sla';
|
||||
var ApplicationXSv4cpio = 'application/x-sv4cpio';
|
||||
var ApplicationXSv4crc = 'application/x-sv4crc';
|
||||
var ImageVndDwg = 'image/vnd.dwg';
|
||||
var ApplicationXWorld = 'application/x-world';
|
||||
var ApplicationXShockwaveFlash = 'application/x-shockwave-flash';
|
||||
var TextXSpeech = 'text/x-speech';
|
||||
var ApplicationXTar = 'application/x-tar';
|
||||
var ApplicationToolbook = 'application/toolbook';
|
||||
var ApplicationXTcl = 'application/x-tcl';
|
||||
var TextXScriptTcsh = 'text/x-script.tcsh';
|
||||
var ApplicationXTex = 'application/x-tex';
|
||||
var ApplicationXTexinfo = 'application/x-texinfo';
|
||||
var ApplicationGnutar = 'application/gnutar';
|
||||
var ImageTiff = 'image/tiff';
|
||||
var AudioTspAudio = 'audio/tsp-audio';
|
||||
var ApplicationDsptype = 'application/dsptype';
|
||||
var TextTabSeparatedValues = 'text/tab-separated-values';
|
||||
var TextXUil = 'text/x-uil';
|
||||
var TextUriList = 'text/uri-list';
|
||||
var ApplicationIDeas = 'application/i-deas';
|
||||
var ApplicationXUstar = 'application/x-ustar';
|
||||
var TextXUuencode = 'text/x-uuencode';
|
||||
var ApplicationXCdlink = 'application/x-cdlink';
|
||||
var TextXVcalendar = 'text/x-vcalendar';
|
||||
var ApplicationVda = 'application/vda';
|
||||
var VideoVdo = 'video/vdo';
|
||||
var ApplicationGroupwise = 'application/groupwise';
|
||||
var VideoVivo = 'video/vivo';
|
||||
var ApplicationVocaltecMediaDesc = 'application/vocaltec-media-desc';
|
||||
var ApplicationVocaltecMediaFile = 'application/vocaltec-media-file';
|
||||
var AudioVoc = 'audio/voc';
|
||||
var VideoVosaic = 'video/vosaic';
|
||||
var AudioVoxware = 'audio/voxware';
|
||||
var AudioXTwinvqPlugin = 'audio/x-twinvq-plugin';
|
||||
var AudioXTwinvq = 'audio/x-twinvq';
|
||||
var ApplicationXVrml = 'application/x-vrml';
|
||||
var XWorldXVrt = 'x-world/x-vrt';
|
||||
var ApplicationXVisio = 'application/x-visio';
|
||||
var ApplicationWordperfect60 = 'application/wordperfect6.0';
|
||||
var ApplicationWordperfect61 = 'application/wordperfect6.1';
|
||||
var AudioWav = 'audio/wav';
|
||||
var ApplicationXQpro = 'application/x-qpro';
|
||||
var ImageVndWapWbmp = 'image/vnd.wap.wbmp';
|
||||
var ApplicationVndXara = 'application/vnd.xara';
|
||||
var ImageWebp = 'image/webp';
|
||||
var ApplicationX123 = 'application/x-123';
|
||||
var WindowsMetafile = 'windows/metafile';
|
||||
var TextVndWapWml = 'text/vnd.wap.wml';
|
||||
var ApplicationVndWapWmlc = 'application/vnd.wap.wmlc';
|
||||
var TextVndWapWmlscript = 'text/vnd.wap.wmlscript';
|
||||
var ApplicationVndWapWmlscriptc = 'application/vnd.wap.wmlscriptc';
|
||||
var ApplicationWordperfect = 'application/wordperfect';
|
||||
var ApplicationXLotus = 'application/x-lotus';
|
||||
var ApplicationMswrite = 'application/mswrite';
|
||||
var ModelVrml = 'model/vrml';
|
||||
var TextScriplet = 'text/scriplet';
|
||||
var ApplicationXWintalk = 'application/x-wintalk';
|
||||
var ImageXXbitmap = 'image/x-xbitmap';
|
||||
var VideoXAmtDemorun = 'video/x-amt-demorun';
|
||||
var XglDrawing = 'xgl/drawing';
|
||||
var ImageVndXiff = 'image/vnd.xiff';
|
||||
var ApplicationExcel = 'application/excel';
|
||||
var AudioXm = 'audio/xm';
|
||||
var ApplicationXml = 'application/xml';
|
||||
var XglMovie = 'xgl/movie';
|
||||
var ApplicationXVndLsXpix = 'application/x-vnd.ls-xpix';
|
||||
var VideoXAmtShowrun = 'video/x-amt-showrun';
|
||||
var ImageXXwd = 'image/x-xwd';
|
||||
var ApplicationXCompress = 'application/x-compress';
|
||||
var MultipartXZip = 'multipart/x-zip';
|
||||
var TextXScriptZsh = 'text/x-script.zsh';
|
||||
}
|
293
Kha/Tools/macos/std/haxe/io/Output.hx
Normal file
293
Kha/Tools/macos/std/haxe/io/Output.hx
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
An Output is an abstract write. A specific output implementation will only
|
||||
have to override the `writeByte` and maybe the `write`, `flush` and `close`
|
||||
methods. See `File.write` and `String.write` for two ways of creating an
|
||||
Output.
|
||||
**/
|
||||
class Output {
|
||||
/**
|
||||
Endianness (word byte order) used when writing numbers.
|
||||
|
||||
If `true`, big-endian is used, otherwise `little-endian` is used.
|
||||
**/
|
||||
public var bigEndian(default, set):Bool;
|
||||
|
||||
#if java
|
||||
private var helper:java.nio.ByteBuffer;
|
||||
#end
|
||||
|
||||
/**
|
||||
Write one byte.
|
||||
**/
|
||||
public function writeByte(c:Int):Void {
|
||||
throw new haxe.exceptions.NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
Write `len` bytes from `s` starting by position specified by `pos`.
|
||||
|
||||
Returns the actual length of written data that can differ from `len`.
|
||||
|
||||
See `writeFullBytes` that tries to write the exact amount of specified bytes.
|
||||
**/
|
||||
public function writeBytes(s:Bytes, pos:Int, len:Int):Int {
|
||||
#if !neko
|
||||
if (pos < 0 || len < 0 || pos + len > s.length)
|
||||
throw Error.OutsideBounds;
|
||||
#end
|
||||
var b = #if js @:privateAccess s.b #else s.getData() #end;
|
||||
var k = len;
|
||||
while (k > 0) {
|
||||
#if neko
|
||||
writeByte(untyped __dollar__sget(b, pos));
|
||||
#elseif php
|
||||
writeByte(b.get(pos));
|
||||
#elseif cpp
|
||||
writeByte(untyped b[pos]);
|
||||
#elseif hl
|
||||
writeByte(b[pos]);
|
||||
#else
|
||||
writeByte(untyped b[pos]);
|
||||
#end
|
||||
pos++;
|
||||
k--;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
Flush any buffered data.
|
||||
**/
|
||||
public function flush() {}
|
||||
|
||||
/**
|
||||
Close the output.
|
||||
|
||||
Behaviour while writing after calling this method is unspecified.
|
||||
**/
|
||||
public function close() {}
|
||||
|
||||
function set_bigEndian(b) {
|
||||
bigEndian = b;
|
||||
return b;
|
||||
}
|
||||
|
||||
/* ------------------ API ------------------ */
|
||||
/**
|
||||
Write all bytes stored in `s`.
|
||||
**/
|
||||
public function write(s:Bytes):Void {
|
||||
var l = s.length;
|
||||
var p = 0;
|
||||
while (l > 0) {
|
||||
var k = writeBytes(s, p, l);
|
||||
if (k == 0)
|
||||
throw Error.Blocked;
|
||||
p += k;
|
||||
l -= k;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `len` bytes from `s` starting by position specified by `pos`.
|
||||
|
||||
Unlike `writeBytes`, this method tries to write the exact `len` amount of bytes.
|
||||
**/
|
||||
public function writeFullBytes(s:Bytes, pos:Int, len:Int) {
|
||||
while (len > 0) {
|
||||
var k = writeBytes(s, pos, len);
|
||||
pos += k;
|
||||
len -= k;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 32-bit floating point number.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeFloat(x:Float) {
|
||||
writeInt32(FPHelper.floatToI32(x));
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 64-bit double-precision floating point number.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeDouble(x:Float) {
|
||||
var i64 = FPHelper.doubleToI64(x);
|
||||
if (bigEndian) {
|
||||
writeInt32(i64.high);
|
||||
writeInt32(i64.low);
|
||||
} else {
|
||||
writeInt32(i64.low);
|
||||
writeInt32(i64.high);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 8-bit signed integer.
|
||||
**/
|
||||
public function writeInt8(x:Int) {
|
||||
if (x < -0x80 || x >= 0x80)
|
||||
throw Error.Overflow;
|
||||
writeByte(x & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 16-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeInt16(x:Int) {
|
||||
if (x < -0x8000 || x >= 0x8000)
|
||||
throw Error.Overflow;
|
||||
writeUInt16(x & 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 16-bit unsigned integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeUInt16(x:Int) {
|
||||
if (x < 0 || x >= 0x10000)
|
||||
throw Error.Overflow;
|
||||
if (bigEndian) {
|
||||
writeByte(x >> 8);
|
||||
writeByte(x & 0xFF);
|
||||
} else {
|
||||
writeByte(x & 0xFF);
|
||||
writeByte(x >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 24-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeInt24(x:Int) {
|
||||
if (x < -0x800000 || x >= 0x800000)
|
||||
throw Error.Overflow;
|
||||
writeUInt24(x & 0xFFFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 24-bit unsigned integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeUInt24(x:Int) {
|
||||
if (x < 0 || x >= 0x1000000)
|
||||
throw Error.Overflow;
|
||||
if (bigEndian) {
|
||||
writeByte(x >> 16);
|
||||
writeByte((x >> 8) & 0xFF);
|
||||
writeByte(x & 0xFF);
|
||||
} else {
|
||||
writeByte(x & 0xFF);
|
||||
writeByte((x >> 8) & 0xFF);
|
||||
writeByte(x >> 16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `x` as 32-bit signed integer.
|
||||
|
||||
Endianness is specified by the `bigEndian` property.
|
||||
**/
|
||||
public function writeInt32(x:Int) {
|
||||
if (bigEndian) {
|
||||
writeByte(x >>> 24);
|
||||
writeByte((x >> 16) & 0xFF);
|
||||
writeByte((x >> 8) & 0xFF);
|
||||
writeByte(x & 0xFF);
|
||||
} else {
|
||||
writeByte(x & 0xFF);
|
||||
writeByte((x >> 8) & 0xFF);
|
||||
writeByte((x >> 16) & 0xFF);
|
||||
writeByte(x >>> 24);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Inform that we are about to write at least `nbytes` bytes.
|
||||
|
||||
The underlying implementation can allocate proper working space depending
|
||||
on this information, or simply ignore it. This is not a mandatory call
|
||||
but a tip and is only used in some specific cases.
|
||||
**/
|
||||
public function prepare(nbytes:Int) {}
|
||||
|
||||
/**
|
||||
Read all available data from `i` and write it.
|
||||
|
||||
The `bufsize` optional argument specifies the size of chunks by
|
||||
which data is read and written. Its default value is 4096.
|
||||
**/
|
||||
public function writeInput(i:Input, ?bufsize:Int) {
|
||||
if (bufsize == null)
|
||||
bufsize = 4096;
|
||||
var buf = Bytes.alloc(bufsize);
|
||||
try {
|
||||
while (true) {
|
||||
var len = i.readBytes(buf, 0, bufsize);
|
||||
if (len == 0)
|
||||
throw Error.Blocked;
|
||||
var p = 0;
|
||||
while (len > 0) {
|
||||
var k = writeBytes(buf, p, len);
|
||||
if (k == 0)
|
||||
throw Error.Blocked;
|
||||
p += k;
|
||||
len -= k;
|
||||
}
|
||||
}
|
||||
} catch (e:Eof) {}
|
||||
}
|
||||
|
||||
/**
|
||||
Write `s` string.
|
||||
**/
|
||||
public function writeString(s:String, ?encoding:Encoding) {
|
||||
#if neko
|
||||
var b = untyped new Bytes(s.length, s.__s);
|
||||
#else
|
||||
var b = Bytes.ofString(s, encoding);
|
||||
#end
|
||||
writeFullBytes(b, 0, b.length);
|
||||
}
|
||||
|
||||
#if neko
|
||||
static function __init__()
|
||||
untyped {
|
||||
Output.prototype.bigEndian = false;
|
||||
}
|
||||
#end
|
||||
}
|
333
Kha/Tools/macos/std/haxe/io/Path.hx
Normal file
333
Kha/Tools/macos/std/haxe/io/Path.hx
Normal file
@ -0,0 +1,333 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
This class provides a convenient way of working with paths. It supports the
|
||||
common path formats:
|
||||
|
||||
- `directory1/directory2/filename.extension`
|
||||
- `directory1\directory2\filename.extension`
|
||||
**/
|
||||
class Path {
|
||||
/**
|
||||
The directory.
|
||||
|
||||
This is the leading part of the path that is not part of the file name
|
||||
and the extension.
|
||||
|
||||
Does not end with a `/` or `\` separator.
|
||||
|
||||
If the path has no directory, the value is `null`.
|
||||
**/
|
||||
public var dir:Null<String>;
|
||||
|
||||
/**
|
||||
The file name.
|
||||
|
||||
This is the part of the part between the directory and the extension.
|
||||
|
||||
If there is no file name, e.g. for `".htaccess"` or `"/dir/"`, the value
|
||||
is the empty String `""`.
|
||||
**/
|
||||
public var file:String;
|
||||
|
||||
/**
|
||||
The file extension.
|
||||
|
||||
It is separated from the file name by a dot. This dot is not part of
|
||||
the extension.
|
||||
|
||||
If the path has no extension, the value is `null`.
|
||||
**/
|
||||
public var ext:Null<String>;
|
||||
|
||||
/**
|
||||
`true` if the last directory separator is a backslash, `false` otherwise.
|
||||
**/
|
||||
public var backslash:Bool;
|
||||
|
||||
/**
|
||||
Creates a new `Path` instance by parsing `path`.
|
||||
|
||||
Path information can be retrieved by accessing the `dir`, `file` and `ext`
|
||||
properties.
|
||||
**/
|
||||
public function new(path:String) {
|
||||
switch (path) {
|
||||
case "." | "..":
|
||||
dir = path;
|
||||
file = "";
|
||||
return;
|
||||
}
|
||||
var c1 = path.lastIndexOf("/");
|
||||
var c2 = path.lastIndexOf("\\");
|
||||
if (c1 < c2) {
|
||||
dir = path.substr(0, c2);
|
||||
path = path.substr(c2 + 1);
|
||||
backslash = true;
|
||||
} else if (c2 < c1) {
|
||||
dir = path.substr(0, c1);
|
||||
path = path.substr(c1 + 1);
|
||||
} else
|
||||
dir = null;
|
||||
var cp = path.lastIndexOf(".");
|
||||
if (cp != -1) {
|
||||
ext = path.substr(cp + 1);
|
||||
file = path.substr(0, cp);
|
||||
} else {
|
||||
ext = null;
|
||||
file = path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a String representation of `this` path.
|
||||
|
||||
If `this.backslash` is `true`, backslash is used as directory separator,
|
||||
otherwise slash is used. This only affects the separator between
|
||||
`this.dir` and `this.file`.
|
||||
|
||||
If `this.directory` or `this.extension` is `null`, their representation
|
||||
is the empty String `""`.
|
||||
**/
|
||||
public function toString():String {
|
||||
return (if (dir == null) "" else dir + if (backslash) "\\" else "/") + file + (if (ext == null) "" else "." + ext);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the String representation of `path` without the file extension.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function withoutExtension(path:String):String {
|
||||
var s = new Path(path);
|
||||
s.ext = null;
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the String representation of `path` without the directory.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function withoutDirectory(path):String {
|
||||
var s = new Path(path);
|
||||
s.dir = null;
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the directory of `path`.
|
||||
|
||||
If the directory is `null`, the empty String `""` is returned.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function directory(path):String {
|
||||
var s = new Path(path);
|
||||
if (s.dir == null)
|
||||
return "";
|
||||
return s.dir;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the extension of `path`.
|
||||
|
||||
If `path` has no extension, the empty String `""` is returned.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function extension(path):String {
|
||||
var s = new Path(path);
|
||||
if (s.ext == null)
|
||||
return "";
|
||||
return s.ext;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a String representation of `path` where the extension is `ext`.
|
||||
|
||||
If `path` has no extension, `ext` is added as extension.
|
||||
|
||||
If `path` or `ext` are `null`, the result is unspecified.
|
||||
**/
|
||||
public static function withExtension(path, ext):String {
|
||||
var s = new Path(path);
|
||||
s.ext = ext;
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Joins all paths in `paths` together.
|
||||
|
||||
If `paths` is empty, the empty String `""` is returned. Otherwise the
|
||||
paths are joined with a slash between them.
|
||||
|
||||
If `paths` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function join(paths:Array<String>):String {
|
||||
var paths = paths.filter(function(s) return s != null && s != "");
|
||||
if (paths.length == 0) {
|
||||
return "";
|
||||
}
|
||||
var path = paths[0];
|
||||
for (i in 1...paths.length) {
|
||||
path = addTrailingSlash(path);
|
||||
path += paths[i];
|
||||
}
|
||||
return normalize(path);
|
||||
}
|
||||
|
||||
/**
|
||||
Normalize a given `path` (e.g. turn `'/usr/local/../lib'` into `'/usr/lib'`).
|
||||
|
||||
Also replaces backslashes `\` with slashes `/` and afterwards turns
|
||||
multiple slashes into a single one.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function normalize(path:String):String {
|
||||
var slash = "/";
|
||||
path = path.split("\\").join(slash);
|
||||
if (path == slash)
|
||||
return slash;
|
||||
|
||||
var target = [];
|
||||
|
||||
for (token in path.split(slash)) {
|
||||
if (token == '..' && target.length > 0 && target[target.length - 1] != "..") {
|
||||
target.pop();
|
||||
} else if (token == '') {
|
||||
if (target.length > 0 || path.charCodeAt(0) == '/'.code) {
|
||||
target.push(token);
|
||||
}
|
||||
} else if (token != '.') {
|
||||
target.push(token);
|
||||
}
|
||||
}
|
||||
|
||||
var tmp = target.join(slash);
|
||||
var acc = new StringBuf();
|
||||
var colon = false;
|
||||
var slashes = false;
|
||||
#if utf16
|
||||
for (c in haxe.iterators.StringIteratorUnicode.unicodeIterator(tmp)) {
|
||||
switch (c) {
|
||||
#else
|
||||
for (i in 0...tmp.length) {
|
||||
switch (StringTools.fastCodeAt(tmp, i)) {
|
||||
#end
|
||||
case ":".code:
|
||||
acc.add(":");
|
||||
colon = true;
|
||||
case "/".code if (!colon):
|
||||
slashes = true;
|
||||
case var i:
|
||||
colon = false;
|
||||
if (slashes) {
|
||||
acc.add("/");
|
||||
slashes = false;
|
||||
}
|
||||
acc.addChar(i);
|
||||
}
|
||||
}
|
||||
|
||||
return acc.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a trailing slash to `path`, if it does not have one already.
|
||||
|
||||
If the last slash in `path` is a backslash, a backslash is appended to
|
||||
`path`.
|
||||
|
||||
If the last slash in `path` is a slash, or if no slash is found, a slash
|
||||
is appended to `path`. In particular, this applies to the empty String
|
||||
`""`.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function addTrailingSlash(path:String):String {
|
||||
if (path.length == 0)
|
||||
return "/";
|
||||
var c1 = path.lastIndexOf("/");
|
||||
var c2 = path.lastIndexOf("\\");
|
||||
return if (c1 < c2) {
|
||||
if (c2 != path.length - 1)
|
||||
path + "\\";
|
||||
else
|
||||
path;
|
||||
} else {
|
||||
if (c1 != path.length - 1)
|
||||
path + "/";
|
||||
else
|
||||
path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Removes trailing slashes from `path`.
|
||||
|
||||
If `path` does not end with a `/` or `\`, `path` is returned unchanged.
|
||||
|
||||
Otherwise the substring of `path` excluding the trailing slashes or
|
||||
backslashes is returned.
|
||||
|
||||
If `path` is `null`, the result is unspecified.
|
||||
**/
|
||||
public static function removeTrailingSlashes(path:String):String {
|
||||
while (true) {
|
||||
switch (path.charCodeAt(path.length - 1)) {
|
||||
case '/'.code | '\\'.code:
|
||||
path = path.substr(0, -1);
|
||||
case _:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns `true` if the path is an absolute path, and `false` otherwise.
|
||||
**/
|
||||
public static function isAbsolute(path:String):Bool {
|
||||
if (StringTools.startsWith(path, '/'))
|
||||
return true;
|
||||
if (path.charAt(1) == ':')
|
||||
return true;
|
||||
if (StringTools.startsWith(path, '\\\\'))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function unescape(path:String):String {
|
||||
var regex = ~/-x([0-9][0-9])/g;
|
||||
return regex.map(path, function(regex) return String.fromCharCode(Std.parseInt(regex.matched(1))));
|
||||
}
|
||||
|
||||
private static function escape(path:String, allowSlashes:Bool = false):String {
|
||||
var regex = allowSlashes ? ~/[^A-Za-z0-9_\/\\\.]/g : ~/[^A-Za-z0-9_\.]/g;
|
||||
return regex.map(path, function(v) return '-x' + v.matched(0).charCodeAt(0));
|
||||
}
|
||||
}
|
18
Kha/Tools/macos/std/haxe/io/Scheme.hx
Normal file
18
Kha/Tools/macos/std/haxe/io/Scheme.hx
Normal file
@ -0,0 +1,18 @@
|
||||
package haxe.io;
|
||||
|
||||
/**
|
||||
A scheme consists of a sequence of characters beginning with a letter and followed
|
||||
by any combination of letters, digits, plus (`+`, period (`.`), or hyphen (`-`).
|
||||
|
||||
Although schemes are case-insensitive, the canonical form is lowercase
|
||||
and documents that specify schemes must do so with lowercase letters.
|
||||
It is followed by a colon (`:`).
|
||||
**/
|
||||
enum abstract Scheme(String) from String to String {
|
||||
var Http = 'http';
|
||||
var Https = 'https';
|
||||
var Ftp = 'ftp';
|
||||
var MailTo = 'mailto';
|
||||
var File = 'file';
|
||||
var Data = 'data';
|
||||
}
|
29
Kha/Tools/macos/std/haxe/io/StringInput.hx
Normal file
29
Kha/Tools/macos/std/haxe/io/StringInput.hx
Normal 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(haxe.io.Bytes.ofString(s));
|
||||
}
|
||||
}
|
87
Kha/Tools/macos/std/haxe/io/UInt16Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/UInt16Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef UInt16ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract UInt16Array(UInt16ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 2;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength >> 1;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int):Int {
|
||||
return this.bytes.getUInt16((index << 1) + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:Int):Int {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.setUInt16((index << 1) + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):UInt16Array {
|
||||
return fromData(this.sub(begin << 1, length == null ? null : length << 1));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):UInt16Array {
|
||||
return fromData(this.subarray(begin == null ? null : begin << 1, end == null ? null : end << 1));
|
||||
}
|
||||
|
||||
public inline function getData():UInt16ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:UInt16ArrayData):UInt16Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<Int>, pos = 0, ?length:Int):UInt16Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new UInt16Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos = 0, ?length:Int):UInt16Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, (length == null ? (bytes.length - bytePos) >> 1 : length) << 1).getData());
|
||||
}
|
||||
}
|
87
Kha/Tools/macos/std/haxe/io/UInt32Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/UInt32Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef UInt32ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract UInt32Array(UInt32ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 4;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength >> 2;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int):UInt {
|
||||
return this.bytes.getInt32((index << 2) + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:UInt):UInt {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.setInt32((index << 2) + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):UInt32Array {
|
||||
return fromData(this.sub(begin << 2, length == null ? null : length << 2));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):UInt32Array {
|
||||
return fromData(this.subarray(begin == null ? null : begin << 2, end == null ? null : end << 2));
|
||||
}
|
||||
|
||||
public inline function getData():UInt32ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:UInt32ArrayData):UInt32Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<UInt>, pos = 0, ?length:Int):UInt32Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new UInt32Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos = 0, ?length:Int):UInt32Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, (length == null ? (bytes.length - bytePos) >> 2 : length) << 2).getData());
|
||||
}
|
||||
}
|
87
Kha/Tools/macos/std/haxe/io/UInt8Array.hx
Normal file
87
Kha/Tools/macos/std/haxe/io/UInt8Array.hx
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
typedef UInt8ArrayData = ArrayBufferView.ArrayBufferViewData;
|
||||
|
||||
abstract UInt8Array(UInt8ArrayData) {
|
||||
public static inline var BYTES_PER_ELEMENT = 1;
|
||||
|
||||
public var length(get, never):Int;
|
||||
public var view(get, never):ArrayBufferView;
|
||||
|
||||
public inline function new(elements:Int) {
|
||||
this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
|
||||
}
|
||||
|
||||
inline function get_length() {
|
||||
return this.byteLength;
|
||||
}
|
||||
|
||||
public inline function get_view():ArrayBufferView {
|
||||
return ArrayBufferView.fromData(this);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(index:Int) {
|
||||
return this.bytes.get(index + this.byteOffset);
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function set(index:Int, value:Int):Int {
|
||||
if (index >= 0 && index < length) {
|
||||
this.bytes.set(index + this.byteOffset, value);
|
||||
return value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public inline function sub(begin:Int, ?length:Int):UInt8Array {
|
||||
return fromData(this.sub(begin, length));
|
||||
}
|
||||
|
||||
public inline function subarray(?begin:Int, ?end:Int):UInt8Array {
|
||||
return fromData(this.subarray(begin, end));
|
||||
}
|
||||
|
||||
public inline function getData():UInt8ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static function fromData(d:UInt8ArrayData):UInt8Array {
|
||||
return cast d;
|
||||
}
|
||||
|
||||
public static function fromArray(a:Array<Int>, pos = 0, ?length:Int):UInt8Array {
|
||||
if (length == null)
|
||||
length = a.length - pos;
|
||||
if (pos < 0 || length < 0 || pos + length > a.length)
|
||||
throw Error.OutsideBounds;
|
||||
var i = new UInt8Array(a.length);
|
||||
for (idx in 0...length)
|
||||
i[idx] = a[idx + pos];
|
||||
return i;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):UInt8Array {
|
||||
return fromData(ArrayBufferView.fromBytes(bytes, bytePos, length).getData());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user