3131import org .spdx .licenseTemplate .LicenseParserException ;
3232import org .spdx .licenseTemplate .LicenseTemplateRule ;
3333import org .spdx .licenseTemplate .LicenseTemplateRule .RuleType ;
34+ import org .spdx .licenseTemplate .LicenseTextHelper ;
35+ import org .spdx .licenseTemplate .LineColumn ;
3436
3537/**
3638 * Compares the output of a parsed license template to text. The method matches is called after
@@ -210,14 +212,14 @@ public int match(String[] matchTokens, int startToken, int endToken, String orig
210212 if (this .rule == null ) {
211213 if (this .text != null ) {
212214 Map <Integer , LineColumn > textLocations = new HashMap <Integer , LineColumn >();
213- String [] textTokens = LicenseCompareHelper .tokenizeLicenseText (text , textLocations );
215+ String [] textTokens = LicenseTextHelper .tokenizeLicenseText (text , textLocations );
214216 if (this .skipFirstTextToken ) {
215217 textTokens = Arrays .copyOfRange (textTokens , 1 , textTokens .length );
216218 }
217219 nextToken = compareText (textTokens , matchTokens , nextToken , endToken , this );
218220 if (nextToken < 0 ) {
219221 int errorLocation = -nextToken ;
220- differences .addDifference (tokenToLocation .get (errorLocation ), LicenseCompareHelper .getTokenAt (matchTokens , errorLocation ),
222+ differences .addDifference (tokenToLocation .get (errorLocation ), LicenseTextHelper .getTokenAt (matchTokens , errorLocation ),
221223 "Normal text of license does not match" , text , null , getLastOptionalDifference ());
222224 }
223225 if (this .subInstructions .size () > 0 ) {
@@ -376,7 +378,7 @@ private List<Integer> findNextNonVarTextStartTokens(ParseInstruction afterChild,
376378 }
377379
378380 Map <Integer , LineColumn > normalTextLocations = new HashMap <Integer , LineColumn >();
379- String [] textTokens = LicenseCompareHelper .tokenizeLicenseText (subInstructions .get (firstNormalTextIndex ).getText (), normalTextLocations );
381+ String [] textTokens = LicenseTextHelper .tokenizeLicenseText (subInstructions .get (firstNormalTextIndex ).getText (), normalTextLocations );
380382 if (textTokens .length > MAX_NEXT_NORMAL_TEXT_SEARCH_LENGTH ) {
381383 textTokens = Arrays .copyOf (textTokens , MAX_NEXT_NORMAL_TEXT_SEARCH_LENGTH );
382384 }
@@ -442,7 +444,7 @@ private int numTokensMatched(String text, int end) {
442444 }
443445 Map <Integer , LineColumn > temp = new HashMap <Integer , LineColumn >();
444446 String subText = text .substring (0 , end );
445- String [] tokenizedString = LicenseCompareHelper .tokenizeLicenseText (subText , temp );
447+ String [] tokenizedString = LicenseTextHelper .tokenizeLicenseText (subText , temp );
446448 return tokenizedString .length ;
447449 }
448450
@@ -475,7 +477,7 @@ private int matchVariable(List<Integer> matchingStartTokens, String[] matchToken
475477 }
476478 }
477479 // if we got here, there was no match found
478- differences .addDifference (tokenToLocation .get (startToken ), LicenseCompareHelper .getTokenAt (matchTokens , startToken ), "Variable text rule " +rule .getName ()+" did not match the compare text" ,
480+ differences .addDifference (tokenToLocation .get (startToken ), LicenseTextHelper .getTokenAt (matchTokens , startToken ), "Variable text rule " +rule .getName ()+" did not match the compare text" ,
479481 null , rule , getLastOptionalDifference ());
480482 return -1 ;
481483 }
@@ -567,7 +569,7 @@ public String[] getNextOptionalTextTokens() {
567569 }
568570 }
569571 Map <Integer , LineColumn > temp = new HashMap <>();
570- return LicenseCompareHelper .tokenizeLicenseText (sb .toString (), temp );
572+ return LicenseTextHelper .tokenizeLicenseText (sb .toString (), temp );
571573 }
572574 }
573575
@@ -746,9 +748,9 @@ public void addDifference(LineColumn location, String token, String msg, String
746748 * @throws IOException This is not to be expected since we are using StringReaders
747749 */
748750 public CompareTemplateOutputHandler (String compareText ) throws IOException {
749- this .compareText = LicenseCompareHelper .normalizeText (
750- LicenseCompareHelper .replaceMultWord (LicenseCompareHelper .replaceSpaceComma (compareText )));
751- this .compareTokens = LicenseCompareHelper .tokenizeLicenseText (this .compareText , tokenToLocation );
751+ this .compareText = LicenseTextHelper .normalizeText (
752+ LicenseTextHelper .replaceMultWord (LicenseTextHelper .replaceSpaceComma (compareText )));
753+ this .compareTokens = LicenseTextHelper .tokenizeLicenseText (this .compareText , tokenToLocation );
752754 }
753755
754756 /**
@@ -765,37 +767,37 @@ private int compareText(String[] textTokens, String[] matchTokens, int startToke
765767 return startToken ;
766768 }
767769 int textTokenCounter = 0 ;
768- String nextTextToken = LicenseCompareHelper .getTokenAt (textTokens , textTokenCounter ++);
770+ String nextTextToken = LicenseTextHelper .getTokenAt (textTokens , textTokenCounter ++);
769771 int matchTokenCounter = startToken ;
770- String nextMatchToken = LicenseCompareHelper .getTokenAt (matchTokens , matchTokenCounter ++);
772+ String nextMatchToken = LicenseTextHelper .getTokenAt (matchTokens , matchTokenCounter ++);
771773 while (nextTextToken != null ) {
772774 if (nextMatchToken == null ) {
773775 // end of compare text stream
774- while (nextTextToken != null && LicenseCompareHelper .canSkip (nextTextToken )) {
775- nextTextToken = LicenseCompareHelper .getTokenAt (textTokens , textTokenCounter ++);
776+ while (nextTextToken != null && LicenseTextHelper .canSkip (nextTextToken )) {
777+ nextTextToken = LicenseTextHelper .getTokenAt (textTokens , textTokenCounter ++);
776778 }
777779 if (nextTextToken != null ) {
778780 return -matchTokenCounter ; // there is more stuff in the compare license text, so not equiv.
779781 }
780- } else if (LicenseCompareHelper .tokensEquivalent (nextTextToken , nextMatchToken )) {
782+ } else if (LicenseTextHelper .tokensEquivalent (nextTextToken , nextMatchToken )) {
781783 // just move onto the next set of tokens
782- nextTextToken = LicenseCompareHelper .getTokenAt (textTokens , textTokenCounter ++);
784+ nextTextToken = LicenseTextHelper .getTokenAt (textTokens , textTokenCounter ++);
783785 if (nextTextToken != null ) {
784- nextMatchToken = LicenseCompareHelper .getTokenAt (matchTokens , matchTokenCounter ++);
786+ nextMatchToken = LicenseTextHelper .getTokenAt (matchTokens , matchTokenCounter ++);
785787 }
786788 } else {
787789 // see if we can skip through some compare tokens to find a match
788- while (nextMatchToken != null && LicenseCompareHelper .canSkip (nextMatchToken )) {
789- nextMatchToken = LicenseCompareHelper .getTokenAt (matchTokens , matchTokenCounter ++);
790+ while (nextMatchToken != null && LicenseTextHelper .canSkip (nextMatchToken )) {
791+ nextMatchToken = LicenseTextHelper .getTokenAt (matchTokens , matchTokenCounter ++);
790792 }
791793 // just to be sure, skip forward on the text
792- while (nextTextToken != null && LicenseCompareHelper .canSkip (nextTextToken )) {
793- nextTextToken = LicenseCompareHelper .getTokenAt (textTokens , textTokenCounter ++);
794+ while (nextTextToken != null && LicenseTextHelper .canSkip (nextTextToken )) {
795+ nextTextToken = LicenseTextHelper .getTokenAt (textTokens , textTokenCounter ++);
794796 }
795- if (LicenseCompareHelper .tokensEquivalent (nextMatchToken , nextTextToken )) {
796- nextTextToken = LicenseCompareHelper .getTokenAt (textTokens , textTokenCounter ++);
797+ if (LicenseTextHelper .tokensEquivalent (nextMatchToken , nextTextToken )) {
798+ nextTextToken = LicenseTextHelper .getTokenAt (textTokens , textTokenCounter ++);
797799 if (nextTextToken != null ) {
798- nextMatchToken = LicenseCompareHelper .getTokenAt (compareTokens , matchTokenCounter ++);
800+ nextMatchToken = LicenseTextHelper .getTokenAt (compareTokens , matchTokenCounter ++);
799801 }
800802 } else {
801803 if (textTokenCounter == textTokens .length &&
@@ -806,7 +808,7 @@ private int compareText(String[] textTokens, String[] matchTokens, int startToke
806808 //less than a token at the end of a compare
807809 //Yes - this is a bit of a hack
808810 String compareToken = nextTextToken + instruction .getNextOptionalTextTokens ()[0 ];
809- if (LicenseCompareHelper .tokensEquivalent (compareToken , nextMatchToken )) {
811+ if (LicenseTextHelper .tokensEquivalent (compareToken , nextMatchToken )) {
810812 instruction .skipNextInstruction ();
811813 return matchTokenCounter ;
812814 } else {
@@ -815,8 +817,8 @@ private int compareText(String[] textTokens, String[] matchTokens, int startToke
815817 if (nextNormalText != null ) {
816818 compareToken = compareToken + nextNormalText ;
817819 String compareWithoutOptional = nextTextToken + nextNormalText ;
818- if (LicenseCompareHelper .tokensEquivalent (compareToken , nextMatchToken ) ||
819- LicenseCompareHelper .tokensEquivalent (compareWithoutOptional , nextMatchToken )) {
820+ if (LicenseTextHelper .tokensEquivalent (compareToken , nextMatchToken ) ||
821+ LicenseTextHelper .tokensEquivalent (compareWithoutOptional , nextMatchToken )) {
820822 instruction .skipNextInstruction ();
821823 nextNormal .setSkipFirstToken (true );
822824 return matchTokenCounter ;
@@ -910,7 +912,7 @@ public void completeParsing() throws LicenseParserException {
910912 int nextTokenIndex = this .topLevelInstruction .match (compareTokens , 0 , compareTokens .length -1 , compareText , differences , tokenToLocation );
911913 if (nextTokenIndex > 0 && nextTokenIndex < compareTokens .length ) {
912914 this .differences .addDifference (tokenToLocation .get (nextTokenIndex ),
913- LicenseCompareHelper .getTokenAt (compareTokens , nextTokenIndex ),
915+ LicenseTextHelper .getTokenAt (compareTokens , nextTokenIndex ),
914916 "Additional text found after the end of the expected license text" , null , null , null );
915917 }
916918 parsingComplete = true ;
@@ -924,7 +926,7 @@ public void completeParsing() throws LicenseParserException {
924926 */
925927 public int textEquivalent (String text , int startToken ) {
926928 Map <Integer , LineColumn > textLocations = new HashMap <Integer , LineColumn >();
927- String [] textTokens = LicenseCompareHelper .tokenizeLicenseText (text , textLocations );
929+ String [] textTokens = LicenseTextHelper .tokenizeLicenseText (text , textLocations );
928930 return this .compareText (textTokens , this .compareTokens , startToken , this .compareTokens .length -1 , null );
929931 }
930932}
0 commit comments