public void FormatGuid()
        {
            var guid = Guid.NewGuid();
            var sb = new StringFormatter();

            sb.Append(guid);
            Assert.Equal(guid.ToString(), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'D');
            Assert.Equal(guid.ToString("D"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'N');
            Assert.Equal(guid.ToString("N"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'B');
            Assert.Equal(guid.ToString("B"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'P');
            Assert.Equal(guid.ToString("P"), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeG()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'G');
            Assert.Equal(time.ToString("G"), sb.ToString());
            sb.Clear();
        }
        public void FormatTimeSpan()
        {
            var time = new TimeSpan(1000, 23, 40, 30, 12345);
            var sb = new StringFormatter();

            sb.Append(time);
            Assert.Equal(time.ToString("", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeOffsetR()
        {
            var time = DateTimeOffset.UtcNow;
            var sb = new StringFormatter(pool);

            sb.Append(time, 'R');
            Assert.Equal(time.ToString("R"), sb.ToString());
            sb.Clear();
        }
        public void FormatDateTimeO()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'O');
            Assert.Equal(time.ToString("O", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
Ejemplo n.º 6
0
        private void CheckByte(byte value, string format, string expected)
        {
            var formatter = new StringFormatter(pool);
            var parsed = Format.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
Ejemplo n.º 7
0
        private void CheckByte(byte value, string format, string expected)
        {
            var formatter = new StringFormatter();
            var parsed    = ParsedFormat.Parse(format);

            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();

            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);

            Assert.Equal(clrResult, result);
        }
Ejemplo n.º 8
0
        public void FloatFormatting()
        {
            var sb = new StringFormatter();

            sb.Append(Double.NaN);
            var result = sb.ToString();

            Assert.Equal("NaN", result);
            sb.Clear();

            sb.Append(Double.PositiveInfinity);
            result = sb.ToString();
            Assert.Equal("Infinity", result);
            sb.Clear();

            sb.Append(Double.NegativeInfinity);
            result = sb.ToString();
            Assert.Equal("-Infinity", result);
            sb.Clear();

            sb.Append(1.2);
            result = sb.ToString();
            Assert.Equal("1.2", result);
        }
        public void FloatFormatting()
        {
            var sb = new StringFormatter(pool);

            sb.Append(Double.NaN);
            var result = sb.ToString();
            Assert.Equal("NaN", result);
            sb.Clear();

            sb.Append(Double.PositiveInfinity);
            result = sb.ToString();
            Assert.Equal("Infinity", result);
            sb.Clear();

            sb.Append(Double.NegativeInfinity);
            result = sb.ToString();
            Assert.Equal("-Infinity", result);
            sb.Clear();

            sb.Append(1.2);
            result = sb.ToString();
            Assert.Equal("1.2", result);
        }
Ejemplo n.º 10
0
        private void CustomCultureFormat()
        {
            StringFormatter sb = new StringFormatter(numbersToWrite * 3, pool);

            sb.SymbolTable = CreateCustomCulture();

            timer.Restart();
            for (int itteration = 0; itteration < itterationsCulture; itteration++)
            {
                sb.Clear();
                for (int i = 0; i < numbersToWrite; i++)
                {
                    var next = (i % 128) + 101;
                    sb.Append(next);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite * 3)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
Ejemplo n.º 11
0
        private void CustomCultureFormat()
        {
            ManagedBufferPool <byte> pool = new ManagedBufferPool <byte>(1024);
            StringFormatter          sb   = new StringFormatter(numbersToWrite * 3, pool);

            sb.FormattingData = CreateCustomCulture();

            timer.Restart();
            for (int itteration = 0; itteration < itterationsCulture; itteration++)
            {
                sb.Clear();
                for (int i = 0; i < numbersToWrite; i++)
                {
                    var next = (i % 128) + 101;
                    sb.Append(next);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite * 3)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
        public void FormatXPrecision()
        {
            var x = Format.Parse("x10");
            var X = Format.Parse("X10");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("00000000ff00000000FF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("00FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("00FFFFFFFE", sb.ToString());
        }
        public void FormatX()
        {
            var x = Format.Parse("x");
            var X = Format.Parse("X");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("ffFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("FFFFFFFE", sb.ToString());
        }
Ejemplo n.º 14
0
        private void CustomCultureFormat()
        {
            StringFormatter sb = new StringFormatter(numbersToWrite * 3, pool);
            sb.FormattingData = CreateCustomCulture();

            timer.Restart();
            for (int itteration = 0; itteration < itterationsCulture; itteration++)
            {
                sb.Clear();
                for (int i = 0; i < numbersToWrite; i++)
                {
                    var next = (i % 128) + 101;
                    sb.Append(next);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite * 3)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
        private void CheckInt64(long value, string format, string expected, StringFormatter formatter)
        {
            var parsed = TextFormat.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
Ejemplo n.º 16
0
        private IReadOnlyList <UnscramblingInstruction> GetDecryptInstructions(string name, string playerSource)
        {
            sb.Clear(); //Just want to make sure
            var instructions     = new List <UnscramblingInstruction>();
            var instrustions_map = new Dictionary <string, string>();
            //TODO: improve the parameter name (using regex maybe)
            var searchTerm = $"{name}=function(a){{";

            var pos = playerSource.IndexOf(searchTerm);

            for (int i = pos + searchTerm.Length; i < playerSource.Length; i++)
            {
                var c = playerSource[i];
                if (c == '}')
                {
                    break;
                }

                if (c == ';')
                {
                    var line = sb.ToString();
                    sb.Clear();
                    if (line.Contains("split") || line.Contains("return"))
                    {
                        continue;
                    }
                    //Example: AL.iy(a,9)
                    //Result:
                    // AL, iy, a, 9
                    var parts = line.Split('.', ',', '(', ')');
                    var func  = parts[1];
                    var index = parts[parts.Length - 2];
                    //We haven't found the funtion
                    if (!instrustions_map.TryGetValue(func, out var value))
                    {
                        if (playerSource.Contains($"{func}:function(a,b){{var"))
                        {
                            value = "swap";
                        }
                        else if (playerSource.Contains($"{func}:function(a){{"))
                        {
                            value = "reverse";
                        }
                        else if (playerSource.Contains($"{func}:function(a,b){{"))
                        {
                            value = "slice";
                        }
                        else
                        {
                            throw new Exception($"Decoding instruction not found for function {func}");
                        }
                        instrustions_map[func] = value;
                    }
                    instructions.Add(new UnscramblingInstruction {
                        Name = value, Index = int.Parse(index)
                    });
                }
                else
                {
                    sb.Append(c);
                }
            }
            return(instructions);
        }