Skip to content

Commit

Permalink
Add InputValidityCheck(charStr:). (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored May 28, 2023
1 parent f6e77f1 commit abba66d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Tekkon.Tests/Tekkon.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ReleaseVersion>1.5.0</ReleaseVersion>
<ReleaseVersion>1.5.1</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Tekkon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ Global
$0.DotNetNamingPolicy = $4
$4.DirectoryNamespaceAssociation = PrefixedHierarchical
$0.StandardHeader = $5
version = 1.5.0
version = 1.5.1
EndGlobalSection
EndGlobal
76 changes: 41 additions & 35 deletions Tekkon/Composer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,47 @@ public void Clear() {
/// <returns>傳入的字符是否合規。</returns>
public bool InputValidityCheck(int inputCharCode) {
char inputKey = (char)Math.Abs(inputCharCode);
if (inputKey >= 128) return false;
switch (Parser) {
case MandarinParser.OfDachen:
return Shared.MapQwertyDachen.ContainsKey(inputKey.ToString());
case MandarinParser.OfDachen26:
return Shared.MapDachenCp26StaticKeys.ContainsKey(inputKey.ToString());
case MandarinParser.OfETen:
return Shared.MapQwertyETenTraditional.ContainsKey(inputKey.ToString());
case MandarinParser.OfHsu:
return Shared.MapHsuStaticKeys.ContainsKey(inputKey.ToString());
case MandarinParser.OfETen26:
return Shared.MapETen26StaticKeys.ContainsKey(inputKey.ToString());
case MandarinParser.OfIBM:
return Shared.MapQwertyIBM.ContainsKey(inputKey.ToString());
case MandarinParser.OfMiTAC:
return Shared.MapQwertyMiTAC.ContainsKey(inputKey.ToString());
case MandarinParser.OfSeigyou:
return Shared.MapSeigyou.ContainsKey(inputKey.ToString());
case MandarinParser.OfFakeSeigyou:
return Shared.MapFakeSeigyou.ContainsKey(inputKey.ToString());
case MandarinParser.OfStarlight:
return Shared.MapStarlightStaticKeys.ContainsKey(inputKey.ToString());
case MandarinParser.OfAlvinLiu:
return Shared.MapAlvinLiuStaticKeys.ContainsKey(inputKey.ToString());
case MandarinParser.OfWadeGilesPinyin:
return Shared.MapWadeGilesPinyinKeys.Contains(inputKey);
case MandarinParser.OfHanyuPinyin:
case MandarinParser.OfSecondaryPinyin:
case MandarinParser.OfYalePinyin:
case MandarinParser.OfHualuoPinyin:
case MandarinParser.OfUniversalPinyin:
return Shared.MapArayuruPinyin.Contains(inputKey);
default:
return false;
}
return (inputKey < 128) && InputValidityCheckStr(inputKey.ToString());
}

/// <summary>
/// 用於檢測「某個輸入字符訊號的合規性」的函式。<br />
/// <br />
/// 注意:回傳結果會受到當前注音排列 parser 屬性的影響。
/// </summary>
/// <param name="charStr">傳入的字元(String)。</param>
/// <returns>傳入的字符是否合規。</returns>
public bool InputValidityCheckStr(string charStr) {
return Parser switch {
MandarinParser.OfDachen => Shared.MapQwertyDachen.ContainsKey(charStr),
MandarinParser.OfDachen26 =>
Shared.MapDachenCp26StaticKeys.ContainsKey(charStr),
MandarinParser.OfETen =>
Shared.MapQwertyETenTraditional.ContainsKey(charStr),
MandarinParser.OfHsu => Shared.MapHsuStaticKeys.ContainsKey(charStr),
MandarinParser.OfETen26 =>
Shared.MapETen26StaticKeys.ContainsKey(charStr),
MandarinParser.OfIBM => Shared.MapQwertyIBM.ContainsKey(charStr),
MandarinParser.OfMiTAC => Shared.MapQwertyMiTAC.ContainsKey(charStr),
MandarinParser.OfSeigyou => Shared.MapSeigyou.ContainsKey(charStr),
MandarinParser.OfFakeSeigyou =>
Shared.MapFakeSeigyou.ContainsKey(charStr),
MandarinParser.OfStarlight =>
Shared.MapStarlightStaticKeys.ContainsKey(charStr),
MandarinParser.OfAlvinLiu =>
Shared.MapAlvinLiuStaticKeys.ContainsKey(charStr),
MandarinParser.OfWadeGilesPinyin =>
Shared.MapWadeGilesPinyinKeys.Contains(charStr),
MandarinParser.OfHanyuPinyin => Shared.MapArayuruPinyin.Contains(charStr),
MandarinParser.OfSecondaryPinyin =>
Shared.MapArayuruPinyin.Contains(charStr),
MandarinParser.OfYalePinyin => Shared.MapArayuruPinyin.Contains(charStr),
MandarinParser.OfHualuoPinyin =>
Shared.MapArayuruPinyin.Contains(charStr),
MandarinParser.OfUniversalPinyin =>
Shared.MapArayuruPinyin.Contains(charStr),
_ => false
};
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Tekkon/Tekkon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<CodePage>65001</CodePage>
<ReleaseVersion>1.5.0</ReleaseVersion>
<ReleaseVersion>1.5.1</ReleaseVersion>
<PackageId>vChewing.Tekkon</PackageId>
<Authors>Shiki Suen</Authors>
<Company>Atelier Inmu</Company>
<Copyright>(c) 2022 and onwards The vChewing Project (MIT-NTL License).</Copyright>
<RepositoryUrl>https://github.com/ShikiSuen/TekkonNT</RepositoryUrl>
<NeutralLanguage>zh-TW</NeutralLanguage>
<AssemblyVersion>1.5.0</AssemblyVersion>
<FileVersion>1.5.0</FileVersion>
<Version>1.5.0</Version>
<AssemblyVersion>1.5.1</AssemblyVersion>
<FileVersion>1.5.1</FileVersion>
<Version>1.5.1</Version>
<Product>Tekkon</Product>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit abba66d

Please sign in to comment.