ChatGPT and わたし。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* Guess the width of the rune on the console screen. 文字幅判定 以下に、各幅の種類に対する処理の説明を示します。 - width.Neutral: 幅が中立的である文字(例:アルファベット、数字、記号)は幅が1です。 - width.EastAsianWide: 全角文字(例:漢字、ひらがな、カタカナ)は幅が2です。 - width.EastAsianNarrow: 半角文字(例:英数字、一部の記号)は幅が1です。 - width.EastAsianAmbiguous: 幅が曖昧な文字(例:一部の漢字、一部のひらがな、一部のカタカナ)は幅が2です。 - width.EastAsianFullwidth: 全角文字(例:漢字、ひらがな、カタカナ)は幅が2です。 - width.EastAsianHalfwidth: 半角文字(例:英数字、一部の記号)は幅が1です。 */ func RuneWidth(r rune) int { p := width.LookupRune(r) switch p.Kind() { case width.Neutral: return 1 case width.EastAsianWide: return 2 case width.EastAsianNarrow: return 1 case width.EastAsianAmbiguous: return 2 case width.EastAsianFullwidth: return 2 case width.EastAsianHalfwidth: return 1 default: return 1 } } |
何度か I/O っして、ググった結果。