UAInspector v0.19.0 UAInspector.Util View Source

Utility methods.

Link to this section Summary

Functions

Upgrades a database regex into a detection regex

Replaces an empty string with :unknown

Sanitizes a model string

Sanitizes a name string

Sanitizes a version string

Converts an unknown version string to a semver-comparable format

Replaces PHP-Style regex captures with their values

Link to this section Functions

Link to this function

build_regex(regex) View Source
build_regex(regex :: String.t()) :: Regex.t()

Upgrades a database regex into a detection regex.

This prevents matching a string with other characters before the matching part.

Link to this function

maybe_unknown(data) View Source
maybe_unknown(data :: String.t()) :: :unknown | String.t()

Replaces an empty string with :unknown.

Link to this function

sanitize_model(model) View Source
sanitize_model(model :: String.t()) :: String.t()

Sanitizes a model string.

Link to this function

sanitize_name(name) View Source
sanitize_name(name :: String.t()) :: String.t()

Sanitizes a name string.

Link to this function

sanitize_version(version) View Source
sanitize_version(version :: String.t()) :: String.t()

Sanitizes a version string.

Link to this function

to_semver(version) View Source
to_semver(version :: String.t()) :: String.t()

Converts an unknown version string to a semver-comparable format.

Everything except the major and minor version is dropped as these two parts are the only available/needed.

Missing values are filled with zeroes while empty strings are ignored.

If a non-integer value is found it is ignored and every part including and after it will be a zero.

Examples

iex> to_semver("15")
"15.0.0"

iex> to_semver("3.6")
"3.6.0"

iex> to_semver("8.8.8")
"8.8.0"

iex> to_semver("")
""

iex> to_semver("invalid")
"0.0.0"

iex> to_semver("3.help")
"3.0.0"

iex> to_semver("0.1.invalid")
"0.1.0"
Link to this function

uncapture(data, captures) View Source
uncapture(data :: String.t(), captures :: list()) :: String.t()

Replaces PHP-Style regex captures with their values.