Apache.Shiro.Util.StringUtils.Split C# (CSharp) Method

Split() public static method

public static Split ( string value, char delimiter = DEFAULT_DELIMITER_CHAR, char beginQuote = DEFAULT_QUOTE_CHAR, char endQuote = DEFAULT_QUOTE_CHAR, bool retainQuotes = false, bool trimTokens = true ) : string[]
value string
delimiter char
beginQuote char
endQuote char
retainQuotes bool
trimTokens bool
return string[]
        public static string[] Split(string value, char delimiter = DEFAULT_DELIMITER_CHAR,
			char beginQuote = DEFAULT_QUOTE_CHAR, char endQuote = DEFAULT_QUOTE_CHAR,
			bool retainQuotes = false, bool trimTokens = true)
        {
            var line = Clean(value);
            if (line == null)
            {
                return null;
            }

            var tokens = new List<string>();
            var builder = new StringBuilder();
            var inQuotes = false;

            for (var i = 0; i < line.Length; ++i)
            {
                var c = line[i];
                if (c == beginQuote)
                {
                    if (inQuotes &&
                        line.Length < (i + 1) &&
                        line[i + 1] == beginQuote)
                    {
                        builder.Append(c);
                        ++i;
                    }
                    else
                    {
                        inQuotes = !inQuotes;
                        if (retainQuotes)
                        {
                            builder.Append(c);
                        }
                    }
                }
                else if (c == endQuote)
                {
                    inQuotes = !inQuotes;
                    if (retainQuotes)
                    {
                        builder.Append(c);
                    }
                }
                else if (c == delimiter && !inQuotes)
                {
                    var s = builder.ToString();
                    if (trimTokens)
                    {
                        s = s.Trim();
                    }
                    tokens.Add(s);
                    builder = new StringBuilder();
                }
                else
                {
                    builder.Append(c);
                }
            }

            if (builder.Length > 0)
            {
                var s = builder.ToString();
                if (trimTokens)
                {
                    s = s.Trim();
                }
                tokens.Add(s);
            }

            return tokens.ToArray();
        }