mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-10-22 18:19:48 -05:00
Move Assets/* (expect Plugins) to Assets/VRM/*
This commit is contained in:
138
Assets/VRM/UniJSON/Scripts/Utf8String/IUtf8String.cs
Normal file
138
Assets/VRM/UniJSON/Scripts/Utf8String/IUtf8String.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public interface IUtf8String: IEnumerable<Byte>
|
||||
{
|
||||
int ByteLength { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Immutable short utf8 string
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Utf8String4 : IEquatable<Utf8String4>, IUtf8String
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
uint _value;
|
||||
|
||||
[FieldOffset(0)]
|
||||
byte _byte0;
|
||||
|
||||
[FieldOffset(1)]
|
||||
byte _byte1;
|
||||
|
||||
[FieldOffset(2)]
|
||||
byte _byte2;
|
||||
|
||||
[FieldOffset(3)]
|
||||
byte _byte3;
|
||||
|
||||
public int ByteLength
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_byte0 == 0) return 0;
|
||||
if (_byte1 == 0) return 1;
|
||||
if (_byte2 == 0) return 2;
|
||||
if (_byte3 == 0) return 3;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
static Utf8String4 Create(uint value)
|
||||
{
|
||||
return new Utf8String4
|
||||
{
|
||||
_value = value
|
||||
};
|
||||
}
|
||||
|
||||
public static Utf8String4 Create(IEnumerable<byte> bytes)
|
||||
{
|
||||
var u = new Utf8String4();
|
||||
var it = bytes.GetEnumerator();
|
||||
|
||||
if (!it.MoveNext()) return u;
|
||||
u._byte0 = it.Current;
|
||||
|
||||
if (!it.MoveNext()) return u;
|
||||
u._byte1 = it.Current;
|
||||
|
||||
if (!it.MoveNext()) return u;
|
||||
u._byte2 = it.Current;
|
||||
|
||||
if (!it.MoveNext()) return u;
|
||||
u._byte3 = it.Current;
|
||||
|
||||
if (!it.MoveNext())
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
public static Utf8String4 Create(string src)
|
||||
{
|
||||
return Create(Utf8String.Encoding.GetBytes(src));
|
||||
}
|
||||
|
||||
public bool Equals(Utf8String4 other)
|
||||
{
|
||||
return _value == other._value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
|
||||
if (obj is Utf8String4)
|
||||
{
|
||||
return Equals((Utf8String4)obj);
|
||||
}
|
||||
|
||||
{
|
||||
var s = obj as string;
|
||||
if (s != null)
|
||||
{
|
||||
return ToString() == s;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _value.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Utf8String.Encoding.GetString(this.ToArray());
|
||||
}
|
||||
|
||||
public IEnumerator<byte> GetEnumerator()
|
||||
{
|
||||
if (_byte0 == 0) yield break;
|
||||
yield return _byte0;
|
||||
if (_byte1 == 0) yield break;
|
||||
yield return _byte1;
|
||||
if (_byte2 == 0) yield break;
|
||||
yield return _byte2;
|
||||
if (_byte3 == 0) yield break;
|
||||
yield return _byte3;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/VRM/UniJSON/Scripts/Utf8String/IUtf8String.cs.meta
Normal file
12
Assets/VRM/UniJSON/Scripts/Utf8String/IUtf8String.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d41f7c86ebb46934c8511b31de827279
|
||||
timeCreated: 1543422872
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
199
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8Iterator.cs
Normal file
199
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8Iterator.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public struct Utf8Iterator : IEnumerator<Byte>
|
||||
{
|
||||
Byte[] m_bytes;
|
||||
int m_offset;
|
||||
int m_start;
|
||||
int m_position;
|
||||
int m_end;
|
||||
|
||||
public Utf8Iterator(ArraySegment<Byte> range, int start = 0)
|
||||
{
|
||||
m_bytes = range.Array;
|
||||
m_offset = range.Offset;
|
||||
m_start = m_offset + start;
|
||||
m_position = -1;
|
||||
m_end = range.Offset + range.Count;
|
||||
}
|
||||
|
||||
public int BytePosition
|
||||
{
|
||||
get { return m_position - m_offset; }
|
||||
}
|
||||
|
||||
public int CurrentByteLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var firstByte = Current;
|
||||
if (firstByte <= 0x7F)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (firstByte <= 0xDF)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if (firstByte <= 0xEF)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else if (firstByte <= 0xF7)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("invalid utf8");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte Current
|
||||
{
|
||||
get { return m_bytes[m_position]; }
|
||||
}
|
||||
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get { return Current; }
|
||||
}
|
||||
|
||||
public byte Second
|
||||
{
|
||||
get { return m_bytes[m_position + 1]; }
|
||||
}
|
||||
|
||||
public byte Third
|
||||
{
|
||||
get { return m_bytes[m_position + 2]; }
|
||||
}
|
||||
|
||||
public byte Fourth
|
||||
{
|
||||
get { return m_bytes[m_position + 3]; }
|
||||
}
|
||||
|
||||
public const uint Mask1 = 0x01;
|
||||
public const uint Mask2 = 0x03;
|
||||
public const uint Mask3 = 0x07;
|
||||
public const uint Mask4 = 0x0F;
|
||||
public const uint Mask5 = 0x1F;
|
||||
public const uint Mask6 = 0x3F;
|
||||
public const uint Mask7 = 0x7F;
|
||||
public const uint Mask11 = 0x07FF;
|
||||
|
||||
public const uint Head1 = 0x80;
|
||||
public const uint Head2 = 0xC0;
|
||||
public const uint Head3 = 0xE0;
|
||||
public const uint Head4 = 0xF0;
|
||||
|
||||
public static int ByteLengthFromChar(char c)
|
||||
{
|
||||
if (c <= Mask7)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (c <= Mask11)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
public uint Unicode
|
||||
{
|
||||
get
|
||||
{
|
||||
var l = CurrentByteLength;
|
||||
if (l == 1)
|
||||
{
|
||||
// 7bit
|
||||
return Current;
|
||||
}
|
||||
else if (l == 2)
|
||||
{
|
||||
// 11bit
|
||||
return (Mask5 & Current) << 6 | (Mask6 & Second);
|
||||
}
|
||||
else if (l == 3)
|
||||
{
|
||||
// 16bit
|
||||
return (Mask4 & Current) << 12 | (Mask6 & Second) << 6 | (Mask6 & Third);
|
||||
}
|
||||
else if (l == 4)
|
||||
{
|
||||
// 21bit
|
||||
return (Mask3 & Current) << 18 | (Mask6 & Second) << 12 | (Mask6 & Third) << 6 | (Mask6 & Fourth);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("invalid utf8");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public char Char
|
||||
{
|
||||
get
|
||||
{
|
||||
var l = CurrentByteLength;
|
||||
if (l == 1)
|
||||
{
|
||||
// 7bit
|
||||
return (char)Current;
|
||||
}
|
||||
else if (l == 2)
|
||||
{
|
||||
// 11bit
|
||||
return (char)((Mask5 & Current) << 6 | (Mask6 & Second));
|
||||
}
|
||||
else if (l == 3)
|
||||
{
|
||||
// 16bit
|
||||
return (char)((Mask4 & Current) << 12 | (Mask6 & Second) << 6 | (Mask6 & Third));
|
||||
}
|
||||
else if (l == 4)
|
||||
{
|
||||
// 21bit
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("invalid utf8");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (m_position == -1)
|
||||
{
|
||||
m_position = m_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_position += CurrentByteLength;
|
||||
}
|
||||
return m_position < m_end;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_position = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8Iterator.cs.meta
Normal file
12
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8Iterator.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5c7531d2d3a77a4ba81e8ee43426726
|
||||
timeCreated: 1544057442
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
444
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8String.cs
Normal file
444
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8String.cs
Normal file
@@ -0,0 +1,444 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public struct Utf8String : IComparable<Utf8String>
|
||||
{
|
||||
public static readonly System.Text.Encoding Encoding = new System.Text.UTF8Encoding(false);
|
||||
|
||||
public readonly ArraySegment<Byte> Bytes;
|
||||
public int ByteLength
|
||||
{
|
||||
get { return Bytes.Count; }
|
||||
}
|
||||
|
||||
public Utf8Iterator GetIterator()
|
||||
{
|
||||
return new Utf8Iterator(Bytes);
|
||||
}
|
||||
|
||||
public int CompareTo(Utf8String other)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < ByteLength && i < other.ByteLength; ++i)
|
||||
{
|
||||
if (this[i] < other[i])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (this[i] > other[i])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (i < ByteLength)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (i < other.ByteLength)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Byte this[int i]
|
||||
{
|
||||
get { return Bytes.Array[Bytes.Offset + i]; }
|
||||
}
|
||||
|
||||
public Utf8String(ArraySegment<Byte> bytes)
|
||||
{
|
||||
Bytes = bytes;
|
||||
}
|
||||
|
||||
public Utf8String(Byte[] bytes, int offset, int count) : this(new ArraySegment<Byte>(bytes, offset, count))
|
||||
{
|
||||
}
|
||||
|
||||
public Utf8String(Byte[] bytes) : this(bytes, 0, bytes.Length)
|
||||
{
|
||||
}
|
||||
|
||||
public static Utf8String From(string src)
|
||||
{
|
||||
return new Utf8String(Encoding.GetBytes(src));
|
||||
}
|
||||
|
||||
public static Utf8String From(string src, Byte[] bytes)
|
||||
{
|
||||
var required = src.Sum(c => Utf8Iterator.ByteLengthFromChar(c));
|
||||
if (required > bytes.Length)
|
||||
{
|
||||
throw new OverflowException();
|
||||
}
|
||||
int pos = 0;
|
||||
foreach (var c in src)
|
||||
{
|
||||
if (c <= Utf8Iterator.Mask7)
|
||||
{
|
||||
// 1bit
|
||||
bytes[pos++] = (byte)c;
|
||||
}
|
||||
else if (c <= Utf8Iterator.Mask11)
|
||||
{
|
||||
// 2bit
|
||||
bytes[pos++] = (byte)(Utf8Iterator.Head2 | Utf8Iterator.Mask5 & (c >> 6));
|
||||
bytes[pos++] = (byte)(Utf8Iterator.Head1 | Utf8Iterator.Mask6 & (c));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 3bit
|
||||
bytes[pos++] = (byte)(Utf8Iterator.Head3 | Utf8Iterator.Mask4 & (c >> 12));
|
||||
bytes[pos++] = (byte)(Utf8Iterator.Head1 | Utf8Iterator.Mask6 & (c >> 6));
|
||||
bytes[pos++] = (byte)(Utf8Iterator.Head1 | Utf8Iterator.Mask6 & (c));
|
||||
}
|
||||
}
|
||||
return new Utf8String(new ArraySegment<byte>(bytes, 0, pos));
|
||||
}
|
||||
|
||||
// -2147483648 ~ 2147483647
|
||||
public static Utf8String From(int src)
|
||||
{
|
||||
if (src >= 0)
|
||||
{
|
||||
if (src < 10)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src),
|
||||
});
|
||||
}
|
||||
else if (src < 100)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 1000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 10000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 100000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 1000000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/100000),
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 10000000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/1000000),
|
||||
(byte)(0x30 + src/100000),
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 100000000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/10000000),
|
||||
(byte)(0x30 + src/1000000),
|
||||
(byte)(0x30 + src/100000),
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else if (src < 1000000000)
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/100000000),
|
||||
(byte)(0x30 + src/10000000),
|
||||
(byte)(0x30 + src/1000000),
|
||||
(byte)(0x30 + src/100000),
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Utf8String(new byte[] {
|
||||
(byte)(0x30 + src/1000000000),
|
||||
(byte)(0x30 + src/100000000),
|
||||
(byte)(0x30 + src/10000000),
|
||||
(byte)(0x30 + src/1000000),
|
||||
(byte)(0x30 + src/100000),
|
||||
(byte)(0x30 + src/10000),
|
||||
(byte)(0x30 + src/1000),
|
||||
(byte)(0x30 + src/100),
|
||||
(byte)(0x30 + src/10),
|
||||
(byte)(0x30 + src%10),
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public Utf8String Concat(Utf8String rhs)
|
||||
{
|
||||
var bytes = new Byte[ByteLength + rhs.ByteLength];
|
||||
Buffer.BlockCopy(Bytes.Array, Bytes.Offset, bytes, 0, ByteLength);
|
||||
Buffer.BlockCopy(rhs.Bytes.Array, rhs.Bytes.Offset, bytes, ByteLength, rhs.ByteLength);
|
||||
return new Utf8String(bytes);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (ByteLength == 0) return "";
|
||||
return Encoding.GetString(Bytes.Array, Bytes.Offset, Bytes.Count);
|
||||
}
|
||||
|
||||
public string ToAscii()
|
||||
{
|
||||
if (ByteLength == 0) return "";
|
||||
return System.Text.Encoding.ASCII.GetString(Bytes.Array, Bytes.Offset, Bytes.Count);
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return ByteLength == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartsWith(Utf8String rhs)
|
||||
{
|
||||
if (rhs.ByteLength > ByteLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rhs.ByteLength; ++i)
|
||||
{
|
||||
if (this[i] != rhs[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool EndsWith(Utf8String rhs)
|
||||
{
|
||||
if (rhs.ByteLength > ByteLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= rhs.ByteLength; ++i)
|
||||
{
|
||||
if (this[ByteLength - i] != rhs[rhs.ByteLength - i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int IndexOf(Byte code)
|
||||
{
|
||||
return IndexOf(0, code);
|
||||
}
|
||||
|
||||
public int IndexOf(int offset, Byte code)
|
||||
{
|
||||
var pos = offset + Bytes.Offset;
|
||||
for (int i = 0; i < Bytes.Count; ++i, ++pos)
|
||||
{
|
||||
if (Bytes.Array[pos] == code)
|
||||
{
|
||||
return pos - Bytes.Offset;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Utf8String Subbytes(int offset)
|
||||
{
|
||||
return Subbytes(offset, ByteLength - offset);
|
||||
}
|
||||
|
||||
public Utf8String Subbytes(int offset, int count)
|
||||
{
|
||||
return new Utf8String(Bytes.Array, Bytes.Offset + offset, count);
|
||||
}
|
||||
|
||||
static bool IsSpace(Byte b)
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case 0x20:
|
||||
case 0x0a:
|
||||
case 0x0b:
|
||||
case 0x0c:
|
||||
case 0x0d:
|
||||
case 0x09:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Utf8String TrimStart()
|
||||
{
|
||||
var i = 0;
|
||||
for (; i < ByteLength; ++i)
|
||||
{
|
||||
if (!IsSpace(this[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Subbytes(i);
|
||||
}
|
||||
|
||||
public Utf8String TrimEnd()
|
||||
{
|
||||
var i = ByteLength-1;
|
||||
for (; i >= 0; --i)
|
||||
{
|
||||
if (!IsSpace(this[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Subbytes(0, i+1);
|
||||
}
|
||||
|
||||
public Utf8String Trim()
|
||||
{
|
||||
return TrimStart().TrimEnd();
|
||||
}
|
||||
|
||||
public override bool Equals(Object obj)
|
||||
{
|
||||
return obj is Utf8String && Equals((Utf8String)obj);
|
||||
}
|
||||
|
||||
public static bool operator ==(Utf8String x, Utf8String y)
|
||||
{
|
||||
return x.Equals(y);
|
||||
}
|
||||
|
||||
public static bool operator !=(Utf8String x, Utf8String y)
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
public bool Equals(Utf8String other)
|
||||
{
|
||||
if (ByteLength != other.ByteLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ByteLength; ++i)
|
||||
{
|
||||
if (this[i] != other[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ByteLength.GetHashCode();
|
||||
}
|
||||
|
||||
public static Utf8String operator +(Utf8String l, Utf8String r)
|
||||
{
|
||||
return new Utf8String(l.Bytes.Concat(r.Bytes));
|
||||
}
|
||||
|
||||
public bool IsInt
|
||||
{
|
||||
get
|
||||
{
|
||||
//bool isInt = false;
|
||||
for (int i = 0; i < ByteLength; ++i)
|
||||
{
|
||||
var c = this[i];
|
||||
if (c == '0'
|
||||
|| c == '1'
|
||||
|| c == '2'
|
||||
|| c == '3'
|
||||
|| c == '4'
|
||||
|| c == '5'
|
||||
|| c == '6'
|
||||
|| c == '7'
|
||||
|| c == '8'
|
||||
|| c == '9'
|
||||
)
|
||||
{
|
||||
// ok
|
||||
//isInt = true;
|
||||
}
|
||||
else if (i == 0 && c == '-')
|
||||
{
|
||||
// ok
|
||||
}
|
||||
else if (c == '.' || c == 'e')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8String.cs.meta
Normal file
11
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8String.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93adff1e1b4725f498a92faccf7e240d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8StringBuilder.cs
Normal file
33
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8StringBuilder.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Text;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class Utf8StringBuilder
|
||||
{
|
||||
ByteBuffer m_buffer = new ByteBuffer();
|
||||
|
||||
public void Ascii(char c)
|
||||
{
|
||||
m_buffer.Push((byte)c);
|
||||
}
|
||||
|
||||
static Encoding s_utf8 = new UTF8Encoding(false);
|
||||
|
||||
public void Quote(string text)
|
||||
{
|
||||
Ascii('"');
|
||||
m_buffer.Push(s_utf8.GetBytes(text));
|
||||
Ascii('"');
|
||||
}
|
||||
|
||||
public void Add(Utf8String str)
|
||||
{
|
||||
m_buffer.Push(str.Bytes);
|
||||
}
|
||||
|
||||
public Utf8String ToUtf8String()
|
||||
{
|
||||
return new Utf8String(m_buffer.Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba2dbf26152e2704d986754eb12f5af4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
341
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8StringExtensions.cs
Normal file
341
Assets/VRM/UniJSON/Scripts/Utf8String/Utf8StringExtensions.cs
Normal file
@@ -0,0 +1,341 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class Utf8StringExtensions
|
||||
{
|
||||
public static void WriteTo(this Utf8String src, Stream dst)
|
||||
{
|
||||
dst.Write(src.Bytes.Array, src.Bytes.Offset, src.Bytes.Count);
|
||||
}
|
||||
|
||||
public static Utf8Iterator GetFirst(this Utf8String src)
|
||||
{
|
||||
var it = src.GetIterator();
|
||||
it.MoveNext();
|
||||
return it;
|
||||
}
|
||||
|
||||
public static bool TrySearchByte(this Utf8String src, Func<byte, bool> pred, out int pos)
|
||||
{
|
||||
pos = 0;
|
||||
for (; pos < src.ByteLength; ++pos)
|
||||
{
|
||||
if (pred(src[pos]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TrySearchAscii(this Utf8String src, Byte target, int start, out int pos)
|
||||
{
|
||||
var p = new Utf8Iterator(src.Bytes, start);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
if (b <= 0x7F)
|
||||
{
|
||||
// ascii
|
||||
if (b == target/*'\"'*/)
|
||||
{
|
||||
// closed
|
||||
pos = p.BytePosition;
|
||||
return true;
|
||||
}
|
||||
else if (b == '\\')
|
||||
{
|
||||
// escaped
|
||||
switch ((char)p.Second)
|
||||
{
|
||||
case '"': // fall through
|
||||
case '\\': // fall through
|
||||
case '/': // fall through
|
||||
case 'b': // fall through
|
||||
case 'f': // fall through
|
||||
case 'n': // fall through
|
||||
case 'r': // fall through
|
||||
case 't': // fall through
|
||||
// skip next
|
||||
p.MoveNext();
|
||||
break;
|
||||
|
||||
case 'u': // unicode
|
||||
// skip next 4
|
||||
p.MoveNext();
|
||||
p.MoveNext();
|
||||
p.MoveNext();
|
||||
p.MoveNext();
|
||||
break;
|
||||
|
||||
default:
|
||||
// unkonw escape
|
||||
throw new ParserException("unknown escape: " + p.Second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pos = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<Utf8String> Split(this Utf8String src, byte delemeter)
|
||||
{
|
||||
var start = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
if (p.Current == delemeter)
|
||||
{
|
||||
if (p.BytePosition - start == 0)
|
||||
{
|
||||
yield return default(Utf8String);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return src.Subbytes(start, p.BytePosition - start);
|
||||
}
|
||||
start = p.BytePosition + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (start < p.BytePosition)
|
||||
{
|
||||
yield return src.Subbytes(start, p.BytePosition - start);
|
||||
}
|
||||
}
|
||||
|
||||
#region atoi
|
||||
public static SByte ToSByte(this Utf8String src)
|
||||
{
|
||||
SByte value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (SByte)(value * 10); break;
|
||||
case 0x31: value = (SByte)(value * 10 + 1); break;
|
||||
case 0x32: value = (SByte)(value * 10 + 2); break;
|
||||
case 0x33: value = (SByte)(value * 10 + 3); break;
|
||||
case 0x34: value = (SByte)(value * 10 + 4); break;
|
||||
case 0x35: value = (SByte)(value * 10 + 5); break;
|
||||
case 0x36: value = (SByte)(value * 10 + 6); break;
|
||||
case 0x37: value = (SByte)(value * 10 + 7); break;
|
||||
case 0x38: value = (SByte)(value * 10 + 8); break;
|
||||
case 0x39: value = (SByte)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static Int16 ToInt16(this Utf8String src)
|
||||
{
|
||||
Int16 value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (Int16)(value * 10); break;
|
||||
case 0x31: value = (Int16)(value * 10 + 1); break;
|
||||
case 0x32: value = (Int16)(value * 10 + 2); break;
|
||||
case 0x33: value = (Int16)(value * 10 + 3); break;
|
||||
case 0x34: value = (Int16)(value * 10 + 4); break;
|
||||
case 0x35: value = (Int16)(value * 10 + 5); break;
|
||||
case 0x36: value = (Int16)(value * 10 + 6); break;
|
||||
case 0x37: value = (Int16)(value * 10 + 7); break;
|
||||
case 0x38: value = (Int16)(value * 10 + 8); break;
|
||||
case 0x39: value = (Int16)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static Int32 ToInt32(this Utf8String src)
|
||||
{
|
||||
Int32 value = 0;
|
||||
Int32 sign = 1;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
bool isFirst = true;
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
|
||||
if (isFirst)
|
||||
{
|
||||
isFirst = false;
|
||||
if (b == '-')
|
||||
{
|
||||
sign = -1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = value * 10; break;
|
||||
case 0x31: value = value * 10 + 1; break;
|
||||
case 0x32: value = value * 10 + 2; break;
|
||||
case 0x33: value = value * 10 + 3; break;
|
||||
case 0x34: value = value * 10 + 4; break;
|
||||
case 0x35: value = value * 10 + 5; break;
|
||||
case 0x36: value = value * 10 + 6; break;
|
||||
case 0x37: value = value * 10 + 7; break;
|
||||
case 0x38: value = value * 10 + 8; break;
|
||||
case 0x39: value = value * 10 + 9; break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value * sign;
|
||||
}
|
||||
public static Int64 ToInt64(this Utf8String src)
|
||||
{
|
||||
Int64 value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (Int64)(value * 10); break;
|
||||
case 0x31: value = (Int64)(value * 10 + 1); break;
|
||||
case 0x32: value = (Int64)(value * 10 + 2); break;
|
||||
case 0x33: value = (Int64)(value * 10 + 3); break;
|
||||
case 0x34: value = (Int64)(value * 10 + 4); break;
|
||||
case 0x35: value = (Int64)(value * 10 + 5); break;
|
||||
case 0x36: value = (Int64)(value * 10 + 6); break;
|
||||
case 0x37: value = (Int64)(value * 10 + 7); break;
|
||||
case 0x38: value = (Int64)(value * 10 + 8); break;
|
||||
case 0x39: value = (Int64)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static Byte ToByte(this Utf8String src)
|
||||
{
|
||||
Byte value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (Byte)(value * 10); break;
|
||||
case 0x31: value = (Byte)(value * 10 + 1); break;
|
||||
case 0x32: value = (Byte)(value * 10 + 2); break;
|
||||
case 0x33: value = (Byte)(value * 10 + 3); break;
|
||||
case 0x34: value = (Byte)(value * 10 + 4); break;
|
||||
case 0x35: value = (Byte)(value * 10 + 5); break;
|
||||
case 0x36: value = (Byte)(value * 10 + 6); break;
|
||||
case 0x37: value = (Byte)(value * 10 + 7); break;
|
||||
case 0x38: value = (Byte)(value * 10 + 8); break;
|
||||
case 0x39: value = (Byte)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static UInt16 ToUInt16(this Utf8String src)
|
||||
{
|
||||
UInt16 value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (UInt16)(value * 10); break;
|
||||
case 0x31: value = (UInt16)(value * 10 + 1); break;
|
||||
case 0x32: value = (UInt16)(value * 10 + 2); break;
|
||||
case 0x33: value = (UInt16)(value * 10 + 3); break;
|
||||
case 0x34: value = (UInt16)(value * 10 + 4); break;
|
||||
case 0x35: value = (UInt16)(value * 10 + 5); break;
|
||||
case 0x36: value = (UInt16)(value * 10 + 6); break;
|
||||
case 0x37: value = (UInt16)(value * 10 + 7); break;
|
||||
case 0x38: value = (UInt16)(value * 10 + 8); break;
|
||||
case 0x39: value = (UInt16)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static UInt32 ToUInt32(this Utf8String src)
|
||||
{
|
||||
UInt32 value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (UInt32)(value * 10); break;
|
||||
case 0x31: value = (UInt32)(value * 10 + 1); break;
|
||||
case 0x32: value = (UInt32)(value * 10 + 2); break;
|
||||
case 0x33: value = (UInt32)(value * 10 + 3); break;
|
||||
case 0x34: value = (UInt32)(value * 10 + 4); break;
|
||||
case 0x35: value = (UInt32)(value * 10 + 5); break;
|
||||
case 0x36: value = (UInt32)(value * 10 + 6); break;
|
||||
case 0x37: value = (UInt32)(value * 10 + 7); break;
|
||||
case 0x38: value = (UInt32)(value * 10 + 8); break;
|
||||
case 0x39: value = (UInt32)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static UInt64 ToUInt64(this Utf8String src)
|
||||
{
|
||||
UInt64 value = 0;
|
||||
var p = new Utf8Iterator(src.Bytes);
|
||||
while (p.MoveNext())
|
||||
{
|
||||
var b = p.Current;
|
||||
switch (b)
|
||||
{
|
||||
case 0x30: value = (UInt64)(value * 10); break;
|
||||
case 0x31: value = (UInt64)(value * 10 + 1); break;
|
||||
case 0x32: value = (UInt64)(value * 10 + 2); break;
|
||||
case 0x33: value = (UInt64)(value * 10 + 3); break;
|
||||
case 0x34: value = (UInt64)(value * 10 + 4); break;
|
||||
case 0x35: value = (UInt64)(value * 10 + 5); break;
|
||||
case 0x36: value = (UInt64)(value * 10 + 6); break;
|
||||
case 0x37: value = (UInt64)(value * 10 + 7); break;
|
||||
case 0x38: value = (UInt64)(value * 10 + 8); break;
|
||||
case 0x39: value = (UInt64)(value * 10 + 9); break;
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static float ToSingle(this Utf8String src)
|
||||
{
|
||||
return Single.Parse(src.ToAscii(), System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
public static double ToDouble(this Utf8String src)
|
||||
{
|
||||
return Double.Parse(src.ToAscii(), System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static Utf8String GetLine(this Utf8String src)
|
||||
{
|
||||
int pos;
|
||||
if (!src.TrySearchAscii((byte)'\n', 0, out pos))
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
||||
return src.Subbytes(0, pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f613907c8a91aa049809fe1f754776de
|
||||
timeCreated: 1544060764
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static class Utf8StringSplitterExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Split integer from start
|
||||
///
|
||||
/// "123 " => "123"
|
||||
/// " 123" => FormatException
|
||||
///
|
||||
/// must start +-0123456789
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <returns></returns>
|
||||
public static Utf8String SplitInteger(this Utf8String src)
|
||||
{
|
||||
var i = 0;
|
||||
if(src[0]=='+' || src[0] == '-')
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
var j = i;
|
||||
for(; j<src.ByteLength; ++j)
|
||||
{
|
||||
if(src[j]<'0' || src[j]>'9')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == j)
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
return src.Subbytes(0, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1627ff7e9bb16a8459021fda0223909c
|
||||
timeCreated: 1545735556
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user