feat: enable InternalImportsByDefault feature flag

This commit is contained in:
Miwa / Ensan
2025-06-15 19:30:51 +09:00
parent 4d4e54691c
commit 543f6d93be
16 changed files with 53 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ import Foundation
let swiftSettings: [SwiftSetting] = [ let swiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("ExistentialAny"), .enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("MemberImportVisibility"), .enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InternalImportsByDefault"),
.interoperabilityMode(.Cxx, .when(traits: ["Zenzai"])) .interoperabilityMode(.Cxx, .when(traits: ["Zenzai"]))
] ]

View File

@@ -2,8 +2,8 @@ import KanaKanjiConverterModuleWithDefaultDictionary
import ArgumentParser import ArgumentParser
@main @main
public struct Anco: AsyncParsableCommand { struct Anco: AsyncParsableCommand {
public static let configuration = CommandConfiguration( static let configuration = CommandConfiguration(
abstract: "Anco is A(zooKey) Kana-Ka(n)ji (co)nverter", abstract: "Anco is A(zooKey) Kana-Ka(n)ji (co)nverter",
subcommands: [ subcommands: [
Subcommands.Run.self, Subcommands.Run.self,
@@ -17,5 +17,5 @@ public struct Anco: AsyncParsableCommand {
defaultSubcommand: Subcommands.Run.self defaultSubcommand: Subcommands.Run.self
) )
public init() {} init() {}
} }

View File

@@ -74,9 +74,9 @@ extension Subcommands {
if stable { if stable {
result.execution_time = 0 result.execution_time = 0
result.timestamp = 0 result.timestamp = 0
result.items.mutatingForeach { result.items.mutatingForEach {
$0.entropy = Double(Int($0.entropy * 10)) / 10 $0.entropy = Double(Int($0.entropy * 10)) / 10
$0.outputs.mutatingForeach { $0.outputs.mutatingForEach {
$0.score = Double(Int($0.score)) $0.score = Double(Int($0.score))
} }
} }

View File

@@ -69,8 +69,8 @@ extension Subcommands {
if stable { if stable {
result.execution_time = 0 result.execution_time = 0
result.timestamp = 0 result.timestamp = 0
result.items.mutatingForeach { result.items.mutatingForEach {
$0.outputs.mutatingForeach { $0.outputs.mutatingForEach {
$0.score = Double(Int($0.score)) $0.score = Double(Int($0.score))
} }
} }

View File

@@ -6,7 +6,7 @@
// Copyright © 2022 ensan. All rights reserved. // Copyright © 2022 ensan. All rights reserved.
// //
import Foundation public import Foundation
public struct ConvertRequestOptions: Sendable { public struct ConvertRequestOptions: Sendable {
/// ///

View File

@@ -7,7 +7,7 @@
// //
import Algorithms import Algorithms
import Foundation package import Foundation
import SwiftUtils import SwiftUtils
import EfficientNGram import EfficientNGram
@@ -19,7 +19,7 @@ import EfficientNGram
} }
private var converter = Kana2Kanji() private var converter = Kana2Kanji()
public static let defaultSpecialCandidateProviders: [any SpecialCandidateProvider] = [ nonisolated public static let defaultSpecialCandidateProviders: [any SpecialCandidateProvider] = [
CalendarSpecialCandidateProvider(), CalendarSpecialCandidateProvider(),
EmailAddressSpecialCandidateProvider(), EmailAddressSpecialCandidateProvider(),
UnicodeSpecialCandidateProvider(), UnicodeSpecialCandidateProvider(),
@@ -582,7 +582,7 @@ import EfficientNGram
result.append(contentsOf: clause_candidates) result.append(contentsOf: clause_candidates)
result.append(contentsOf: word_candidates) result.append(contentsOf: word_candidates)
result.mutatingForeach { item in result.mutatingForEach { item in
item.withActions(self.getAppropriateActions(item)) item.withActions(self.getAppropriateActions(item))
item.parseTemplate() item.parseTemplate()
} }

View File

@@ -125,7 +125,7 @@ public final class DicdataStore {
self.closeKeyboard() self.closeKeyboard()
case .importOSUserDict(let dicdata), .importDynamicUserDict(let dicdata): case .importOSUserDict(let dicdata), .importDynamicUserDict(let dicdata):
self.dynamicUserDict = dicdata self.dynamicUserDict = dicdata
self.dynamicUserDict.mutatingForeach { self.dynamicUserDict.mutatingForEach {
$0.metadata = .isFromUserDictionary $0.metadata = .isFromUserDictionary
} }
case let .forgetMemory(candidate): case let .forgetMemory(candidate):
@@ -258,12 +258,12 @@ public final class DicdataStore {
data.append(contentsOf: LOUDS.getDataForLoudstxt3(identifier + "\(key)", indices: value.map {$0 & 2047}, cache: self.loudstxts[identifier + "\(key)"], option: self.requestOptions)) data.append(contentsOf: LOUDS.getDataForLoudstxt3(identifier + "\(key)", indices: value.map {$0 & 2047}, cache: self.loudstxts[identifier + "\(key)"], option: self.requestOptions))
} }
if identifier == "memory" { if identifier == "memory" {
data.mutatingForeach { data.mutatingForEach {
$0.metadata = .isLearned $0.metadata = .isLearned
} }
} }
if identifier == "user" { if identifier == "user" {
data.mutatingForeach { data.mutatingForEach {
$0.metadata = .isFromUserDictionary $0.metadata = .isFromUserDictionary
} }
} }

View File

@@ -6,7 +6,7 @@
// Copyright © 2020 ensan. All rights reserved. // Copyright © 2020 ensan. All rights reserved.
// //
import Foundation package import Foundation
import SwiftUtils import SwiftUtils
extension LOUDS { extension LOUDS {

View File

@@ -6,7 +6,7 @@
// Copyright © 2023 ensan. All rights reserved. // Copyright © 2023 ensan. All rights reserved.
// //
import Foundation public import Foundation
import SwiftUtils import SwiftUtils
/// `TextReplacer` /// `TextReplacer`

View File

@@ -6,7 +6,7 @@
// Copyright © 2020 ensan. All rights reserved. // Copyright © 2020 ensan. All rights reserved.
// //
import Foundation public import Foundation
import SwiftUtils import SwiftUtils
public struct TemplateData: Codable, Sendable { public struct TemplateData: Codable, Sendable {

View File

@@ -1,4 +1,4 @@
import Foundation package import Foundation
import SwiftUtils import SwiftUtils
import EfficientNGram import EfficientNGram

View File

@@ -1,5 +1,5 @@
@_exported import KanaKanjiConverterModule @_exported public import KanaKanjiConverterModule
import Foundation public import Foundation
public extension ConvertRequestOptions { public extension ConvertRequestOptions {
static func withDefaultDictionary( static func withDefaultDictionary(

View File

@@ -5,20 +5,20 @@
// Created by ensan on 2023/04/30. // Created by ensan on 2023/04/30.
// //
import Algorithms package import Algorithms
import Foundation 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. /// Returns a sequence that contains the elements of this sequence followed by the elements of the given sequence.
/// - Parameters: /// - Parameters:
/// - sequence: A sequence of elements to chain. /// - 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. /// - 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) chain(self, sequence)
} }
} }
public extension Collection { package extension Collection {
/// Returns a `Set` containing the elements of this sequence with transformed values. /// Returns a `Set` containing the elements of this sequence with transformed values.
/// - Parameters: /// - Parameters:
/// - transform: A closure that transforms each element of this sequence into a value that can be hashed. /// - 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. /// Calls the given closure with a pointer to the array's mutable contiguous storage.
/// - Parameter /// - Parameter
/// - transform: A closure that takes a pointer to the array's mutable contiguous storage. /// - 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 { for index in self.indices {
try closure(&self[index]) 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. /// Returns a SubSequence containing the elements of this sequence up to the first element that does not satisfy the given predicate.
/// - Parameters: /// - 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. /// - 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. /// Returns a Bool value indicating whether the collection has the given prefix.
/// - Parameters: /// - Parameters:
/// - prefix: A collection to search for at the start of this collection. /// - prefix: A collection to search for at the start of this collection.

View File

@@ -8,7 +8,7 @@
import Foundation import Foundation
public enum CharacterUtils { package enum CharacterUtils {
/// ///
private static let kogakiKana: Set<Character> = [ private static let kogakiKana: Set<Character> = [
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
@@ -26,12 +26,12 @@ public enum CharacterUtils {
} }
/// (a-z, A-Z) /// (a-z, A-Z)
@inlinable public static func isRomanLetter(_ character: Character) -> Bool { @inlinable package static func isRomanLetter(_ character: Character) -> Bool {
character.isASCII && character.isCased character.isASCII && character.isCased
} }
/// ///
public static func kogaki(_ character: Character) -> Character { package static func kogaki(_ character: Character) -> Character {
switch character { switch character {
case "": return "" case "": return ""
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 { switch character {
case "": return "" case "": return ""
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) dakutenKana.contains(character)
} }
/// ///
public static func dakuten(_ character: Character) -> Character { package static func dakuten(_ character: Character) -> Character {
switch character { switch character {
case"": return "" case"": return ""
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 { switch character {
case"": return "" case"": return ""
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) ].contains(character)
} }
/// ///
public static func handakuten(_ character: Character) -> Character { package static func handakuten(_ character: Character) -> Character {
switch character { switch character {
case"": return "" case"": return ""
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 { switch character {
case"": return "" case"": return ""
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 { if character.isLowercase {
return character.uppercased() return character.uppercased()
} }
@@ -285,7 +285,7 @@ public enum CharacterUtils {
} }
} }
public extension Character { package extension Character {
/// Returns the Katakanized version of the character. /// Returns the Katakanized version of the character.
@inlinable func toKatakana() -> Character { @inlinable func toKatakana() -> Character {
if self.unicodeScalars.count != 1 { if self.unicodeScalars.count != 1 {

View File

@@ -6,14 +6,14 @@
// Copyright © 2022 ensan. All rights reserved. // 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. /// Converts this data to an array of the given type.
/// - Parameter: /// - Parameter:
/// - type: The type to convert this data to. /// - type: The type to convert this data to.
/// - Returns: An array of the given type. /// - 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 self.withUnsafeBytes {pointer -> [T] in
Array( Array(
UnsafeBufferPointer( UnsafeBufferPointer(

View File

@@ -8,16 +8,16 @@
import Foundation import Foundation
public extension StringProtocol { package extension StringProtocol {
/// ///
/// - note: `false` /// - note: `false`
@inlinable @usableFromInline
var onlyRomanAlphabetOrNumber: Bool { var onlyRomanAlphabetOrNumber: Bool {
!isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil !isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil
} }
/// ///
/// - note: `false` /// - note: `false`
@inlinable @usableFromInline
var onlyRomanAlphabet: Bool { var onlyRomanAlphabet: Bool {
!isEmpty && range(of: "[^a-zA-Z]", options: .regularExpression) == nil !isEmpty && range(of: "[^a-zA-Z]", options: .regularExpression) == nil
} }
@@ -35,20 +35,21 @@ public extension StringProtocol {
} }
/// ///
/// - note: `false` /// - note: `false`
@inlinable @usableFromInline
var isEnglishSentence: Bool { var isEnglishSentence: Bool {
!isEmpty && range(of: "[^0-9a-zA-Z\n !'_<>\\[\\]{}*@`\\^|~=\"#$%&\\+\\(\\),\\-\\./:;?\\\\]", options: .regularExpression) == nil !isEmpty && range(of: "[^0-9a-zA-Z\n !'_<>\\[\\]{}*@`\\^|~=\"#$%&\\+\\(\\),\\-\\./:;?\\\\]", options: .regularExpression) == nil
} }
/// ///
@inlinable @usableFromInline
var isKana: Bool { var isKana: Bool {
!isEmpty && range(of: "[^ぁ-ゖァ-ヶ]", options: .regularExpression) == nil !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.
/// - 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 {
// utf162utf16 // utf162utf16
let result = self.utf16.map { scalar -> UInt16 in let result = self.utf16.map { scalar -> UInt16 in
if 0x3041 <= scalar && scalar <= 0x3096 { 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.
/// - 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 {
// utf162utf16 // utf162utf16
let result = self.utf16.map { scalar -> UInt16 in let result = self.utf16.map { scalar -> UInt16 in
if 0x30A1 <= scalar && scalar <= 0x30F6 { if 0x30A1 <= scalar && scalar <= 0x30F6 {