Skip to content

Commit 98c6d9c

Browse files
committed
Inital commit
0 parents  commit 98c6d9c

14 files changed

Lines changed: 491 additions & 0 deletions

File tree

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
excoding-*.tar
24+
25+
# Temporary files, for example, from tests.
26+
/tmp/
27+
28+
/priv/native/
29+
30+
/native/*/target

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Excoding
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `excoding` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:excoding, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at <https://hexdocs.pm/excoding>.
21+

lib/excoding.ex

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
defmodule Excoding do
2+
@moduledoc """
3+
String encoding/decoding library with NIF binding to rust [endcoding]() crate.
4+
5+
Supported encodings:
6+
7+
* 7-bit strict ASCII (`ascii`)
8+
* UTF-8 (`utf-8`)
9+
* UTF-16 in little endian (`utf-16` or `utf-16le`) and big endian (`utf-16be`)
10+
* All single byte encoding in WHATWG Encoding Standard:
11+
* IBM code page `ibm-866`
12+
* ISO 8859-{2,3,4,5,6,7,8,10,13,14,15,16}
13+
* KOI8-R, KOI8-U
14+
* MacRoman (`macintosh`), Macintosh Cyrillic encoding (`x-mac-cyrillic`)
15+
* Windows code pages `windows-874`, `windows-1250`, `windows-1251`, `windows-1252`
16+
(instead of ISO 8859-1), `windows-1253`, `windows-1254` (instead of ISO 8859-9),
17+
`windows-1255`, `windows-1256`, `windows-1257`, `windows-1258`
18+
* All multi byte encodings in WHATWG Encoding Standard:
19+
* Windows code page `windows-949` (`euc-kr`, since the strict EUC-KR is hardly used)
20+
* EUC-JP (`euc-jp`) and Windows code page `windows-932` (`shift_jis`, since it's the most widespread extension to Shift_JIS)
21+
* ISO-2022-JP (`iso-2022-jp`) with asymmetric JIS X 0212 support (Note: this is not yet up to date to the current standard)
22+
* GBK
23+
* GB 18030
24+
* Big5-2003 with HKSCS-2008 extensions
25+
* Encodings that were originally specified by WHATWG Encoding Standard:
26+
* HZ
27+
* ISO 8859-1 (`iso-8859-1` distinct from Windows code page `windows-1255`)
28+
29+
30+
### Example
31+
32+
iex> Excoding.encode("¥₪ש", "windows-1255")
33+
<<0xA5, 0xA4, 0xF9>>
34+
iex> Excoding.decode(<<0xA5, 0xA4, 0xF9>>, "windows-1255")
35+
"¥₪ש"
36+
"""
37+
use Rustler,
38+
otp_app: :excoding,
39+
crate: "excoding",
40+
mode: if(Mix.env() == :prod, do: :release, else: :debug)
41+
42+
@doc """
43+
Encodes utf-8 string using given codepage. If there are any unknown codes they
44+
will be converted into `?` in its place.
45+
"""
46+
@spec encode(string :: binary, codepage :: binary) :: binary
47+
def encode(_string, _codepage), do: error()
48+
49+
@doc """
50+
Decodes given binary from given codepage into utf-8 string.
51+
"""
52+
@spec decode(binary :: binary, codepage :: binary) :: binary
53+
def decode(_binary, _codepage), do: error()
54+
55+
@doc false
56+
def error(), do: :erlang.nif_error(:nif_not_loaded)
57+
end

mix.exs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
defmodule Excoding.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :excoding,
7+
version: "0.1.0",
8+
elixir: "~> 1.9",
9+
start_permanent: Mix.env() == :prod,
10+
deps: deps(),
11+
description:
12+
"String encoding/decoding NIF using rust [encoding](https://crates.io/crates/encoding) library",
13+
package: package()
14+
]
15+
end
16+
17+
# Run "mix help compile.app" to learn about applications.
18+
def application do
19+
[
20+
extra_applications: [:rustler]
21+
]
22+
end
23+
24+
# Run "mix help deps" to learn about dependencies.
25+
defp deps do
26+
[
27+
{:rustler, "~> 0.25.0"},
28+
{:rustler_precompiled, "~> 0.5"},
29+
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
30+
]
31+
end
32+
33+
defp package do
34+
[
35+
name: "excoding",
36+
maintainers: ["Kevin Seidel"],
37+
licenses: ["MIT"],
38+
links: %{"GitHub" => "https://github.com/moogle19/excoding"},
39+
files: ~w(.formatter.exs mix.exs README.md lib native)
40+
]
41+
end
42+
end

mix.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%{
2+
"castore": {:hex, :castore, "0.1.17", "ba672681de4e51ed8ec1f74ed624d104c0db72742ea1a5e74edbc770c815182f", [:mix], [], "hexpm", "d9844227ed52d26e7519224525cb6868650c272d4a3d327ce3ca5570c12163f9"},
3+
"earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"},
4+
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
5+
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
6+
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
7+
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
8+
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
9+
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
10+
"rustler": {:hex, :rustler, "0.25.0", "32526b51af7e58a740f61941bf923486ce6415a91c3934cc16c281aa201a2240", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6b43a11a37fe79c6234d88c4102ab5dfede7a6a764dc5c7b539956cfa02f3cf4"},
11+
"rustler_precompiled": {:hex, :rustler_precompiled, "0.5.1", "93df423bd7b14b67dcacf994443d132d300623f80756974cac4febeab40af74a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "3f8cbc8e92eef4e1a71bf441b568b868b16a3730f63f5b803c68073017e30b13"},
12+
"toml": {:hex, :toml, "0.6.2", "38f445df384a17e5d382befe30e3489112a48d3ba4c459e543f748c2f25dd4d1", [:mix], [], "hexpm", "d013e45126d74c0c26a38d31f5e8e9b83ea19fc752470feb9a86071ca5a672fa"},
13+
}

native/excoding/.cargo/config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[target.'cfg(target_os = "macos")']
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]

native/excoding/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

native/excoding/Cargo.lock

Lines changed: 204 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)