Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/main/java/org/spdx/utility/compare/TemplateRegexMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ public boolean isTemplateMatchWithinText(String text) throws SpdxCompareExceptio
}
}

/**
* Normalizes text for use in the template matcher
* @param text text to normalize
* @return text that is normalized for license comparison
*/
public String normalizeText(String text) {
StringBuilder normalizedText = new StringBuilder();

for (String token:LicenseTextHelper.tokenizeLicenseText(LicenseTextHelper.removeLineSeparators(
LicenseCompareHelper.removeCommentChars(text)), new HashMap<>())) {
normalizedText.append(
LicenseTextHelper.NORMALIZE_TOKENS.getOrDefault(token.toLowerCase(), token.toLowerCase()));
normalizedText.append(' ');
}
return normalizedText.toString();
}

/**
* @param text text to search for
* @return the text matching the beginning and end regular expressions for the template. Null if there is no match.
Expand All @@ -298,17 +315,8 @@ public boolean isTemplateMatchWithinText(String text) throws SpdxCompareExceptio
if (text == null || text.isEmpty() || template == null) {
return null;
}

StringBuilder normalizedText = new StringBuilder();

for (String token:LicenseTextHelper.tokenizeLicenseText(LicenseTextHelper.removeLineSeparators(
LicenseCompareHelper.removeCommentChars(text)), new HashMap<>())) {
normalizedText.append(
LicenseTextHelper.NORMALIZE_TOKENS.getOrDefault(token.toLowerCase(), token.toLowerCase()));
normalizedText.append(' ');
}

String compareText = normalizedText.toString();

String compareText = normalizeText(text);

Pattern quickPattern = Pattern.compile(getQuickMatchRegex(WORD_LIMIT));
if (quickPattern.matcher(compareText).find()) {
Expand Down