Skip to content

Commit

Permalink
Update version and update compatibility (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-d authored Feb 20, 2022
1 parent 046fc82 commit c3a6ef3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(lang dune 2.7)
(name ppx_pyformat)
(version "0.1.1")
(version "0.1.2")

(generate_opam_files true)

Expand All @@ -15,8 +15,8 @@
(synopsis "Ppxlib based string format rewriter inspired by Python string `format`")
(depends
(ocaml (>= 4.08))
(ppxlib (>= 0.22.0))
(ppxlib (>= 0.23.0))
(ppx_make (>= 0.3.0))
menhir
(menhir (>= 20200624))
(ounit2 :with-test)))
(using menhir 2.1)
6 changes: 3 additions & 3 deletions ppx_pyformat.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
version: "0.1.2"
synopsis:
"Ppxlib based string format rewriter inspired by Python string `format`"
maintainer: ["Boning <me@boni.ng>"]
Expand All @@ -12,9 +12,9 @@ bug-reports: "https://github.com/bn-d/ppx_pyformat/issues"
depends: [
"dune" {>= "2.7"}
"ocaml" {>= "4.08"}
"ppxlib" {>= "0.22.0"}
"ppxlib" {>= "0.23.0"}
"ppx_make" {>= "0.3.0"}
"menhir"
"menhir" {>= "20200624"}
"ounit2" {with-test}
"odoc" {with-doc}
]
Expand Down
11 changes: 8 additions & 3 deletions runtime/ppx_pyformat_runtime.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
external format_int : string -> int -> string = "caml_format_int"

external bytes_unsafe_blit_string :
string -> int -> bytes -> int -> int -> unit
= "caml_blit_string"
[@@noalloc]

let align_left c w s =
let len = String.length s in
if len >= w then
s
else
let b = Bytes.create w in
Bytes.unsafe_blit_string s 0 b 0 len;
bytes_unsafe_blit_string s 0 b 0 len;
Bytes.unsafe_fill b len (w - len) c;
Bytes.unsafe_to_string b

Expand All @@ -17,7 +22,7 @@ let align_right c w s =
else
let b = Bytes.create w and fill_len = w - len in
Bytes.unsafe_fill b 0 fill_len c;
Bytes.unsafe_blit_string s 0 b fill_len len;
bytes_unsafe_blit_string s 0 b fill_len len;
Bytes.unsafe_to_string b

let align_center c w s =
Expand All @@ -29,7 +34,7 @@ let align_center c w s =
let left_len = (w - len) / 2 in
let right_len = w - len - left_len in
Bytes.unsafe_fill b 0 left_len c;
Bytes.unsafe_blit_string s 0 b left_len len;
bytes_unsafe_blit_string s 0 b left_len len;
Bytes.unsafe_fill b (left_len + len) right_len c;
Bytes.unsafe_to_string b

Expand Down

0 comments on commit c3a6ef3

Please sign in to comment.