private string[] SplitOnUppercaseToLowercase(string word)
{
List<string> splitWords = new List<string>();
for (int i = 0; i < word.Length-1; i++)
{
if (char.IsUpper(word, i) && char.IsLower(word, i + 1))
{
//found split point
double camelScore = Score(word.Substring(i)); //score for camelcase split, e.g. AST Visitor
double altScore = Score(word.Substring(i + 1)); //score for alternate split, e.g. ASTV isitor
//TODO: should this be >=? That way, if both alternatives have the same score, then camelcase is selected
// This occurs most often when neither word is in the dictionaries, i.e. score = 0
if (camelScore >= Math.Sqrt(altScore))
{
//use camel split
if (i > 0)
{
//don't add if only one uppercase at beginning of word, e.g. "Hourly"
splitWords.Add(word.Substring(0, i));
}
splitWords.Add(word.Substring(i));
}
else
{
//use alternate split
splitWords.Add(word.Substring(0, i + 1));
splitWords.Add(word.Substring(i + 1));
}
break; //there is only one uppercase-to-lowercase split per word (as per precondition), so don't look any further
}
}
//if no split was found, add the original word
if(splitWords.Count == 0)
splitWords.Add(word);
return splitWords.ToArray();
}