Cased.Sensitive.String (cased v1.0.0)

Used to mask sensitive string values.

Link to this section Summary

Functions

Check two sensitive strings for equality.

Extract all {begin_offset, end_offset} values for matches of a given regular expression.

Link to this section Types

Specs

new_opt() :: {:label, String.t() | atom()}

Specs

new_opts() :: [new_opt()]

Specs

t() :: %Cased.Sensitive.String{
  data: String.t(),
  label: nil | atom() | String.t()
}

Link to this section Functions

Link to this function

equal?(string1, string2)

Specs

equal?(string1 :: t(), string2 :: t()) :: boolean()

Check two sensitive strings for equality.

Examples

Two strings with the same data and label are equivalent:

iex> string1 = Cased.Sensitive.String.new("text", label: "username")
iex> string2 = Cased.Sensitive.String.new("text", label: "username")
iex> Cased.Sensitive.String.equal?(string1, string2)
true

If the contents are different, two sensitive strings are not equal:

iex> string1 = Cased.Sensitive.String.new("text", label: "username")
iex> string2 = Cased.Sensitive.String.new("txet", label: "username")
iex> Cased.Sensitive.String.equal?(string1, string2)
false

If the labels are different, two sensitive strings are not equal:

iex> string1 = Cased.Sensitive.String.new("text", label: "username")
iex> string2 = Cased.Sensitive.String.new("text", label: "email")
iex> Cased.Sensitive.String.equal?(string1, string2)
false
Link to this function

matches(string, regex)

Specs

matches(string :: t(), regex :: Regex.t()) :: [
  {non_neg_integer(), non_neg_integer()}
]

Extract all {begin_offset, end_offset} values for matches of a given regular expression.

Examples

Cased.Sensitive.String.new("Hello @username and @username")
|> Cased.Sensitive.String.matches(~r/@w+/)
# => [{6, 15}, {20, 29}]
Link to this function

new(raw_string, opts \\ [])

Specs

new(raw_string :: String.t(), opts :: new_opts()) :: t()

Create a new Cased.Sensitive.String struct.

Example

Cased.Sensitive.String.new("john@example.com", label: :email)
Link to this function

to_range(string, key)

Specs

to_range(string :: t(), key :: String.t()) :: Cased.Sensitive.Range.t()