コード例 #1
0
        public static Utf8Iterator GetFirst(this Utf8String src)
        {
            var it = src.GetIterator();

            it.MoveNext();
            return(it);
        }
コード例 #2
0
ファイル: JsonString.cs プロジェクト: vrm-c/UniVRM_1_0
        public static void Escape(Utf8String s, IStore w)
        {
            if (s.IsEmpty)
            {
                return;
            }

            var it = s.GetIterator();

            while (it.MoveNext())
            {
                var l = it.CurrentByteLength;
                if (l == 1)
                {
                    var b = it.Current;
                    switch (b)
                    {
                    case (Byte)'"':
                    case (Byte)'\\':
                    case (Byte)'/':
                        // \\ prefix
                        w.Write((Byte)'\\');
                        w.Write(b);
                        break;

                    case (Byte)'\b':
                        w.Write((Byte)'\\');
                        w.Write((Byte)'b');
                        break;

                    case (Byte)'\f':
                        w.Write((Byte)'\\');
                        w.Write((Byte)'f');
                        break;

                    case (Byte)'\n':
                        w.Write((Byte)'\\');
                        w.Write((Byte)'n');
                        break;

                    case (Byte)'\r':
                        w.Write((Byte)'\\');
                        w.Write((Byte)'r');
                        break;

                    case (Byte)'\t':
                        w.Write((Byte)'\\');
                        w.Write((Byte)'t');
                        break;

                    default:
                        w.Write(b);
                        break;
                    }
                    // ascii
                }
                else if (l == 2)
                {
                    w.Write(it.Current);
                    w.Write(it.Second);
                }
                else if (l == 3)
                {
                    w.Write(it.Current);
                    w.Write(it.Second);
                    w.Write(it.Third);
                }
                else if (l == 4)
                {
                    w.Write(it.Current);
                    w.Write(it.Second);
                    w.Write(it.Third);
                    w.Write(it.Fourth);
                }
                else
                {
                    throw new ParserException("invalid utf8");
                }
            }
        }
コード例 #3
0
ファイル: JsonString.cs プロジェクト: vrm-c/UniVRM_1_0
        public static int Unescape(Utf8String s, IStore w)
        {
            int           writeCount = 0;
            Action <Byte> Write      = c =>
            {
                if (w != null)
                {
                    w.Write(c);
                }
                ++writeCount;
            };

            var it = s.GetIterator();

            while (it.MoveNext())
            {
                var l = it.CurrentByteLength;
                if (l == 1)
                {
                    if (it.Current == (Byte)'\\')
                    {
                        var c = it.Second;
                        switch (c)
                        {
                        case (Byte)'\\':
                        case (Byte)'/':
                        case (Byte)'"':
                            // remove prefix
                            Write(c);
                            it.MoveNext();
                            continue;

                        case (Byte)'b':
                            Write((Byte)'\b');
                            it.MoveNext();
                            continue;

                        case (Byte)'f':
                            Write((Byte)'\f');
                            it.MoveNext();
                            continue;

                        case (Byte)'n':
                            Write((Byte)'\n');
                            it.MoveNext();
                            continue;

                        case (Byte)'r':
                            Write((Byte)'\r');
                            it.MoveNext();
                            continue;

                        case (Byte)'t':
                            Write((Byte)'\t');
                            it.MoveNext();
                            continue;
                        }
                    }

                    Write(it.Current);
                }
                else if (l == 2)
                {
                    Write(it.Current);
                    Write(it.Second);
                }
                else if (l == 3)
                {
                    Write(it.Current);
                    Write(it.Second);
                    Write(it.Third);
                }
                else if (l == 4)
                {
                    Write(it.Current);
                    Write(it.Second);
                    Write(it.Third);
                    Write(it.Fourth);
                }
                else
                {
                    throw new ParserException("invalid utf8");
                }
            }

            return(writeCount);
        }