Example #1
0
    void wstringTest()
    {
        using (profiler.Sample("wstring"))
        {
            using (profiler.Sample("Format"))
            {
                wstring gf = wstringManager.Instance.StaticString1024();
                gf.IntToFormat(123);
                gf.FloatToFormat(3.148f);
                gf.Append("Text");
                gf.AppendFormat("Number = {0}, Float = {1} String = {2}");
                int x = 10;
                wstringManager.Instance.DeSpawnString(gf);
            }

            using (profiler.Sample("Concat"))
            {
                wstring gf = wstringManager.Instance.StaticString1024();
                gf.Append("That's ");
                gf.Append("a lot");
                gf.Append(" of");
                gf.Append(" strings");
                gf.Append(" to ");
                gf.Append("concat");
                gf.AppendFormat("{0}{1}{2}{3}{4}{5}");
                wstringManager.Instance.DeSpawnString(gf);
                int x = 10;
            }
            //功能缺失只能使用string替代
            using (profiler.Sample("Substring + IndexOf + LastIndexOf"))
            {
                string path   = "Path/To/Some/File.txt";
                int    period = path.IndexOf('.');
                var    ext    = path.Substring(period + 1);
                var    file   = path.Substring(path.LastIndexOf('/') + 1, 4);
                int    x      = 10;
            }

            //功能缺失只能使用string替代
            using (profiler.Sample("Replace (char)"))
            {
                string input       = "This is some sort of text";
                string replacement = input.Replace('o', '0').Replace('i', '1');
                int    x           = 10;
            }
            //功能缺失只能使用string替代
            using (profiler.Sample("Replace (string)"))
            {
                string input       = "m_This is the is is form of text";
                string replacement = input.Replace("m_", "").Replace("is", "si");
                int    x           = 10;
            }
            using (profiler.Sample("Concat + Intern"))
            {
                for (int i = 0; i < 4; i++)
                {
                    wstring gf = wstringManager.Instance.StaticString1024();
                    gf.StringToFormat("Item");
                    gf.IntToFormat(i);
                    gf.AppendFormat("{0}{1}");
                    dict[string.Intern(gf.ToString())] = i;
                    wstringManager.Instance.DeSpawnString(gf);
                }
                wstring gf02 = wstringManager.Instance.StaticString1024();
                gf02.Append("I'm ");
                gf02.Append("long ");
                gf02.Append("gone ");
                gf02.Append("by ");
                gf02.Append("the ");
                gf02.Append("end ");
                gf02.Append("of ");
                gf02.Append("this ");
                gf02.Append("gstring block ");
                gf02.AppendFormat("{0}{1}{2}{3}{4}{5}{6}{7}");
                outsideString1 = gf02.ToString();
                wstringManager.Instance.DeSpawnString(gf02);
                wstring gf03 = wstringManager.Instance.StaticString1024();
                gf03.Append("I'll ");
                gf03.Append("be ");
                gf03.Append("still ");
                gf03.Append("around ");
                gf03.Append("here");
                gf03.Append("{0}{1}{2}{3}{4}");
                outsideString = string.Intern(gf03.ToString());
                wstringManager.Instance.DeSpawnString(gf03);
                int x = 10;
            }

            using (profiler.Sample("ToUpper + ToLower"))
            {
                wstring gf = wstringManager.Instance.StaticString1024();
                gf.Append("Hello");
                gf.AppendFormat("{0}");
                gf.ToUpper();
                wstring gf02 = wstringManager.Instance.StaticString1024();
                gf02.Append(gf);
                gf02.Append(gf.ToString().ToLower());
                gf02.AppendFormat("{0}{1}");
                wstringManager.Instance.DeSpawnString(gf);
                wstringManager.Instance.DeSpawnString(gf02);
                int x = 10;
            }
            if (!bigStringTest)
            {
                return;
            }
            using (profiler.Sample("BigStringEval"))
            {
                wstring gf = wstringManager.Instance.StaticString1024();
                gf.Append(bigString);
                gf.Append("hello");
                gf.AppendFormat("{0}{1}");
            }
        }
    }
Example #2
0
    private void InternalAppendFormat(string format, int lengthf)
    {
        if (m_myString == null || format == null)
        {
            return;
        }
        wstringManager instance = wstringManager.Instance;
        int            num      = 0;

        while (true)
        {
            char c;
            if (num < lengthf)
            {
                c = format[num];
                num++;
                if (c == '}')
                {
                    if (num >= lengthf || format[num] != '}')
                    {
                        break;
                    }
                    num++;
                }
                if (c == '{')
                {
                    if (num >= lengthf || format[num] != '{')
                    {
                        num--;
                        goto IL_8C;
                    }
                    num++;
                }
                Append(c);
                continue;
            }
IL_8C:
            if (num == lengthf)
            {
                return;
            }
            num++;
            if (num == lengthf || (c = format[num]) < '0' || c > '9')
            {
                return;
            }
            int num2 = 0;
            do
            {
                num2 = num2 * 10 + (int)c - 48;
                num++;
                if (num == lengthf)
                {
                    return;
                }
                c = format[num];
            }while (c >= '0' && c <= '9' && num2 < 1000000);
            wstring[] formatS = instance.m_formatString;
            if (num2 >= formatS.Length)
            {
                return;
            }
            while (num < lengthf && (c = format[num]) == ' ')
            {
                num++;
            }
            bool flag = false;
            int  num3 = 0;
            if (c == ',')
            {
                num++;
                while (num < lengthf && format[num] == ' ')
                {
                    num++;
                }
                if (num == lengthf)
                {
                    return;
                }
                c = format[num];
                if (c == '-')
                {
                    flag = true;
                    num++;
                    if (num == lengthf)
                    {
                        return;
                    }
                    c = format[num];
                }
                if (c < '0' || c > '9')
                {
                    return;
                }
                do
                {
                    num3 = num3 * 10 + (int)c - 48;
                    num++;
                    if (num == lengthf)
                    {
                        return;
                    }
                    c = format[num];
                    if (c < '0' || c > '9')
                    {
                        break;
                    }
                }while (num3 < 1000000);
            }
            while (num < lengthf && (c = format[num]) == ' ')
            {
                num++;
            }
            wstring cString = instance.StaticString1024();
            if (c == ':')
            {
                num++;
                while (num != lengthf)
                {
                    c = format[num];
                    num++;
                    if (c == '{')
                    {
                        if (num >= lengthf || format[num] != '{')
                        {
                            return;
                        }
                        num++;
                    }
                    else if (c == '}')
                    {
                        if (num >= lengthf || format[num] != '}')
                        {
                            num--;
                            goto IL_286;
                        }
                        num++;
                    }
                    cString.Append(c);
                }
                return;
            }
IL_286:
            if (c != '}')
            {
                return;
            }
            num++;
            wstring cString2 = null;
            if (formatS[num2] != null)
            {
                cString2 = formatS[num2];
            }
            if (cString2 == null)
            {
                cString2 = instance.StaticString1024();
            }
            int num4 = num3 - cString2.Length;
            if (!flag && num4 > 0)
            {
                Append(' ', num4);
            }
            Append(cString2);
            if (flag && num4 > 0)
            {
                Append(' ', num4);
            }
        }
    }