Exemple #1
0
        public WhiteSpaceKind WhiteSpace(IStyledObject control, WhiteSpaceKind defaultValue = WhiteSpaceKind.Nowrap)
        {
            IDictionary <Type, IStyle> styles = _getStyles(control);

            if (styles.ContainsKey(typeof(WhiteSpace)))
            {
                var ws = (WhiteSpace)styles[typeof(WhiteSpace)];
                return(ws.Kind);
            }
            return(defaultValue);
        }
Exemple #2
0
        public override void FromString(string s)
        {
            s = s.Trim();

            WhiteSpaceKind result;

            if (!Enum.TryParse(s, true, out result))
            {
                throw new Exception("Invalid white-space value: " + s);
            }

            Kind = result;
        }
Exemple #3
0
        /// <summary>
        /// Removes the specified whitespace left margin from the specified lines.
        /// </summary>
        /// <param name="lines">The lines to process.</param>
        /// <param name="kind">The kind of whitespace to trim.</param>
        /// <returns>A new set of lines with whitespace trimmed.</returns>
        public static string[] RemoveLeftMargin(string[] lines, WhiteSpaceKind kind)
        {
            if (lines.Length == 0)
            {
                return(lines);
            }

            char spaceChar = (char)kind;
            // Get shortest white space.
            int shortest = int.MaxValue;

            foreach (var line in lines)
            {
                int count = GetCharacterStartCount(line, spaceChar);

                if (count < shortest && count != -1)
                {
                    shortest = count;
                }
            }

            if (shortest == int.MaxValue || shortest == 0)
            {
                return(lines);
            }

            string[] newLines = new string[lines.Length];

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i] != null)
                {
                    newLines[i] = lines[i].TrimStart(spaceChar, shortest);
                }
            }

            return(newLines);
        }