Package org.spdx.utility.compare
Class TemplateRegexMatcher
java.lang.Object
org.spdx.utility.compare.TemplateRegexMatcher
- All Implemented Interfaces:
ILicenseTemplateOutputHandler
Constructs a regular expression from a license or exception template and provide a matching method
to see if code matching the template exists within the text provided
Note that the regular expression assumes a fully normalized text string to match
isTemplateMatchWithinText(String text) will return true if the text text matches the template
getQuickMatchRegex() will return a regular expression with limited backtracking which can be used for a quick search
getCompleteRegex() will return a regular expression for the entire license where
getStartRegex(int wordLimit) will return a regular expression to match the beginning of a license
and getEndRegex(int wordLimit) will return a regular expression to match the end of a license- Author:
- Gary O'Neall
-
Constructor Summary
ConstructorsConstructorDescriptionTemplateRegexMatcher(String template) Generates regular expressions from a license or exception template -
Method Summary
Modifier and TypeMethodDescriptionvoidBegin optional rule foundvoidSignals all text has been added and parsing can be completed.voidEnd optional rule foundgetEndRegex(int wordLimit) getQuickMatchRegex(int wordLimit) getStartRegex(int wordLimit) booleanvoidText for processingvoidVariable rule found within the template
-
Constructor Details
-
TemplateRegexMatcher
Generates regular expressions from a license or exception template- Throws:
SpdxCompareException
-
-
Method Details
-
getCompleteRegex
- Returns:
- the complete regular expression for the template
-
getQuickMatchRegex
- Parameters:
wordLimit- maximum number of contiguous words to match- Returns:
- a regular expression to match the template with minimum backtracking - avoiding optional and var tags
-
getStartRegex
- Parameters:
wordLimit- number of non optional words to include in the pattern- Returns:
- a regex to match the start of the license per the template
-
getEndRegex
- Parameters:
wordLimit- number of non optional words to include in the pattern- Returns:
- a regex to match the end of the license per the template
-
isTemplateMatchWithinText
public boolean isTemplateMatchWithinText(String text) throws SpdxCompareException, InvalidSPDXAnalysisException - Parameters:
text- text to search for a match- Returns:
- true if a match is found, otherwise false
- Throws:
SpdxCompareExceptionInvalidSPDXAnalysisException
-
text
Description copied from interface:ILicenseTemplateOutputHandlerText for processing- Specified by:
textin interfaceILicenseTemplateOutputHandler
-
variableRule
Description copied from interface:ILicenseTemplateOutputHandlerVariable rule found within the template- Specified by:
variableRulein interfaceILicenseTemplateOutputHandler
-
beginOptional
Description copied from interface:ILicenseTemplateOutputHandlerBegin optional rule found- Specified by:
beginOptionalin interfaceILicenseTemplateOutputHandler
-
endOptional
Description copied from interface:ILicenseTemplateOutputHandlerEnd optional rule found- Specified by:
endOptionalin interfaceILicenseTemplateOutputHandler
-
completeParsing
Description copied from interface:ILicenseTemplateOutputHandlerSignals all text has been added and parsing can be completed.- Specified by:
completeParsingin interfaceILicenseTemplateOutputHandler- Throws:
LicenseParserException
-