Skip to content

Commit

Permalink
null check
Browse files Browse the repository at this point in the history
  • Loading branch information
na1307 committed May 2, 2024
1 parent 47be569 commit cde1bbe
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 25 deletions.
7 changes: 7 additions & 0 deletions Bluehill.Hangul.Pages/Pages/Changelog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

<h2>Changelog</h2>

<h3>2.0.3 (2024-05-02)</h3>

<ol>
<li>널 검사 추가</li>
</ol>

<h3>2.0.2 (2024-05-02)</h3>

<ol>
Expand Down Expand Up @@ -114,6 +120,7 @@

<ol>
<li>문자열이 비어 있을 떄 (<code>""</code>) 조사 처리에 실패하는 문제 수정</li>
<li>널 검사 추가</li>
</ol>

<h3>1.1.1 (2022-11-22)</h3>
Expand Down
4 changes: 2 additions & 2 deletions Bluehill.Hangul/Bluehill.Hangul.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>한글 관련 라이브러리</Description>
<AssemblyVersion>2</AssemblyVersion>
<FileVersion>2.0.2</FileVersion>
<Version>2.0.2</Version>
<FileVersion>2.0.3</FileVersion>
<Version>2.0.3</Version>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\bluehill.snk</AssemblyOriginatorKeyFile>
<NoWarn>$(NoWarn);0436</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion Bluehill.Hangul/CharExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ public static class CharExtensions {
/// <returns><paramref name="hangulSyllable"/>의 초성에 해당하는 <see cref="Hangul.Jongseong"/> 값</returns>
/// <exception cref="ArgumentException"><paramref name="hangulSyllable"/>가 한글 음절이 아님</exception>
public static Jongseong Jongseong(this char hangulSyllable) => ((HangulSyllable)hangulSyllable).Jongseong;
}
}
2 changes: 1 addition & 1 deletion Bluehill.Hangul/Choseong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public enum Choseong : byte {
Pieup,
/// <summary>자음 ㅎ을 나타냄</summary>
Hieut
}
}
2 changes: 1 addition & 1 deletion Bluehill.Hangul/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public static class EnumExtensions {
/// <param name="jongseong"><see cref="Jongseong"/></param>
/// <returns><paramref name="jongseong"/>에 해당하는 <see cref="char"/> 값</returns>
public static char ToJamo(this Jongseong jongseong) => Jongseongs[(int)jongseong];
}
}
2 changes: 1 addition & 1 deletion Bluehill.Hangul/HangulConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ public static class HangulConstants {
/// 유니코드에서 한글 첫가끝 코드 종성의 마지막 문자(ᇂ)를 가리킴
/// </summary>
public const char LastIPFJongseong = '\u11C2'; // U+11C2 == 4546 == ᇂ
}
}
42 changes: 32 additions & 10 deletions Bluehill.Hangul/HangulSyllable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
/// </summary>
public required char Value {
get {
if (!IsValid) throw new InvalidOperationException(invalidMessage);
if (!IsValid) {
throw new InvalidOperationException(invalidMessage);
}

return _Value;
}
init {
if (!value.IsHangulSyllable()) throw new ArgumentException("문자가 한글 음절 문자가 아닙니다.", nameof(value));
if (!value.IsHangulSyllable()) {
throw new ArgumentException("문자가 한글 음절 문자가 아닙니다.", nameof(value));
}

_Value = value;
}
Expand Down Expand Up @@ -64,7 +68,9 @@ public required char Value {
/// <exception cref="ArgumentException"><paramref name="c"/>가 한글 음절 문자가 아님</exception>
[SetsRequiredMembers]
public HangulSyllable(char c) {
if (!c.IsHangulSyllable()) throw new ArgumentException("문자가 한글 음절 문자가 아닙니다.", nameof(c));
if (!c.IsHangulSyllable()) {
throw new ArgumentException("문자가 한글 음절 문자가 아닙니다.", nameof(c));
}

_Value = c;
}
Expand All @@ -87,9 +93,17 @@ public HangulSyllable(char c) {
/// <exception cref="ArgumentOutOfRangeException">초성 값이 18보다 높을 경우 또는 중성 값이 20보다 높을 경우 또는 종성 값이 27보다 높을 경우</exception>
[SetsRequiredMembers]
public HangulSyllable(byte choseong, byte jungseong, byte jongseong) {
if (choseong > 18) throw new ArgumentOutOfRangeException(nameof(choseong), choseong, "초성 값은 18 이하여야 합니다.");
if (jungseong > 20) throw new ArgumentOutOfRangeException(nameof(jungseong), jungseong, "중성 값은 20 이하여야 합니다.");
if (jongseong > 27) throw new ArgumentOutOfRangeException(nameof(jongseong), jongseong, "종성 값은 27 이하여야 합니다.");
if (choseong > 18) {
throw new ArgumentOutOfRangeException(nameof(choseong), choseong, "초성 값은 18 이하여야 합니다.");
}

if (jungseong > 20) {
throw new ArgumentOutOfRangeException(nameof(jungseong), jungseong, "중성 값은 20 이하여야 합니다.");
}

if (jongseong > 27) {
throw new ArgumentOutOfRangeException(nameof(jongseong), jongseong, "종성 값은 27 이하여야 합니다.");
}

_Value = getChar(choseong, jungseong, jongseong);
}
Expand All @@ -103,9 +117,17 @@ public HangulSyllable(byte choseong, byte jungseong, byte jongseong) {
/// <exception cref="ArgumentException"><paramref name="choseong"/>이 초성 낱자가 아님 또는 <paramref name="jungseong"/>이 중성 낱자가 아님 또는 <paramref name="jongseong"/>이 종성 낱자가 아님</exception>
[SetsRequiredMembers]
public HangulSyllable(char choseong, char jungseong, char jongseong) {
if (!Choseongs.Contains(choseong)) throw new ArgumentException("초성 낱자가 아닙니다.", nameof(choseong));
if (!Jungseongs.Contains(jungseong)) throw new ArgumentException("중성 낱자가 아닙니다.", nameof(jungseong));
if (!Jongseongs.Contains(jongseong)) throw new ArgumentException("종성 낱자가 아닙니다.", nameof(jongseong));
if (!Choseongs.Contains(choseong)) {
throw new ArgumentException("초성 낱자가 아닙니다.", nameof(choseong));
}

if (!Jungseongs.Contains(jungseong)) {
throw new ArgumentException("중성 낱자가 아닙니다.", nameof(jungseong));
}

if (!Jongseongs.Contains(jongseong)) {
throw new ArgumentException("종성 낱자가 아닙니다.", nameof(jongseong));
}

_Value = getChar(getByte(Choseongs, choseong), getByte(Jungseongs, jungseong), getByte(Jongseongs, jongseong));

Expand Down Expand Up @@ -204,4 +226,4 @@ public void Deconstruct(out Choseong choseong, out Jungseong jungseong, out Jong
}

private static char getChar(byte choseong, byte jungseong, byte jongseong) => (char)(FirstSyllable + (((choseong * 21) + jungseong) * 28) + jongseong);
}
}
8 changes: 4 additions & 4 deletions Bluehill.Hangul/Internal.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Bluehill.Hangul;

internal static class Internal {
internal static readonly char[] Choseongs = { 'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ' };
internal static readonly char[] Jungseongs = { 'ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ' };
internal static readonly char[] Jongseongs = { '\0', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ' };
}
internal static readonly char[] Choseongs = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
internal static readonly char[] Jungseongs = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'];
internal static readonly char[] Jongseongs = ['\0', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
}
2 changes: 1 addition & 1 deletion Bluehill.Hangul/Jongseong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ public enum Jongseong : byte {
Pieup,
/// <summary>ㅎ 받침을 나타냄</summary>
Hieut,
}
}
38 changes: 35 additions & 3 deletions Bluehill.Hangul/Josa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,24 @@ public static class Josa {
/// <param name="josaOnly">입력 문자열 없이 조사만 반환할지 여부</param>
/// <returns>마지막 글자의 받침 여부에 따라 <paramref name="defaultJosa"/> 또는 <paramref name="jongseong"/> 또는 <paramref name="noJongseong"/>을 붙인 문자열</returns>
public static string Jongseong(this string str, string defaultJosa, string jongseong, string noJongseong, bool josaOnly) {
if (str is null) {
throw new ArgumentNullException(nameof(str));
}

if (defaultJosa is null) {
throw new ArgumentNullException(nameof(defaultJosa));
}

if (jongseong is null) {
throw new ArgumentNullException(nameof(jongseong));
}

if (noJongseong is null) {
throw new ArgumentNullException(nameof(noJongseong));
}

// 문자열이 비어 있으면 기본 조사를 반환
if (string.IsNullOrEmpty(str)) {
if (str == string.Empty) {
return defaultJosa;
}

Expand All @@ -37,8 +53,24 @@ public static string Jongseong(this string str, string defaultJosa, string jongs
/// <param name="josaOnly">입력 문자열 없이 조사만 반환할지 여부</param>
/// <returns>마지막 글자의 ㄹ받침 여부에 따라 <paramref name="defaultJosa"/> 또는 <paramref name="rieul"/> 또는 <paramref name="noRieul"/>을 붙인 문자열</returns>
public static string NoJongseongOrRieul(this string str, string defaultJosa, string rieul, string noRieul, bool josaOnly) {
if (str is null) {
throw new ArgumentNullException(nameof(str));
}

if (defaultJosa is null) {
throw new ArgumentNullException(nameof(defaultJosa));
}

if (rieul is null) {
throw new ArgumentNullException(nameof(rieul));
}

if (noRieul is null) {
throw new ArgumentNullException(nameof(noRieul));
}

// 문자열이 비어 있으면 기본 조사를 반환
if (string.IsNullOrEmpty(str)) {
if (str == string.Empty) {
return defaultJosa;
}

Expand Down Expand Up @@ -217,4 +249,4 @@ public static string NoJongseongOrRieul(this string str, string defaultJosa, str
/// <param name="josaOnly">입력 문자열 없이 조사만 반환할지 여부</param>
/// <returns>'로' 또는 '으로'를 붙인 문자열</returns>
public static string EuRo(this string str, string defaultJosa, bool josaOnly) => NoJongseongOrRieul(str, defaultJosa, Ro, Euro, josaOnly);
}
}
2 changes: 1 addition & 1 deletion Bluehill.Hangul/Jungseong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public enum Jungseong : byte {
Ui,
/// <summary>모음 ㅣ를 나타냄</summary>
I,
}
}

0 comments on commit cde1bbe

Please sign in to comment.