/// <summary>Fix up faction names</summary> public static string getPhoneticFaction(string faction, bool useICAO = false) { if (faction == null) { return(null); } // Specific fixing of names to avoid later confusion if (FACTION_FIXES.ContainsKey(faction)) { faction = FACTION_FIXES[faction]; } // Faction names can contain system names; hunt them down and change them foreach (var pronunciation in STAR_SYSTEM_FIXES) { if (faction.Contains(pronunciation.Key)) { return(faction.Replace(pronunciation.Key, pronunciation.Value)); } } foreach (var pronunciation in STAR_SYSTEM_PRONUNCIATIONS) { if (faction.Contains(pronunciation.Key)) { var replacement = replaceWithPronunciation(pronunciation.Key, pronunciation.Value); return(faction.Replace(pronunciation.Key, replacement)); } } // It's possible that the name contains a constellation or catalog abbreviation, in which case translate it string[] pieces = faction.Split(' '); for (int i = 0; i < pieces.Length; i++) { if (CONSTELLATION_PRONUNCIATIONS.ContainsKey(pieces[i])) { pieces[i] = replaceWithPronunciation(pieces[i], CONSTELLATION_PRONUNCIATIONS[pieces[i]]); } else if (ALPHA_THEN_NUMERIC.IsMatch(pieces[i])) { pieces[i] = sayAsLettersOrNumbers(pieces[i], false, useICAO); } else if (ALPHA_DOT.IsMatch(pieces[i])) { pieces[i] = sayAsLettersOrNumbers(pieces[i].Replace(".", ""), false, useICAO); } else if (DIGIT.IsMatch(pieces[i])) { pieces[i] = sayAsLettersOrNumbers(pieces[i], !THREE_OR_MORE_DIGITS.IsMatch(pieces[i]), useICAO); } } return(string.Join(" ", pieces)); }
/// <summary>Fix up body names</summary> private static string getPhoneticBody(string body, bool useICAO = false) { if (body == null) { return(null); } // Use a regex to break apart the body from the system var shortBody = SHORTBODY.Match(body); if (!shortBody.Success) { // There was no match so we pass this as-is return(body); } var results = new List <string>(); // Extract and parse any leading star system name first var system = body.Substring(0, body.Length - shortBody.Groups[0].Value.Length).Trim(); if (!string.IsNullOrEmpty(system)) { results.Add(getPhoneticStarSystem(system, useICAO)); } // Parse the short body name for (int i = 1; i < shortBody.Groups.Count; i++) { for (int j = 0; j < shortBody.Groups[i].Captures.Count; j++) { var part = shortBody.Groups[i].Captures[j].Value.Trim(); var lastPart = GetLastPart(shortBody, i, j); var nextPart = GetNextPart(shortBody, i, j); if (string.IsNullOrEmpty(part)) { continue; } if (part == "Belt" || part == "Cluster" || part == "Ring") { // Pass as-is results.Add(part); } else if (DIGIT.IsMatch(part) || MOON.IsMatch(part) || nextPart == "Ring" || nextPart == "Belt" || lastPart == "Cluster") { // The part represents a body, possibly part of the name of a moon, ring, (stellar) belt, or belt cluster; // e.g. "Pru Aescs NC-M d7-192 A A Belt", "Prai Flyou JQ-F b30-3 B Belt Cluster 9", "Oopailks NV-X c17-1 AB 6 A Ring" results.Add(sayAsLettersOrNumbers(part, true, useICAO)); } else if (SUBSTARS.IsMatch(part)) { // The part is uppercase; turn it in to ICAO if required results.Add(sayAsLettersOrNumbers(part, false, useICAO)); } else if (TEXT.IsMatch(part)) { results.Add(sayAsLettersOrNumbers(part, true, useICAO)); } else { // Pass it as-is results.Add(part); } } } return(Regex.Replace(string.Join(" ", results), @"\s+", " ")); }