Skip to content

Commit

Permalink
Better wchar-t support.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Mar 4, 2021
1 parent a606a80 commit 69fb96f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject cnuernber/dtype-next "6.05"
(defproject cnuernber/dtype-next "6.05-SNAPSHOT"
:description "A Clojure library designed to aid in the implementation of high performance algorithms and systems."
:url "http://github.com/cnuernber/dtype-next"
:license {:name "EPL-2.0"
Expand Down
36 changes: 34 additions & 2 deletions src/tech/v3/datatype/ffi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,45 @@ user> dbuf
"Convert an item into a Pointer, throwing an exception upon failure."))


(defn utf16-platform-encoding
"Get the utf-16 encoding that matches the current platform so you can encode
a utf-16 string without a bom."
[]
(case (dtype-proto/platform-endianness)
:little-endian :utf-16LE
:big-endian :utf-16BE))


(defn utf32-platform-encoding
"Get the utf-16 encoding that matches the current platform so you can encode
a utf-16 string without a bom."
[]
(case (dtype-proto/platform-endianness)
:little-endian :utf-32LE
:big-endian :utf-32BE))


(defn windows-platform?
[]
(-> (System/getProperty "os.name")
(.toLowerCase)
(.contains "win")))


(defn ^:private encoding->info
[encoding]
(case (or encoding :utf-8)
:ascii [1 "ASCII"]
:utf-8 [1 "UTF-8"]
:utf-16 [2 "UTF-16"]
:utf-32 [4 "UTF-32"]))
:utf-16LE [2 "UTF-16LE"]
:utf-16BE [2 "UTF-16BE"]
:utf-32 [4 "UTF-32"]
:utf-32LE [4 "UTF-32LE"]
:utf-32BE [4 "UTF-32BE"]
:wchar-t (if (windows-platform?)
(encoding->info (utf16-platform-encoding))
(encoding->info (utf32-platform-encoding)))))

(def ^{:tag BiFunction
:private true} incrementor
Expand Down Expand Up @@ -162,7 +194,7 @@ user> dbuf
(defn string->c
"Convert a java String to a zero-padded c-string. Available encodings are
* `:ascii`, `:utf-8` (default), `:utf-16`, and `:utf-32`
* `:ascii`, `:utf-8` (default), `:utf-16`, `:utf-16LE`, `utf-16-BE` and `:utf-32`
String data will be zero padded."
^NativeBuffer [str-data & [{:keys [encoding]
Expand Down

0 comments on commit 69fb96f

Please sign in to comment.