UAInspector.Util
Utility methods.
Summary↑
build_regex(regex) | Upgrades a database regex into a detection regex |
maybe_unknown(data) | Replaces an empty string with |
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
Specs:
Upgrades a database regex into a detection regex.
This prevents matching a string with other characters before the matching part.
Specs:
Replaces an empty string with :unknown
.
Specs:
Sanitizes a model string.
Specs:
Sanitizes a name string.
Specs:
Sanitizes a version string.
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"
Specs:
Replaces PHP-Style regex captures with their values.