Merge pull request #206 from azooKey/feat/enable_upcoming_features

feat(breaking): enable upcoming features for future compatibility
This commit is contained in:
Miwa
2025-06-15 19:52:01 +09:00
committed by GitHub
27 changed files with 63 additions and 40 deletions

View File

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

View File

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

View File

@ -1,6 +1,7 @@
import KanaKanjiConverterModuleWithDefaultDictionary
import ArgumentParser
import Foundation
import SwiftUtils
extension Subcommands {
struct Evaluate: AsyncParsableCommand {
@ -73,9 +74,9 @@ extension Subcommands {
if stable {
result.execution_time = 0
result.timestamp = 0
result.items.mutatingForeach {
result.items.mutatingForEach {
$0.entropy = Double(Int($0.entropy * 10)) / 10
$0.outputs.mutatingForeach {
$0.outputs.mutatingForEach {
$0.score = Double(Int($0.score))
}
}

View File

@ -1,3 +1,4 @@
import Algorithms
import KanaKanjiConverterModuleWithDefaultDictionary
import ArgumentParser
import Foundation

View File

@ -1,6 +1,7 @@
import KanaKanjiConverterModuleWithDefaultDictionary
import ArgumentParser
import Foundation
import SwiftUtils
extension Subcommands {
struct Run: AsyncParsableCommand {

View File

@ -1,6 +1,9 @@
import KanaKanjiConverterModuleWithDefaultDictionary
import Algorithms
import ArgumentParser
import Foundation
import KanaKanjiConverterModuleWithDefaultDictionary
import SwiftUtils
import Tokenizers
extension Subcommands {
struct Session: AsyncParsableCommand {

View File

@ -1,6 +1,7 @@
import KanaKanjiConverterModuleWithDefaultDictionary
import ArgumentParser
import Foundation
import SwiftUtils
extension Subcommands {
struct ZenzEvaluate: AsyncParsableCommand {
@ -68,8 +69,8 @@ extension Subcommands {
if stable {
result.execution_time = 0
result.timestamp = 0
result.items.mutatingForeach {
$0.outputs.mutatingForeach {
result.items.mutatingForEach {
$0.outputs.mutatingForEach {
$0.score = Double(Int($0.score))
}
}

View File

@ -6,6 +6,7 @@
// Copyright © 2022 ensan. All rights reserved.
//
import Foundation
import SwiftUtils
/// 3

View File

@ -7,6 +7,7 @@
//
import Foundation
import SwiftUtils
extension KanaKanjiConverter {
/// 西

View File

@ -1,4 +1,5 @@
import Foundation
import SwiftUtils
extension KanaKanjiConverter {
func commaSeparatedNumberCandidates(_ inputData: ComposingText) -> [Candidate] {
@ -18,7 +19,7 @@ extension KanaKanjiConverter {
let integerPart = parts[0]
guard integerPart.count > 3 else { return [] }
var reversed = Array(integerPart.reversed())
let reversed = Array(integerPart.reversed())
var formatted = ""
for (i, ch) in reversed.enumerated() {
if i > 0 && i % 3 == 0 {

View File

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

View File

@ -1,4 +1,5 @@
import Foundation
import SwiftUtils
extension KanaKanjiConverter {
private static let domains = [

View File

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

View File

@ -7,6 +7,7 @@
//
import Foundation
import SwiftUtils
private extension UnicodeScalar {
///

View File

@ -7,6 +7,7 @@
//
import Foundation
import SwiftUtils
extension KanaKanjiConverter {
/// unicode`"uxxxx, Uxxxx, u+xxxx, U+xxxx"`

View File

@ -7,6 +7,7 @@
//
import Foundation
import SwiftUtils
extension KanaKanjiConverter {

View File

@ -6,6 +6,7 @@
// Copyright © 2020 ensan. All rights reserved.
//
import Algorithms
import Foundation
import SwiftUtils
@ -124,7 +125,7 @@ public final class DicdataStore {
self.closeKeyboard()
case .importOSUserDict(let dicdata), .importDynamicUserDict(let dicdata):
self.dynamicUserDict = dicdata
self.dynamicUserDict.mutatingForeach {
self.dynamicUserDict.mutatingForEach {
$0.metadata = .isFromUserDictionary
}
case let .forgetMemory(candidate):
@ -257,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))
}
if identifier == "memory" {
data.mutatingForeach {
data.mutatingForEach {
$0.metadata = .isLearned
}
}
if identifier == "user" {
data.mutatingForeach {
data.mutatingForEach {
$0.metadata = .isFromUserDictionary
}
}

View File

@ -1,3 +1,4 @@
import Algorithms
import Foundation
import SwiftUtils
import EfficientNGram

View File

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

View File

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

View File

@ -7,6 +7,8 @@
//
import Foundation
import SwiftUtils
enum Roman2Kana {
static let katakanaChanges: [String: String] = Dictionary(uniqueKeysWithValues: hiraganaChanges.map { (String($0.key), String($0.value).toKatakana()) })
static let hiraganaChanges: [[Character]: [Character]] = Dictionary(uniqueKeysWithValues: [

View File

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

View File

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

View File

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

View File

@ -5,15 +5,15 @@
// 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)
}
}
@ -64,7 +64,7 @@ public 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])
}

View File

@ -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(

View File

@ -6,26 +6,26 @@
// Copyright © 2020 ensan. All rights reserved.
//
import Foundation
public import Foundation
public extension StringProtocol {
extension StringProtocol {
///
/// - note: `false`
@inlinable
var onlyRomanAlphabetOrNumber: Bool {
package var onlyRomanAlphabetOrNumber: Bool {
!isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil
}
///
/// - note: `false`
@inlinable
var onlyRomanAlphabet: Bool {
package var onlyRomanAlphabet: Bool {
!isEmpty && range(of: "[^a-zA-Z]", options: .regularExpression) == nil
}
///
/// - note: `false`
/// 40
@inlinable
var containsRomanAlphabet: Bool {
package var containsRomanAlphabet: Bool {
for value in self.utf8 {
if (UInt8(ascii: "a") <= value && value <= UInt8(ascii: "z")) || (UInt8(ascii: "A") <= value && value <= UInt8(ascii: "Z")) {
return true
@ -36,19 +36,20 @@ public extension StringProtocol {
///
/// - note: `false`
@inlinable
var isEnglishSentence: Bool {
public var isEnglishSentence: Bool {
!isEmpty && range(of: "[^0-9a-zA-Z\n !'_<>\\[\\]{}*@`\\^|~=\"#$%&\\+\\(\\),\\-\\./:;?\\\\]", options: .regularExpression) == nil
}
///
@inlinable
var isKana: Bool {
public 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 {
@inlinable
public func toKatakana() -> String {
// utf162utf16
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 {
@inlinable
public func toHiragana() -> String {
// utf162utf16
let result = self.utf16.map { scalar -> UInt16 in
if 0x30A1 <= scalar && scalar <= 0x30F6 {
@ -85,7 +87,7 @@ public extension StringProtocol {
" -> \d
*/
// please use these letters in order to avoid user-inputting text crash
func templateDataSpecificEscaped() -> String {
package func templateDataSpecificEscaped() -> String {
var result = self.replacingOccurrences(of: "\\", with: "\\b")
result = result.replacingOccurrences(of: "\0", with: "\\0")
result = result.replacingOccurrences(of: "\n", with: "\\n")
@ -96,7 +98,7 @@ public extension StringProtocol {
return result
}
func templateDataSpecificUnescaped() -> String {
package func templateDataSpecificUnescaped() -> String {
var result = self.replacingOccurrences(of: "\\d", with: "\"")
result = result.replacingOccurrences(of: "\\s", with: " ")
result = result.replacingOccurrences(of: "\\c", with: ",")