AppHarbor.Commands.HelpCommand.SplitUpperCase C# (CSharp) Method

SplitUpperCase() private static method

Splitting Pascal/Camel Cased Strings http://haacked.com/archive/2005/09/23/splitting-pascalcamel-cased-strings.aspx/ Licensed under the terms of the Creative Commons Attribution 2.5 Generic License
private static SplitUpperCase ( string source ) : string[]
source string
return string[]
        private static string[] SplitUpperCase(string source)
        {
            if (source == null)
            {
                return new string[] { };
            }

            if (source.Length == 0)
            {
                return new string[] { "" };
            }

            var words = new StringCollection();
            int wordStartIndex = 0;

            var letters = source.ToCharArray();

            for (int i = 1; i < letters.Length; i++)
            {
                if (char.IsUpper(letters[i]))
                {
                    words.Add(new String(letters, wordStartIndex, i - wordStartIndex));
                    wordStartIndex = i;
                }
            }

            words.Add(new String(letters, wordStartIndex, letters.Length - wordStartIndex));

            var wordArray = new string[words.Count];
            words.CopyTo(wordArray, 0);

            return wordArray;
        }