diff --git a/src/khun.Facts/project.json b/src/khun.Facts/project.json index 5e7fa14..6e13c09 100644 --- a/src/khun.Facts/project.json +++ b/src/khun.Facts/project.json @@ -1,4 +1,7 @@ { + "runtimes": { + "osx.10.11-x64": {} + }, "version": "1.0.0-*", "buildOptions": { "debugType": "portable" diff --git a/src/khun/KhunExtension.cs b/src/khun/KhunExtension.cs index c187aab..4aa9cdd 100644 --- a/src/khun/KhunExtension.cs +++ b/src/khun/KhunExtension.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Text.RegularExpressions; namespace GreatFriends.Khun { public static class KhunExtension { @@ -16,6 +17,11 @@ public static class KhunExtension { "อ." }; + private static string[] vowels = new string[] { + "า" + }; + + private const string khun = "คุณ"; public static string AsKhun(this string name) { @@ -28,8 +34,19 @@ public static string AsKhun(this string name) { string[] parts = name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - if (parts[0].StartsWith("คุณ")) { - return string.Join(" ", parts); + if (parts[0].StartsWith(khun)) { + Regex regex = new Regex(Regex.Escape(khun)); + string nextToKhun = regex.Replace(parts[0], string.Empty, 1); + bool nextToKhunIsVowel = false; + for (int i = 0; i < vowels.Length; i++) { + if (nextToKhun.StartsWith(vowels[i])) { + nextToKhunIsVowel = true; + break; + } + } + if (!nextToKhunIsVowel) { + return string.Join(" ", parts); + } } for (int i = 0; i < prefixes.Length; i++) {