LazyStrings.jl

Lazy `AbstractString` transformations.
Author gkappler
Popularity
2 Stars
Updated Last
3 Years Ago
Started In
August 2021

LazyStrings

Dev Build Status Codecov

StringWrapper

Provides a lazy abstract type StringWrapper <: AbstractString end interface implementation, delegating AbstractString API methods

  • index boundaries and sizes: firstindex, lastindex, length, ncodeunits, sizeof
  • getting elements getindex, iterate, codeunit
  • codeunits and indices: isvalid, thisind, prevind, nextind
  • SubString LazyStrings.jl provides similar functionality for AbstractStrings as LazyArrays.jl for Vectors.

These sources have been reviewed for AbstractString interface methods.

Note:

The package is used in CombinedParsers.jl for lookbehind parsers and parsers on a lazyly transformed String (e.g. lowercase). ReversedStrings.jl was the deprecated and moved into this package.

Custom StringWrapper

All you need is provide a LazyStrings.representation method.

Lazy CharMappedString

julia> using LazyStrings

julia> using BenchmarkTools

julia> @btime lmap(lowercase,"JuliaCon")[1]
  6.706 ns (0 allocations: 0 bytes)
'j': ASCII/Unicode U+006A (category Ll: Letter, lowercase)

julia> @btime map(lowercase,"JuliaCon")[1]
  93.681 ns (3 allocations: 144 bytes)
'j': ASCII/Unicode U+006A (category Ll: Letter, lowercase)

Lazy ReversedString

A lazy reverse implementation

julia> using LazyStrings


julia> using BenchmarkTools

julia> @btime reverse("JuliaCon")
  28.694 ns (1 allocation: 32 bytes)
"noCailuJ"

julia> @btime reversed("JuliaCon")
  3.167 ns (0 allocations: 0 bytes)
"noCailuJ"

julia> @btime reverse(reverse("JuliaCon"))
  58.530 ns (2 allocations: 64 bytes)
"JuliaCon"

julia> @btime reversed(reversed("JuliaCon"))
  3.734 ns (0 allocations: 0 bytes)
"JuliaCon"

Required Packages

Used By Packages