mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
feat: enable InternalImportsByDefault feature flag
This commit is contained in:
@@ -5,20 +5,20 @@
|
||||
// Created by ensan on 2023/04/30.
|
||||
//
|
||||
|
||||
import Algorithms
|
||||
package import Algorithms
|
||||
import Foundation
|
||||
|
||||
public extension Sequence {
|
||||
package extension Sequence {
|
||||
/// Returns a sequence that contains the elements of this sequence followed by the elements of the given sequence.
|
||||
/// - Parameters:
|
||||
/// - sequence: A sequence of elements to chain.
|
||||
/// - Returns: A sequence that contains the elements of this sequence followed by the elements of the given sequence.
|
||||
@inlinable func chained<S: Sequence<Element>>(_ sequence: S) -> Chain2Sequence<Self, S> {
|
||||
func chained<S: Sequence<Element>>(_ sequence: S) -> Chain2Sequence<Self, S> {
|
||||
chain(self, sequence)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Collection {
|
||||
package extension Collection {
|
||||
/// Returns a `Set` containing the elements of this sequence with transformed values.
|
||||
/// - Parameters:
|
||||
/// - transform: A closure that transforms each element of this sequence into a value that can be hashed.
|
||||
@@ -60,18 +60,18 @@ public extension Collection {
|
||||
}
|
||||
}
|
||||
|
||||
public extension MutableCollection {
|
||||
package extension MutableCollection {
|
||||
/// Calls the given closure with a pointer to the array's mutable contiguous storage.
|
||||
/// - Parameter
|
||||
/// - transform: A closure that takes a pointer to the array's mutable contiguous storage.
|
||||
@inlinable mutating func mutatingForeach(transform closure: (inout Element) throws -> Void) rethrows {
|
||||
@inlinable mutating func mutatingForEach(transform closure: (inout Element) throws -> Void) rethrows {
|
||||
for index in self.indices {
|
||||
try closure(&self[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Collection {
|
||||
package extension Collection {
|
||||
/// Returns a SubSequence containing the elements of this sequence up to the first element that does not satisfy the given predicate.
|
||||
/// - Parameters:
|
||||
/// - condition: A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be included.
|
||||
@@ -85,7 +85,7 @@ public extension Collection {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Collection where Self.Element: Equatable {
|
||||
package extension Collection where Self.Element: Equatable {
|
||||
/// Returns a Bool value indicating whether the collection has the given prefix.
|
||||
/// - Parameters:
|
||||
/// - prefix: A collection to search for at the start of this collection.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum CharacterUtils {
|
||||
package enum CharacterUtils {
|
||||
/// 小書きのかなカナ集合
|
||||
private static let kogakiKana: Set<Character> = [
|
||||
"ぁ", "ぃ", "ぅ", "ぇ", "ぉ", "ゕ", "ゖ", "っ", "ゃ", "ゅ", "ょ", "ゎ",
|
||||
@@ -26,12 +26,12 @@ public enum CharacterUtils {
|
||||
}
|
||||
|
||||
/// ローマ字(a-z, A-Zか否か)
|
||||
@inlinable public static func isRomanLetter(_ character: Character) -> Bool {
|
||||
@inlinable package static func isRomanLetter(_ character: Character) -> Bool {
|
||||
character.isASCII && character.isCased
|
||||
}
|
||||
|
||||
/// 自分が小書きであれば該当する文字を返す。
|
||||
public static func kogaki(_ character: Character) -> Character {
|
||||
package static func kogaki(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case "あ": return "ぁ"
|
||||
case "い": return "ぃ"
|
||||
@@ -62,7 +62,7 @@ public enum CharacterUtils {
|
||||
}
|
||||
|
||||
/// 小書きから大書きを返す
|
||||
public static func ogaki(_ character: Character) -> Character {
|
||||
package static func ogaki(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case "ぁ": return "あ"
|
||||
case "ぃ": return "い"
|
||||
@@ -93,11 +93,11 @@ public enum CharacterUtils {
|
||||
}
|
||||
|
||||
/// 濁点付きか否か
|
||||
public static func isDakuten(_ character: Character) -> Bool {
|
||||
package static func isDakuten(_ character: Character) -> Bool {
|
||||
dakutenKana.contains(character)
|
||||
}
|
||||
/// 濁点をつけて返す
|
||||
public static func dakuten(_ character: Character) -> Character {
|
||||
package static func dakuten(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case"う": return "ゔ"
|
||||
case"か": return "が"
|
||||
@@ -145,7 +145,7 @@ public enum CharacterUtils {
|
||||
}
|
||||
}
|
||||
/// 濁点を外して返す
|
||||
public static func mudakuten(_ character: Character) -> Character {
|
||||
package static func mudakuten(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case"ゔ": return "う"
|
||||
case"が": return "か"
|
||||
@@ -193,14 +193,14 @@ public enum CharacterUtils {
|
||||
}
|
||||
}
|
||||
/// 半濁点かどうか
|
||||
public static func isHandakuten(_ character: Character) -> Bool {
|
||||
package static func isHandakuten(_ character: Character) -> Bool {
|
||||
[
|
||||
"ぱ", "ぴ", "ぷ", "ぺ", "ぽ",
|
||||
"パ", "ピ", "プ", "ペ", "ポ"
|
||||
].contains(character)
|
||||
}
|
||||
/// 半濁点をつけて返す
|
||||
public static func handakuten(_ character: Character) -> Character {
|
||||
package static func handakuten(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case"は": return "ぱ"
|
||||
case"ひ": return "ぴ"
|
||||
@@ -216,7 +216,7 @@ public enum CharacterUtils {
|
||||
}
|
||||
}
|
||||
/// 半濁点を外して返す
|
||||
public static func muhandakuten(_ character: Character) -> Character {
|
||||
package static func muhandakuten(_ character: Character) -> Character {
|
||||
switch character {
|
||||
case"ぱ": return "は"
|
||||
case"ぴ": return "ひ"
|
||||
@@ -233,7 +233,7 @@ public enum CharacterUtils {
|
||||
}
|
||||
|
||||
/// 濁点、小書き、半濁点などを相互に変換する関数。
|
||||
public static func requestChange(_ character: Character) -> String {
|
||||
package static func requestChange(_ character: Character) -> String {
|
||||
if character.isLowercase {
|
||||
return character.uppercased()
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public enum CharacterUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public extension Character {
|
||||
package extension Character {
|
||||
/// Returns the Katakanized version of the character.
|
||||
@inlinable func toKatakana() -> Character {
|
||||
if self.unicodeScalars.count != 1 {
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
// Copyright © 2022 ensan. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
package import Foundation
|
||||
|
||||
extension Data {
|
||||
package extension Data {
|
||||
/// Converts this data to an array of the given type.
|
||||
/// - Parameter:
|
||||
/// - type: The type to convert this data to.
|
||||
/// - Returns: An array of the given type.
|
||||
@inlinable public func toArray<T>(of type: T.Type) -> [T] {
|
||||
func toArray<T>(of type: T.Type) -> [T] {
|
||||
self.withUnsafeBytes {pointer -> [T] in
|
||||
Array(
|
||||
UnsafeBufferPointer(
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension StringProtocol {
|
||||
package extension StringProtocol {
|
||||
/// ローマ字と数字のみかどうか
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
@usableFromInline
|
||||
var onlyRomanAlphabetOrNumber: Bool {
|
||||
!isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil
|
||||
}
|
||||
/// ローマ字のみかどうか
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
@usableFromInline
|
||||
var onlyRomanAlphabet: Bool {
|
||||
!isEmpty && range(of: "[^a-zA-Z]", options: .regularExpression) == nil
|
||||
}
|
||||
@@ -35,20 +35,21 @@ public extension StringProtocol {
|
||||
}
|
||||
/// 英語として許容可能な文字のみで構成されているか。
|
||||
/// - note: 空文字列の場合`false`を返す。
|
||||
@inlinable
|
||||
@usableFromInline
|
||||
var isEnglishSentence: Bool {
|
||||
!isEmpty && range(of: "[^0-9a-zA-Z\n !'_<>\\[\\]{}*@`\\^|~=\"#$%&\\+\\(\\),\\-\\./:;?’\\\\]", options: .regularExpression) == nil
|
||||
}
|
||||
|
||||
/// 仮名か
|
||||
@inlinable
|
||||
@usableFromInline
|
||||
var isKana: Bool {
|
||||
!isEmpty && range(of: "[^ぁ-ゖァ-ヶ]", options: .regularExpression) == nil
|
||||
}
|
||||
|
||||
/// Returns a String value in which Hiraganas are all converted to Katakana.
|
||||
/// - Returns: A String value in which Hiraganas are all converted to Katakana.
|
||||
@inlinable func toKatakana() -> String {
|
||||
@usableFromInline
|
||||
func toKatakana() -> String {
|
||||
// カタカナはutf16で常に2バイトなので、utf16単位で処理して良い
|
||||
let result = self.utf16.map { scalar -> UInt16 in
|
||||
if 0x3041 <= scalar && scalar <= 0x3096 {
|
||||
@@ -62,7 +63,8 @@ public extension StringProtocol {
|
||||
|
||||
/// Returns a String value in which Katakana are all converted to Hiragana.
|
||||
/// - Returns: A String value in which Katakana are all converted to Hiragana.
|
||||
@inlinable func toHiragana() -> String {
|
||||
@usableFromInline
|
||||
func toHiragana() -> String {
|
||||
// ひらがなはutf16で常に2バイトなので、utf16単位で処理して良い
|
||||
let result = self.utf16.map { scalar -> UInt16 in
|
||||
if 0x30A1 <= scalar && scalar <= 0x30F6 {
|
||||
|
||||
Reference in New Issue
Block a user