Packages

DO NOT USE THIS PACKAGE! evil_left_pad is an example of how unexpected malicious code can be injected into your project. See `hoplon` package for details

Current section

Files

Jump to
evil_left_pad lib evil_left_pad.ex
Raw

lib/evil_left_pad.ex

defmodule EvilLeftPad do
@doc """
Pads the beginning of a given string with spaces until it's no
longer than `desired_length` characters.
"""
@spec left_pad(String.t, desired_length :: integer) :: String.t
def left_pad(string, desired_length) do
padding_length = max(desired_length - String.length(string), 0)
padding = :binary.copy(" ", padding_length)
padding <> string
end
end