UAInspector.Util

Utility methods.

Source

Summary

build_regex(regex)

Upgrades a database regex into a detection regex

maybe_unknown(data)

Replaces an empty string with :unknown

sanitize_model(model)

Sanitizes a model string

sanitize_name(name)

Sanitizes a name string

sanitize_version(version)

Sanitizes a version string

to_semver(version)

Converts an unknown version string to a semver-comparable format

uncapture(data, captures)

Replaces PHP-Style regex captures with their values

Functions

build_regex(regex)

Specs:

Upgrades a database regex into a detection regex.

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

Source
maybe_unknown(data)

Specs:

Replaces an empty string with :unknown.

Source
sanitize_model(model)

Specs:

Sanitizes a model string.

Source
sanitize_name(name)

Specs:

Sanitizes a name string.

Source
sanitize_version(version)

Specs:

Sanitizes a version string.

Source
to_semver(version)

Specs:

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"
Source
uncapture(data, captures)

Specs:

Replaces PHP-Style regex captures with their values.

Source