View Source MetaLogger.Slicer.Utf8Impl (MetaLogger v1.9.1)

Slices a string into chunks of a given length, taking into account the UTF-8 encoding of the string.

Summary

Functions

Returns sliced log entries according to the given max entry length.

Functions

Link to this function

slice(entry, max_entry_length)

View Source

Returns sliced log entries according to the given max entry length.

Ensures that all slices are valid UTF-8 strings by not splitting multibyte characters. If the entry is smaller than the given max length, or if :infinity is given as an option, a list with one entry is returned. Otherwise, a list with multiple entries is returned.

Examples

iex> MetaLogger.Slicer.Utf8Impl.slice("1234567890", 10)
["1234567890"]

iex> MetaLogger.Slicer.Utf8Impl.slice("1234567890", :infinity)
["1234567890"]

iex> MetaLogger.Slicer.Utf8Impl.slice("1234567890", 5)
["12345", "67890"]

iex> MetaLogger.Slicer.Utf8Impl.slice("Hello 世界", 7)
["Hello ", "世界"]