spdx.regexes
Regex related functionality. This functionality is bespoke (it does not use any logic from Spdx-Java-Library
).
addition-ref-re
(addition-ref-re)
Returns a regex (Pattern
) that can find or match any SPDX AdditionRef
. The regex provides these named capturing groups:
AdditionDocumentRef
(optional) - captures theDocumentRef
tag of anAdditionRef
, if it contains oneAdditionRef
(always present) - captures theAdditionRef
tag of anAdditionRef
Notes:
- caches the generated
Pattern
object and returns it on subsequent calls, so is efficient when called many times
build-re
(build-re ids)
(build-re ids {:keys [case-sensitive? include-license-refs? include-addition-refs?], :or {case-sensitive? false, include-license-refs? false, include-addition-refs? false}, :as opts})
Returns a regex (Pattern
) that can find or match the given SPDX ids
(a sequence of String
s) in a source text. Returns nil
if ids
is nil
or empty.
The regex provides these named capturing groups:
Identifier
(always present) - captures the entire identifier,LicenseRef
orAdditionRef
DocumentRef
(optional) - captures theDocumentRef
tag of aLicenseRef
, if it contains oneLicenseRef
(optional) - captures theLicenseRef
tag of aLicenseRef
AdditionDocumentRef
(optional) - captures theDocumentRef
tag of anAdditionRef
, if it contains oneAdditionRef
(optional) - captures theAdditionRef
tag of anAdditionRef
Groups should not be accessed by index, as the groups in the returned regexes are not part of the public contract of this API, and are liable to change over time. You may choose to use something like rencg to ensure your code is future proof in this regard.
ids
will appear in the regex sorted from longest to shortest, so that more specific values are preferentially found or matched first - this avoids mismatches when one id is a subset of another id (e.g. GPL-2.0
and GPL-2.0-or-later
).
opts
are:
case-sensitive?
(boolean
, defaultfalse
) - controls whether SPDX identifier matching is case sensitive or not. The spec explicitly states that SPDX identifiers are not case sensitive, but there may be cases where case sensitive matching is preferred. Note that regardless of this setting, LicenseRefs and AdditionRefs are always matched case sensitively - this is required by the spec.include-license-refs?
(boolean
, defaultfalse
) - controls whetherLicenseRef
support is also included in the regexinclude-addition-refs?
(boolean
, defaultfalse
) - controls whetherAdditionRef
support is also included in the regex
exception-ids-re
(exception-ids-re)
Returns a regex (Pattern
) that can find or match any SPDX license exception identifier, or AdditionRef
in a source text.
Specifics of the regex are as for build-re.
Notes:
- caches the generated
Pattern
object and returns it on subsequent calls, so is efficient when called many times
ids-re
(ids-re)
Returns a regex (Pattern
) that can find or match any SPDX license identifier, SPDX exception identifier, LicenseRef
, or AdditionRef
in a source text.
Specifics of the regex are as for build-re.
Notes:
- caches the generated
Pattern
object and returns it on subsequent calls, so is efficient when called many times
init!
(init!)
Initialises this namespace upon first call (and does nothing on subsequent calls), returning nil
. Consumers of this namespace are not required to call this fn, as initialisation will occur implicitly anyway; it is provided to allow explicit control of the cost of initialisation to callers who need it.
Note: this method may have a substantial performance cost.
license-ids-re
(license-ids-re)
Returns a regex (Pattern
) that can find or match any SPDX license identifier, or LicenseRef
in a source text.
Specifics of the regex are as for build-re.
Notes:
- caches the generated
Pattern
object and returns it on subsequent calls, so is efficient when called many times
license-ref-re
(license-ref-re)
Returns a regex (Pattern
) that can find or match any SPDX LicenseRef
. The regex provides these named capturing groups:
DocumentRef
(optional) - captures theDocumentRef
tag of aLicenseRef
, if it contains oneLicenseRef
(always present) - captures theLicenseRef
tag of aLicenseRef
Notes:
- caches the generated
Pattern
object and returns it on subsequent calls, so is efficient when called many times