Skip to content

Commit

Permalink
Revert "add swift native package"
Browse files Browse the repository at this point in the history
This reverts commit 70e98ff.
  • Loading branch information
paiv committed Nov 12, 2024
1 parent 70e98ff commit d261c28
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 1,102 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ __pycache__/
*.py[cdo]
*.egg-info/
*.so
.swiftpm/

33 changes: 19 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
// swift-tools-version: 5.8
// swift-tools-version:5.1

import PackageDescription

let package = Package(
name: "uklatn",
products: [
.library(
name: "UkrainianLatin",
targets: ["UkrainianLatin"]),
.executable(
name: "uklatn",
targets: ["cli"]),
name: "UKLatn",
targets: ["UKLatn"]),
],
targets: [
.target(
name: "UkrainianLatin",
path: "swift/Sources/UkrainianLatin"),
name: "UKLatn",
dependencies: ["_uklatn"],
path: "swift/Sources/UKLatn"),
.target(
name: "_uklatn",
path: "swift/Sources/_uklatn",
cSettings: [
.headerSearchPath("../../../c/include"),
],
linkerSettings: [
.linkedLibrary("icuuc"),
.linkedLibrary("icui18n"),
]),
.testTarget(
name: "UKLatnTests",
dependencies: ["UkrainianLatin"],
path: "swift/Tests/UkrainianLatinTests"),
.executableTarget(
name: "cli",
dependencies: ["UkrainianLatin"],
path: "swift/Sources/cli"),
dependencies: ["UKLatn"],
path: "swift/Tests/UKLatnTests"),
],
swiftLanguageVersions: [.v5]
)

13 changes: 11 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Ukrainian Cyrillic transliteration to Latin script.
[![standwithukraine](docs/StandWithUkraine.svg)](https://ukrainewar.carrd.co/)
[![](https://github.com/paiv/uklatn/actions/workflows/test-builds.yml/badge.svg)](https://github.com/paiv/uklatn/actions)

[JavaScript](#javascript-package) | [Python](#python-module) | [C](c/) | [Swift](#swift-package)
[JavaScript](#javascript-package) | [Python](#python-module) | [C](#c-library) | [Swift](#swift-package)

Supported transliteration schemes:
- [DSTU 9112:2021](https://uk.wikipedia.org/wiki/ДСТУ_9112:2021)
Expand Down Expand Up @@ -46,14 +46,23 @@ uklatn.decode("Paljanycja")
```


C library
--
- [uklatn C library](c/)


Swift package
--
- [uklatn Swift package](swift/)

Add package dependency:
```sh
swift package add-dependency 'https://github.com/paiv/uklatn.git' --from '1.0.0'
swift package add-target-dependency --package uklatn UkrainianLatin <target-name>
```

Use in target dependencies in `Package.swift`:
```swift
.product(name: "UKLatn", package: "uklatn")
```


Expand Down
43 changes: 43 additions & 0 deletions swift/Sources/UKLatn/UKLatn.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import _uklatn


public struct UKLatnTable {
public static let DSTU_9112_A = Int(_uklatn.UklatnTable_DSTU_9112_A.rawValue)
public static let DSTU_9112_B = Int(_uklatn.UklatnTable_DSTU_9112_B.rawValue)
public static let KMU_55 = Int(_uklatn.UklatnTable_KMU_55.rawValue)
}


public enum UKLatnError: Error {
case failed(code: Int)
}


public func encode(_ text: String, table: Int = 0) throws -> String {
let n = text.utf8.count
let dst = UnsafeMutableBufferPointer<CChar>.allocate(capacity: n * 3)
defer {
dst.deallocate()
}
let err = _uklatn.uklatn_encode(text, Int32(table), dst.baseAddress, Int32(dst.count))
if err != 0 {
throw UKLatnError.failed(code: Int(err))
}
let res = String(cString: dst.baseAddress!)
return res
}


public func decode(_ text: String, table: Int = 0) throws -> String {
let n = text.utf8.count
let dst = UnsafeMutableBufferPointer<CChar>.allocate(capacity: n * 3)
defer {
dst.deallocate()
}
let err = _uklatn.uklatn_decode(text, Int32(table), dst.baseAddress, Int32(dst.count))
if err != 0 {
throw UKLatnError.failed(code: Int(err))
}
let res = String(cString: dst.baseAddress!)
return res
}
215 changes: 0 additions & 215 deletions swift/Sources/UkrainianLatin/UKLatn.swift

This file was deleted.

2 changes: 2 additions & 0 deletions swift/Sources/_uklatn/_uklatn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "include/_uklatn/_uklatn.h"
#include "../../../c/uklatn.c"
3 changes: 3 additions & 0 deletions swift/Sources/_uklatn/include/_uklatn/_uklatn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#include "../../../../../c/include/uklatn.h"

Loading

0 comments on commit d261c28

Please sign in to comment.