Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for padding and char replication #14

Merged
merged 3 commits into from
Sep 11, 2023

Commits on Sep 10, 2023

  1. Add support for padding and char replication

    - Add `Char` replication functions `prependChars` and `appendChars`
    - Add padding functions `justifyLeft`, `justifyRight` and `center`.
    - Move low-level `MArray` manipulation to their own module
      `Data.Text.Builder.Linear.Array`.
    - Add corresponding tests and benchmarks.
    wismill committed Sep 10, 2023
    Configuration menu
    Copy the full SHA
    ea52747 View commit details
    Browse the repository at this point in the history
  2. Add newEmptyBuffer

    Some situations may require a fresh empty buffer. For example, if one
    want to define a function that append padded hexadecimal numbers, the
    use of a mere `justifyRight` requires the input `Buffer` to be empty.
    
    We introduce `newEmptyBuffer` to solve this issue. It has the caveat to
    require an existing `Buffer`, because we need to to know if the array is
    pinned or not.
    
    Working example for padded hexadecimal numbers:
    
        -- | Convenient function to append padded hex
        infixl 6 |>&&
        (|>&&) ∷ (Integral a, FiniteBits a) ⇒ Buffer ⊸ (Word, a) → Buffer
        b |>&& (w, n) = case newEmptyBuffer b of
        (# b', empty #) → (b' |># "0x"#) >< justifyRight w '0' (empty |>& n)
    
        -- Example
        runBuffer \b → (b |># "Foo "#) |>&& (4, 0xf ∷ Word) |># "; "# |>&& (4, 0xabc ∷ Word)
        -- "Foo 0x000f; 0x0abc"
    wismill committed Sep 10, 2023
    Configuration menu
    Copy the full SHA
    2c4bb34 View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2023

  1. Review fixes

    wismill committed Sep 11, 2023
    Configuration menu
    Copy the full SHA
    9c3f237 View commit details
    Browse the repository at this point in the history