Ejemplo n.º 1
0
        private static string[] TrimLines(string[] lines)
        {
            if (lines == null || lines.Length == 0)
            {
                return((string[])null);
            }
            int index1 = 0;

            while (index1 < lines.Length && MamlNode.IsEmptyLine(lines[index1]))
            {
                ++index1;
            }
            int num1 = index1;

            if (num1 == lines.Length)
            {
                return((string[])null);
            }
            int index2 = lines.Length - 1;

            while (index2 >= num1 && MamlNode.IsEmptyLine(lines[index2]))
            {
                --index2;
            }
            int num2 = index2;

            string[] strArray = new string[num2 - num1 + 1];
            for (int index3 = num1; index3 <= num2; ++index3)
            {
                strArray[index3 - num1] = lines[index3];
            }
            return(strArray);
        }
Ejemplo n.º 2
0
        private static int GetIndentation(string line)
        {
            if (MamlNode.IsEmptyLine(line))
            {
                return(0);
            }
            string str = line.TrimStart(' ');

            return(line.Length - str.Length);
        }
Ejemplo n.º 3
0
        private static int GetMinIndentation(string[] lines)
        {
            int num = -1;

            for (int index = 0; index < lines.Length; ++index)
            {
                if (!MamlNode.IsEmptyLine(lines[index]))
                {
                    int indentation = MamlNode.GetIndentation(lines[index]);
                    if (num < 0 || indentation < num)
                    {
                        num = indentation;
                    }
                }
            }
            return(num);
        }
Ejemplo n.º 4
0
        private static string GetPreformattedText(string text)
        {
            string[] lines = MamlNode.TrimLines(text.Replace("\t", "    ").Split('\n'));
            if (lines == null || lines.Length == 0)
            {
                return("");
            }
            int minIndentation = MamlNode.GetMinIndentation(lines);

            string[] strArray = new string[lines.Length];
            for (int index = 0; index < lines.Length; ++index)
            {
                strArray[index] = !MamlNode.IsEmptyLine(lines[index]) ? lines[index].Remove(0, minIndentation) : lines[index];
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int index = 0; index < strArray.Length; ++index)
            {
                stringBuilder.AppendLine(strArray[index]);
            }
            return(stringBuilder.ToString());
        }