Exemplo n.º 1
0
 private static void StripStringBurst(ref ReadOnlyStringEntity source,
                                      ref ReadOnlyStringEntity target,
                                      bool left, bool right,
                                      out ReadOnlyStringEntity result)
 {
     result = StringStripperExt.StripStringImpl(source, target, left, right);
 }
Exemplo n.º 2
0
        private void CheckCollections()
        {
            Assert.AreEqual(str_native.Length, str_list.Count);

            int elem_len = math.min(str_native.Length, str_list.Count);

            for (int i = 0; i < elem_len; i++)
            {
                StringEntity entity  = str_native[i];
                string       str_e   = entity.ToString();
                char[]       c_arr_e = entity.ToArray();

                ReadOnlyStringEntity entity_ro = entity.GetReadOnly();

                string str   = str_list[i];
                char[] c_arr = str.ToCharArray();

                Assert.AreEqual(str_e, str);
                Assert.AreEqual(c_arr_e.ToString(), c_arr.ToString());

                Assert.IsTrue(entity.Equals(str));
                Assert.IsTrue(entity.Equals(c_arr));
                if (str.Length == 1)
                {
                    Assert.IsTrue(entity.Equals(str[0]));
                }

                Assert.IsTrue(entity_ro.Equals(str));
                Assert.IsTrue(entity_ro.Equals(c_arr));
                if (str.Length == 1)
                {
                    Assert.IsTrue(entity_ro.Equals(str[0]));
                }
            }
        }
        public void CheckParseInt64(int n_numeric_string)
        {
            // random value check
            this.GenerateRandomIntStrings(n_numeric_string, 9, 19, 128);

            int long_count = 0;

            for (int i = 0; i < n_numeric_string; i++)
            {
                string str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = long.TryParse(str, out long value);
                bool success_e = str_e.TryParse(out long value_e);

                Assert.AreEqual(success, success_e);
                Assert.AreEqual(value, value_e);

                if (success != success_e || value != value_e)
                {
                    Debug.LogError("failed to parse. string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "]");
                }
                if (success)
                {
                    long_count++;
                }
            }
            Debug.Log("parsed long count = " + long_count.ToString() + " / " + n_numeric_string.ToString());
        }
        private void CheckParseHexFloat64(NativeStringList str_native_big, NativeStringList str_native_lit)
        {
            // double hex
            double[] double_list = new double[]
            {
                0.0, 128.0, 512.0, 12345.67, -12345678,
                -9223372036854775808d, 9223372036854775807d,
                -3.40281e+38, 3.40281E+38,
                -1.797693134862e+308, 1.797693134862E+308
            };

            str_native_big.Clear();
            str_native_lit.Clear();

            for (int i = 0; i < double_list.Length; i++)
            {
                double double_v = double_list[i];
                byte[] bytes    = BitConverter.GetBytes(double_v);
                string str      = BitConverter.ToString(bytes).Replace("-", ""); // BitConverter returns little endian code on x86.
                string str_0x   = "0x" + str;

                str_native_lit.Add(str);
                str_native_lit.Add(str_0x);
                str_native_big.Add(this.ConvertEndian(str));
                str_native_big.Add(this.ConvertEndian(str_0x));
            }
            for (int i = 0; i < str_native_lit.Length; i++)
            {
                double value_ref             = double_list[i / 2];
                ReadOnlyStringEntity str_lit = str_native_lit[i];
                ReadOnlyStringEntity str_big = str_native_big[i];

                bool success_lit = str_lit.TryParseHex(out double value_lit);
                bool success_big = str_big.TryParseHex(out double value_big, Endian.Big);

                Debug.Log("parse str[big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                          + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                          + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");

                Assert.IsTrue(success_lit);
                Assert.IsTrue(success_big);
                Assert.AreEqual(value_ref, value_lit);
                Assert.AreEqual(value_ref, value_big);
                // must be bit-complete convertion in hex data format
                if ((value_ref != value_lit || value_ref != value_big) || !success_lit || !success_big)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString()
                                   + " string [big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                                   + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                                   + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");
                }
            }
        }
        public void CheckParseFloat64_Boundary()
        {
            // boundary value check
            str_native.Clear();
            str_list.Clear();

            string in_range_lo  = "-1.797693134862e+308";
            string in_range_hi  = "1.797693134862E+308";
            string out_range_lo = "-1.797693134863e+308";
            string out_range_hi = "1.797693134863E+308";

            str_list.Add(in_range_lo.ToString());
            str_list.Add(in_range_hi.ToString());
            str_list.Add(out_range_lo.ToString());
            str_list.Add(out_range_hi.ToString());

            // this implementation don't aim perfect accuracy for IEEE754 convertion.
            //   Epsilon = 4.94065645841247e-324
            str_list.Add("1e-323");
            str_list.Add("-1e-323");
            str_list.Add("1e-325");
            str_list.Add("-1e-325");

            str_list.Add("00924731130.63782E+299");

            for (int i = 0; i < str_list.Count; i++)
            {
                str_native.Add(str_list[i]);
            }

            for (int i = 0; i < str_native.Length; i++)
            {
                var str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = double.TryParse(str, out double value);
                bool success_e = str_e.TryParse(out double value_e);

                Assert.AreEqual(success, success_e);

                bool check_value = this.EqualsDouble(value, value_e, 1.0e-14, out double rel_diff);
                if (!check_value || success != success_e)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString() + " string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "], rel_diff = " + rel_diff.ToString());
                }
                Assert.IsTrue(check_value);
            }
        }
        public void CheckParseFloat32_Boundary()
        {
            // boundary value check
            str_native.Clear();
            str_list.Clear();

            string in_range_lo  = "-3.40281e+38";
            string in_range_hi  = "3.40281E+38";
            string out_range_lo = "-3.40283e+38";
            string out_range_hi = "3.40283E+38";

            str_list.Add(in_range_lo.ToString());
            str_list.Add(in_range_hi.ToString());
            str_list.Add(out_range_lo.ToString());
            str_list.Add(out_range_hi.ToString());

            str_list.Add("1.401298e-45");  // float.Elipson
            str_list.Add("-1.401298e-45");

            str_list.Add("1.401297e-45");
            str_list.Add("-1.401297e-45");

            for (int i = 0; i < str_list.Count; i++)
            {
                str_native.Add(str_list[i]);
            }

            for (int i = 0; i < str_native.Length; i++)
            {
                var str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                //Debug.Log($"@ parse target: {str_e}");

                bool success   = float.TryParse(str, out float value);
                bool success_e = str_e.TryParse(out float value_e);

                Assert.AreEqual(success, success_e);

                bool check_value = this.EqualsFloat(value, value_e, 1.0e-5f, out float rel_diff);
                if (!check_value || success != success_e)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString() + " string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "], rel_diff = " + rel_diff.ToString());
                }
                Assert.IsTrue(check_value);
            }
        }
        private void CheckParseHexFloat32(NativeStringList str_native_big, NativeStringList str_native_lit)
        {
            // float hex
            float[] float_list = new float[] { 0.0f, 128.0f, 512.0f, 12345.67f, -12345678f, -3.40281e+38f, 3.40281E+38f };

            str_native_big.Clear();
            str_native_lit.Clear();

            for (int i = 0; i < float_list.Length; i++)
            {
                float  float_v = float_list[i];
                byte[] bytes   = BitConverter.GetBytes(float_v);
                string str     = BitConverter.ToString(bytes).Replace("-", ""); // BitConverter returns little endian code on x86.
                string str_0x  = "0x" + str;

                str_native_lit.Add(str);
                str_native_lit.Add(str_0x);
                str_native_big.Add(this.ConvertEndian(str));
                str_native_big.Add(this.ConvertEndian(str_0x));
            }
            for (int i = 0; i < str_native_lit.Length; i++)
            {
                float value_ref = float_list[i / 2];
                ReadOnlyStringEntity str_lit = str_native_lit[i];
                ReadOnlyStringEntity str_big = str_native_big[i];

                bool success_lit = str_lit.TryParseHex(out float value_lit);
                bool success_big = str_big.TryParseHex(out float value_big, Endian.Big);

                Debug.Log("parse str[big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                          + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                          + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");

                Assert.IsTrue(success_lit);
                Assert.IsTrue(success_big);
                Assert.AreEqual(value_ref, value_lit);
                Assert.AreEqual(value_ref, value_big);
                // must be bit-complete convertion in hex data format
                if ((value_ref != value_lit || value_ref != value_big) || !success_lit || !success_big)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString()
                                   + " string [big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                                   + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                                   + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");
                }
            }
        }
        private void CheckParseHexInt32(NativeStringList str_native_big, NativeStringList str_native_lit)
        {
            // int hex
            int[] int_list = new int[] { 0, 128, 512, 10000, -12345678, -2147483648, 2147483647 };

            str_native_big.Clear();
            str_native_lit.Clear();

            for (int i = 0; i < int_list.Length; i++)
            {
                int    int_v  = int_list[i];
                byte[] bytes  = BitConverter.GetBytes(int_v);
                string str    = BitConverter.ToString(bytes).Replace("-", ""); // BitConverter returns little endian code on x86.
                string str_0x = "0x" + str;

                str_native_lit.Add(str);
                str_native_lit.Add(str_0x);
                str_native_big.Add(this.ConvertEndian(str));
                str_native_big.Add(this.ConvertEndian(str_0x));
            }
            for (int i = 0; i < str_native_lit.Length; i++)
            {
                int value_ref = int_list[i / 2];  // stored 2x elems as [hex data] and 0x[hex data]
                ReadOnlyStringEntity str_lit = str_native_lit[i];
                ReadOnlyStringEntity str_big = str_native_big[i];

                bool success_lit = str_lit.TryParseHex(out int value_lit);
                bool success_big = str_big.TryParseHex(out int value_big, Endian.Big);

                Debug.Log("parse str[big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                          + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                          + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");

                Assert.IsTrue(success_lit);
                Assert.IsTrue(success_big);
                Assert.AreEqual(value_ref, value_lit);
                Assert.AreEqual(value_ref, value_big);
                if ((value_ref != value_lit || value_ref != value_big) || !success_lit || !success_big)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString()
                                   + " string [big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                                   + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                                   + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");
                }
            }
        }
        private void CheckParseHexInt64(NativeStringList str_native_big, NativeStringList str_native_lit)
        {
            // long hex
            long[] long_list = new long[] { 0, 128, 512, 10000, -12345678, -9223372036854775808, 9223372036854775807 };

            str_native_big.Clear();
            str_native_lit.Clear();

            for (int i = 0; i < long_list.Length; i++)
            {
                long   long_v = long_list[i];
                byte[] bytes  = BitConverter.GetBytes(long_v);
                string str    = BitConverter.ToString(bytes).Replace("-", ""); // BitConverter returns little endian code on x86.
                string str_0x = "0x" + str;

                str_native_lit.Add(str);
                str_native_lit.Add(str_0x);
                str_native_big.Add(this.ConvertEndian(str));
                str_native_big.Add(this.ConvertEndian(str_0x));
            }
            for (int i = 0; i < str_native_lit.Length; i++)
            {
                long value_ref = long_list[i / 2];
                ReadOnlyStringEntity str_lit = str_native_lit[i];
                ReadOnlyStringEntity str_big = str_native_big[i];

                bool success_lit = str_lit.TryParseHex(out long value_lit);
                bool success_big = str_big.TryParseHex(out long value_big, Endian.Big);

                Debug.Log("parse str[big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                          + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                          + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");

                Assert.IsTrue(success_lit);
                Assert.IsTrue(success_big);
                Assert.AreEqual(value_ref, value_lit);
                Assert.AreEqual(value_ref, value_big);
                if ((value_ref != value_lit || value_ref != value_big) || !success_lit || !success_big)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString()
                                   + " string [big/little] = [" + str_big.ToString() + "/" + str_lit.ToString()
                                   + "], try[big/little] = [" + success_big.ToString() + "/" + success_lit.ToString()
                                   + "], value[ref/big/little] = [" + value_ref.ToString() + "/" + value_big.ToString() + "/" + value_lit.ToString() + "]");
                }
            }
        }
        public void CheckParseFloat32(int n_numeric_string)
        {
            this.GenerateRandomFloatStrings(n_numeric_string, 3, 8, 39, 64);

            int fail_count = 0;

            float max_rel_err = 0.0f;
            int   max_err_id  = 0;

            int float_count = 0;

            for (int i = 0; i < n_numeric_string; i++)
            {
                string str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = float.TryParse(str, out float value);
                bool success_e = str_e.TryParse(out float value_e);

                Assert.AreEqual(success, success_e);

                bool check_value = this.EqualsFloat(value, value_e, 1.0e-5f, out float rel_diff);
                if (!check_value || success != success_e)
                {
                    fail_count++;
                    Debug.LogError("failed to parse i = " + i.ToString() + " string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "], rel_diff = " + rel_diff.ToString());
                }
                Assert.IsTrue(check_value);

                if (success)
                {
                    float_count++;
                }

                if (max_rel_err < rel_diff)
                {
                    max_rel_err = rel_diff;
                    max_err_id  = i;
                }
            }
            Debug.Log("parsed float count = " + float_count.ToString() + " / " + n_numeric_string.ToString());
            Debug.Log("max relative error = " + max_rel_err.ToString() + " at " + str_list[max_err_id]);
        }
Exemplo n.º 11
0
        private void ApplyRemoveAt(int n_RemoveAt)
        {
            if (str_native.Length <= 0 || str_list.Count <= 0)
            {
                return;
            }
            if (n_RemoveAt <= 0)
            {
                return;
            }

            Assert.AreEqual(str_native.Length, str_list.Count);

            int i_range  = str_native.Length;
            int n_remove = math.min(n_RemoveAt, i_range);

            Debug.Log("str_native.Capacity = " + str_native.Capacity.ToString() + ", str_native.Size = " + str_native.Size.ToString()
                      + ", str_native.IndexCapacity = " + str_native.IndexCapacity.ToString() + ", str_native.Length = " + str_native.Length.ToString() + " (before remove)");

            for (int i = 0; i < n_remove; i++)
            {
                int index = random.Next(0, i_range);

                StringEntity         entity    = str_native.At(index);
                ReadOnlyStringEntity entity_ro = entity.GetReadOnly();

                //Debug.Log("delete: index = " + index.ToString());

                str_native.RemoveAt(index);
                str_list.RemoveAt(index);

                i_range--;
            }


            Debug.Log("str_native.Capacity = " + str_native.Capacity.ToString() + ", str_native.Size = " + str_native.Size.ToString()
                      + ", str_native.IndexCapacity = " + str_native.IndexCapacity.ToString() + ", str_native.Length = " + str_native.Length.ToString() + " (after remove)");
            str_native.ReAdjustment();
            Debug.Log("str_native.Capacity = " + str_native.Capacity.ToString() + ", str_native.Size = " + str_native.Size.ToString()
                      + ", str_native.IndexCapacity = " + str_native.IndexCapacity.ToString() + ", str_native.Length = " + str_native.Length.ToString() + " (after call 'ReAdjustment()')");
            str_native.ShrinkToFit();
            Debug.Log("str_native.Capacity = " + str_native.Capacity.ToString() + ", str_native.Size = " + str_native.Size.ToString()
                      + ", str_native.IndexCapacity = " + str_native.IndexCapacity.ToString() + ", str_native.Length = " + str_native.Length.ToString() + " (after call 'ShrinkToFit()')");
        }
        public void CheckParseFloat64(int n_numeric_string)
        {
            this.GenerateRandomFloatStrings(n_numeric_string, 2, 18, 309, 64);

            double max_rel_err = 0.0;
            int    max_err_id  = 0;

            int double_count = 0;

            for (int i = 0; i < n_numeric_string; i++)
            {
                string str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = double.TryParse(str, out double value);
                bool success_e = str_e.TryParse(out double value_e);

                //Debug.Log($"@ parse target: {str_e}");

                Assert.AreEqual(success, success_e);

                bool check_value = this.EqualsDouble(value, value_e, 1.0e-14, out double rel_diff);
                if (!check_value || success != success_e)
                {
                    Debug.LogError("failed to parse i = " + i.ToString() + " string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "], rel_diff = " + rel_diff.ToString());
                }
                Assert.IsTrue(check_value);

                if (success)
                {
                    double_count++;
                }

                if (max_rel_err < rel_diff)
                {
                    max_rel_err = rel_diff;
                    max_err_id  = i;
                }
            }
            Debug.Log("parsed double count = " + double_count.ToString() + " / " + n_numeric_string.ToString());
            Debug.Log("max relative error = " + max_rel_err.ToString() + " at " + str_list[max_err_id]);
        }
        public void CheckParseInt32_Boundary()
        {
            // boundary value check
            str_native.Clear();
            str_list.Clear();

            string in_range_lo  = "-2147483648";
            string in_range_hi  = "2147483647";
            string out_range_lo = "-2147483649";
            string out_range_hi = "2147483648";
            string out_sp_1     = "4400000000"; // overflow to plus region

            str_list.Add(in_range_lo.ToString());
            str_list.Add(in_range_hi.ToString());
            str_list.Add(out_range_lo.ToString());
            str_list.Add(out_range_hi.ToString());
            str_list.Add(out_sp_1.ToString());

            for (int i = 0; i < str_list.Count; i++)
            {
                str_native.Add(str_list[i]);
            }

            for (int i = 0; i < str_native.Length; i++)
            {
                var str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = int.TryParse(str, out int value);
                bool success_e = str_e.TryParse(out int value_e);

                Assert.AreEqual(success, success_e);
                Assert.AreEqual(value, value_e);

                if (success != success_e || value != value_e)
                {
                    Debug.LogError("failed to parse. string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "]");
                }
            }
        }
        public void CheckParseInt64_Boundary()
        {
            // boundary value check
            str_native.Clear();
            str_list.Clear();

            string in_range_lo  = "-9223372036854775808";
            string in_range_hi  = "9223372036854775807";
            string out_range_lo = "-9223372036854775809";
            string out_range_hi = "9223372036854775808";

            str_list.Add(in_range_lo.ToString());
            str_list.Add(in_range_hi.ToString());
            str_list.Add(out_range_lo.ToString());
            str_list.Add(out_range_hi.ToString());

            for (int i = 0; i < str_list.Count; i++)
            {
                str_native.Add(str_list[i]);
            }

            for (int i = 0; i < str_native.Length; i++)
            {
                var str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                bool success   = long.TryParse(str, out long value);
                bool success_e = str_e.TryParse(out long value_e);

                Assert.AreEqual(success, success_e);
                Assert.AreEqual(value, value_e);

                if (success != success_e || value != value_e)
                {
                    Debug.LogError("failed to parse. string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "]");
                }
            }
        }
Exemplo n.º 15
0
 private static void SplitWhiteSpaceBurst(ref ReadOnlyStringEntity source,
                                          ref UnsafeRefToNativeList <ReadOnlyStringEntity> result)
 {
     source.Split(result);
 }
Exemplo n.º 16
0
 private static void StripWhiteSpaceBurst(ref ReadOnlyStringEntity source,
                                          bool left, bool right,
                                          out ReadOnlyStringEntity result)
 {
     result = StringStripperExt.StripWhiteSpaceImpl(source, left, right);
 }
 /// <summary>
 /// Get the index of the entity.
 /// </summary>
 /// <param name="key">entity</param>
 /// <returns>index or -1 (not found)</returns>
 public int IndexOf(ReadOnlyStringEntity key)
 {
     return(_jarr.IndexOf(key));
 }
 /// <summary>
 /// specialize for ReadOnlyStringEntity
 /// </summary>
 /// <param name="entity"></param>
 public unsafe void Add(ReadOnlyStringEntity entity)
 {
     this.Add((Char16 *)entity.GetUnsafePtr(), entity.Length);
 }
Exemplo n.º 19
0
        private bool ParseLineImpl(ReadOnlyStringEntity line)
        {
            pack.Lines++;
            if (line.Length < 1)
            {
                return(true);
            }

            if (EnableBurstFunc)
            {
                BurstFunc.Split(line, '\t', _str_list);
            }
            else
            {
                line.Split('\t', _str_list);
            }

            //--- check data block
            if (_str_list.Length >= 2 && _str_list[0] == pack.mark_tag)
            {
                if (_str_list[1] == pack.mark_header)
                {
                    pack.read_mode = ReadMode.Header;
                }
                else if (_str_list[1] == pack.mark_ext)
                {
                    pack.read_mode = ReadMode.ExtData;
                }
                else if (_str_list[1] == pack.mark_ext_end)
                {
                    pack.read_mode = ReadMode.None;
                }
                else if (_str_list[1] == pack.mark_body)
                {
                    //--- check header info was read correctly or not
                    if (pack.N <= 0 || pack.D <= 0 || pack.R < 0.0 || pack.R >= 1.0)
                    {
                        pack.read_mode = ReadMode.HeaderError;
                        return(false);
                    }
                    pack.read_mode = ReadMode.Body;
                }
                return(true);
            }
            if (pack.read_mode == ReadMode.None)
            {
                return(true);
            }

            //--- ignore comment line
            if (_str_list[0].Length >= 1 && _str_list[0].Slice(0, 1) == pack.mark_comment)
            {
                return(true);
            }

            //--- store data
            if (pack.read_mode == ReadMode.Header)
            {
                bool success = true;
                if (EnableBurstFunc)
                {
                    // using BurstCompiler applied TryParse
                    if (_str_list[0] == pack.mark_n_total)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.N);
                    }
                    else if (_str_list[0] == pack.mark_d)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.D);
                    }
                    else if (_str_list[0] == pack.mark_r)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.R);
                    }
                }
                else
                {
                    // using normal TryParse()
                    if (_str_list[0] == pack.mark_n_total)
                    {
                        success = _str_list[1].TryParse(out pack.N);
                    }
                    else if (_str_list[0] == pack.mark_d)
                    {
                        success = _str_list[1].TryParse(out pack.D);
                    }
                    else if (_str_list[0] == pack.mark_r)
                    {
                        success = _str_list[1].TryParse(out pack.R);
                    }
                }

                if (!success)
                {
                    pack.read_mode = ReadMode.HeaderError;
                    return(false);
                }
            }
            else if (pack.read_mode == ReadMode.ExtData)
            {
                if (_str_list.Length > 1)
                {
                    // must be 1 element in line
                    pack.read_mode = ReadMode.Base64DataError;
                    return(false);
                }
                else if (_str_list.Length == 1)
                {
                    bool success = true;
                    if (EnableBurst)
                    {
                        // using BurstCompiler applied GetChars()
                        success = BurstFunc.GetBytes(_b64_decoder, _b64_decoded_bytes, _str_list[0]);
                    }
                    else
                    {
                        // using normal GetChars()
                        success = _b64_decoder.GetBytes(_b64_decoded_bytes, _str_list[0]);
                    }

                    if (!success)
                    {
                        pack.read_mode = ReadMode.Base64DataError;
                        return(false);
                    }
                }
            }
            else if (pack.read_mode == ReadMode.Body)
            {
                if (_str_list.Length < 6)
                {
                    return(true);
                }

                var  tmp     = new CharaData();
                bool success = true;
                if (EnableBurstFunc)
                {
                    // using BurstCompiler applied TryParse
                    success = success && BurstFunc.TryParse(_str_list[0], out tmp.ID);
                    success = success && BurstFunc.TryParse(_str_list[2], out tmp.HP);
                    success = success && BurstFunc.TryParse(_str_list[3], out tmp.MP);
                    success = success && BurstFunc.TryParse(_str_list[4], out tmp.Attack);
                    success = success && BurstFunc.TryParse(_str_list[5], out tmp.Defence);
                }
                else
                {
                    // using normal TryParse()
                    success = success && _str_list[0].TryParse(out tmp.ID);
                    success = success && _str_list[2].TryParse(out tmp.HP);
                    success = success && _str_list[3].TryParse(out tmp.MP);
                    success = success && _str_list[4].TryParse(out tmp.Attack);
                    success = success && _str_list[5].TryParse(out tmp.Defence);
                }

                if (!success)
                {
                    pack.read_mode = ReadMode.FormatError;
                    return(false);
                }

                _tmp_name.Add(_str_list[1]);
                tmp.Name = _tmp_name.Last;

                Data.Add(tmp);

                if (Data.Length > pack.N)
                {
                    pack.read_mode = ReadMode.FormatError;
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 20
0
        private static bool ParseLineImpl(ref CharaDataParser.DataPack pack, ReadOnlyStringEntity line)
        {
            pack.Lines++;
            if (line.Length < 1)
            {
                return(true);
            }

            line.Split('\t', pack.str_list);

            //--- check data block
            if (pack.str_list.Length >= 2 && pack.str_list[0] == pack.mark_tag)
            {
                if (pack.str_list[1] == pack.mark_header)
                {
                    pack.read_mode = CharaDataParser.ReadMode.Header;
                }
                else if (pack.str_list[1] == pack.mark_ext)
                {
                    pack.read_mode = CharaDataParser.ReadMode.ExtData;
                }
                else if (pack.str_list[1] == pack.mark_ext_end)
                {
                    pack.read_mode = CharaDataParser.ReadMode.None;
                }
                else if (pack.str_list[1] == pack.mark_body)
                {
                    //--- check header info was read correctly or not
                    if (pack.N <= 0 || pack.D <= 0 || pack.R < 0.0 || pack.R >= 1.0)
                    {
                        pack.read_mode = CharaDataParser.ReadMode.HeaderError;
                        return(false);
                    }
                    pack.read_mode = CharaDataParser.ReadMode.Body;
                }
                return(true);
            }
            if (pack.read_mode == CharaDataParser.ReadMode.None)
            {
                return(true);
            }

            //--- ignore comment line
            if (pack.str_list[0].Length >= 1 && pack.str_list[0].Slice(0, 1) == pack.mark_comment)
            {
                return(true);
            }

            //--- store data
            if (pack.read_mode == CharaDataParser.ReadMode.Header)
            {
                bool success = true;
                // using normal TryParse() for large scope optimization of BurstCompile
                if (pack.str_list[0] == pack.mark_n_total)
                {
                    success = pack.str_list[1].TryParse(out pack.N);
                }
                else if (pack.str_list[0] == pack.mark_d)
                {
                    success = pack.str_list[1].TryParse(out pack.D);
                }
                else if (pack.str_list[0] == pack.mark_r)
                {
                    success = pack.str_list[1].TryParse(out pack.R);
                }

                if (!success)
                {
                    pack.read_mode = CharaDataParser.ReadMode.HeaderError;
                    return(false);
                }
            }
            else if (pack.read_mode == CharaDataParser.ReadMode.ExtData)
            {
                if (pack.str_list.Length > 1)
                {
                    // must be 1 element in line
                    pack.read_mode = CharaDataParser.ReadMode.Base64DataError;
                    return(false);
                }
                else if (pack.str_list.Length == 1)
                {
                    bool success = pack.b64_decoder.GetBytes(pack.b64_decoded_bytes, pack.str_list[0]);
                    if (!success)
                    {
                        pack.read_mode = CharaDataParser.ReadMode.Base64DataError;
                        return(false);
                    }
                }
            }
            else if (pack.read_mode == CharaDataParser.ReadMode.Body)
            {
                if (pack.str_list.Length < 6)
                {
                    return(true);
                }

                var  tmp     = new CharaData();
                bool success = true;
                // using normal TryParse() for large scope optimization of BurstCompile
                success = success && pack.str_list[0].TryParse(out tmp.ID);
                success = success && pack.str_list[2].TryParse(out tmp.HP);
                success = success && pack.str_list[3].TryParse(out tmp.MP);
                success = success && pack.str_list[4].TryParse(out tmp.Attack);
                success = success && pack.str_list[5].TryParse(out tmp.Defence);

                if (!success)
                {
                    pack.read_mode = CharaDataParser.ReadMode.FormatError;
                    return(false);
                }

                pack.tmp_name.Add(pack.str_list[1]);
                tmp.Name = pack.tmp_name.Last;

                pack.Data.Add(tmp);

                if (pack.Data.Length > pack.N)
                {
                    pack.read_mode = CharaDataParser.ReadMode.FormatError;
                    return(false);
                }
            }

            return(true);
        }
        public void CheckParseFloat32_Typical()
        {
            // typical format sample
            str_native.Clear();
            str_list.Clear();

            str_list.Add("12345678987654321");
            str_list.Add("-12345678987654321");
            str_list.Add("123456789.87654321");
            str_list.Add("-123456789.87654321");
            str_list.Add("12345678987654321e-5");
            str_list.Add("-12345678987654321E-5");
            str_list.Add("123456789.87654321e-5");
            str_list.Add("-123456789.87654321E-5");
            str_list.Add("000.00123456789e-5");
            str_list.Add("-000.00123456789E-5");

            str_list.Add("1.11111111e-60");
            str_list.Add("-1.11111111e-60");

            str_list.Add("4E+08");
            str_list.Add("3E+08");
            str_list.Add("0E+0");
            str_list.Add("000E-00");
            str_list.Add("321.98e22");

            str_list.Add("123E+00000000000000000000221");
            str_list.Add("123E-00000000000000000000221");
            str_list.Add("123E+00000000000000000000221777");
            str_list.Add("123E-00000000000000000000221777");


            str_list.Add("e");
            str_list.Add(".01234e+2");
            str_list.Add("6633.11e+");
            str_list.Add("6633.11e-+-4");
            str_list.Add("123E+0000000000Kg00000000022");

            for (int i = 0; i < str_list.Count; i++)
            {
                str_native.Add(str_list[i]);
            }

            for (int i = 0; i < str_native.Length; i++)
            {
                var str = str_list[i];
                ReadOnlyStringEntity str_e = str_native[i];

                //Debug.Log($"@ parse target: {str_e}");

                bool success   = float.TryParse(str, out float value);
                bool success_e = str_e.TryParse(out float value_e);

                Assert.AreEqual(success, success_e);

                bool check_value = this.EqualsFloat(value, value_e, 1.0e-5f, out float rel_diff);
                if (!check_value || success != success_e)
                {
                    Debug.LogError("failed to parse. i = " + i.ToString() + " string [str/entity] = [" + str + "/" + str_e.ToString() + "]"
                                   + "bool [str/entity] = [" + success.ToString() + "/" + success_e.ToString() + "], "
                                   + "value [str/entity] = [" + value.ToString() + "/" + value_e.ToString() + "], rel_diff = " + rel_diff.ToString());
                }
                Assert.IsTrue(check_value);
            }
        }
Exemplo n.º 22
0
 private static void SplitStringBurst(ref ReadOnlyStringEntity source,
                                      ref ReadOnlyStringEntity delim,
                                      ref UnsafeRefToNativeList <ReadOnlyStringEntity> result)
 {
     source.Split(delim, result);
 }