-
Notifications
You must be signed in to change notification settings - Fork 1
fix Kunakorn case #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| { | ||
| "runtimes": { | ||
| "osx.10.11-x64": {} | ||
| }, | ||
| "version": "1.0.0-*", | ||
| "buildOptions": { | ||
| "debugType": "portable" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ใช้ RegEx ในกรณีนี้ ผมเห็นว่าเกินความจำเป็นนะครับ เราต้องการแค่เช็คตัวอักษรตัวที่ 4 เท่านั้นเอง
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. เดี๋ยวเปลี่ยนเป็น start with หรือ เช็คตำแหน่งที่ 4 แทนครับ |
||
| 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++) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ขอถกเรื่อง solution ใน issue นี้ก่อนนะครับ แนวทางตีโจทย์และหาทางออก เท่าที่คุยและคิดกัน เหมือนจะมี 2 อย่างครับ คือ ดูว่าตัวอักษรตัวที่ 4 เป็น สระ กับอีกอย่างคือ ยังมีชื่อที่ตัวอักษรตัวที่ 4 ไม่ใช่สระด้วย เช่น คุณณา แต่มันอาจจะมีน้อย จนเราอาจจะใช้วิธี list ชื่อคน"พิเศษ" เหล่านี้แบบ hard-code ไปเลย
คิดเห็นยังไงครับ? : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list พิเศษก็เหมาะสมครับ แค่อาจจะต้องคอยมาปรับปรุงอยู่เป็นระยะๆ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ถ้าอย่างนั้น เราน่าจะมี test cases ได้ประมาณนี้
// names that in the list
"คุณวุฒิ".AsKhun() => "คุณคุณวุฒิ"
"คุณคุณวุฒิ".AsKhun() => "คุณคุณวุฒิ"
// names that not in the list (can check with vowels)
"คุณากร".AsKhun() => "คุณคุณากร"
"คุณคุณากร".AsKhun() => "คุณคุณากร"
// names that not in the list (cannot check with vowels)
"คุณศรี".AsKhun() => "คุณศรี"
"คุณคุณศรี".AsKhun() => "คุณคุณศรี"
// the list
string[] specialNames = new string [] { "คุณวุฒิ", "คุณสมบัติ" };