kOS.Suffixed.WaypointValue.GreekToInteger C# (CSharp) Method

GreekToInteger() public static method

Return an integer to go with the alphabet position of the string given in greek lettering. For example, input "alpha" and get out 0. input "beta" and get out 1. If no match is found, -1 is returned.
This is used by waypoints so that you can figure out that a waypoint named like "Jebadiah's lament Gamma" is really the 3rd (index 2) member of the "Jebadiah's lament" cluster of waypoints.
Because that is its purpose, it actually operates on the LASTMOST word in the string it is given. given a string like "foo bar baz", it will check if "baz" is a greek letter, not "foo". Thus you can pass in exactly the name as it appears onscreen.
public static GreekToInteger ( string greekLetterName, int &index, string &baseName ) : bool
greekLetterName string string name to check. Case insensitively.
index int integer position in alphabet. -1 if no match.
baseName string the name after the last term has been stripped off, if there are /// space separated terms. Note that if the return value of this method is false, this /// shouldn't be used and you should stick with the original full name.
return bool
        public static bool GreekToInteger(string greekLetterName, out int index, out string baseName )
        {
            // greekMap is static, and we only need to populate it once in
            // the lifetime of the KSP process.  We'll do so the first time
            // this method (the only one that uses it) gets called:
            if (greekMap == null)
                InitializeGreekMap();

            // Get lastmost word (or whole string if there's no spaces):
            int lastSpace = greekLetterName.LastIndexOf(' ');
            string lastTerm;
            if (lastSpace >= 0 && lastSpace < greekLetterName.Length - 1)
            {
                // last space is real, and isn't the lastmost char but actually has
                // nonspaces that follow it:
                lastTerm = greekLetterName.Substring(lastSpace+1).ToLower(); // ToLower for the dictionary hashmap lookup
                baseName = greekLetterName.Substring(0,lastSpace);
            }
            else
            {
                lastTerm = greekLetterName.ToLower(); // ToLower for the dictionary hashmap lookup
                baseName = greekLetterName;
            }

            bool worked = greekMap.TryGetValue(lastTerm, out index);
            if (!worked)
                index = -1;
            return worked;
        }