示例#1
0
        public static string ToLowercaseUnderscore(this string value)
        {
            if (value.IsNullOrEmpty())
            {
                return(value);
            }
            value = value.ToCamelCase();

            var sb = StringBuilderPool.Get();

            foreach (char t in value)
            {
                if (char.IsDigit(t) || (char.IsLetter(t) && char.IsLower(t)) || t == '_')
                {
                    sb.Append(t);
                }
                else
                {
                    sb.Append("_");
                    sb.Append(char.ToLower(t));
                }
            }
            return(StringBuilderPool.GetStringAndRelease(sb));
        }
示例#2
0
        public static string PrettyPrint(string input)
        {
            if (input.IsNullOrEmpty())
            {
                return(null);
            }
            string spaces = new string(' ', 3);

            var stringBuilder = StringBuilderPool.Get();
            int num           = 0;
            int length        = input.Length;

            char[] array = input.ToCharArray();
            for (int i = 0; i < length; i++)
            {
                char c = array[i];
                if (c == '"')
                {
                    bool flag = true;
                    while (flag)
                    {
                        stringBuilder.Append(c);
                        c = array[++i];
                        switch (c)
                        {
                        case '\\':
                            stringBuilder.Append(c);
                            c = array[++i];
                            break;

                        case '"':
                            flag = false;
                            break;
                        }
                    }
                }
                switch (c)
                {
                case '[':
                case '{':
                    stringBuilder.Append(c);
                    stringBuilder.AppendLine();
                    AppendIndent(stringBuilder, ++num, spaces);
                    break;

                case ']':
                case '}':
                    stringBuilder.AppendLine();
                    AppendIndent(stringBuilder, --num, spaces);
                    stringBuilder.Append(c);
                    break;

                case ',':
                    stringBuilder.Append(c);
                    stringBuilder.AppendLine();
                    AppendIndent(stringBuilder, num, spaces);
                    break;

                case ':':
                    stringBuilder.Append(" : ");
                    break;

                default:
                    if (!char.IsWhiteSpace(c))
                    {
                        stringBuilder.Append(c);
                    }
                    break;
                }
            }
            return(StringBuilderPool.GetStringAndRelease(stringBuilder));
        }