Skip to content

Commit

Permalink
extract only the actual SPDX ID from scanline it was found at
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Rutkowski <mrutkows@us.ibm.com>
  • Loading branch information
mrutkows committed Jun 13, 2024
1 parent c4dcd88 commit 7bb08d1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions identifier/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ func IdentifyLicensesInFile(filePath string, options Options, licenseLibrary *li
const SPDX_ID_KEY = "SPDX-License-Identifier:"

var LEN_SPDX_ID_KEY = len(SPDX_ID_KEY)
var SPDX_ID_KEY_BYTES = []byte(SPDX_ID_KEY)

//var SPDX_ID_KEY_BYTES = []byte(SPDX_ID_KEY)

func findSPDXIdentifierInFile(filePath string, maxLines int) (licenseMatches []licenseMatch, err error) {
var file *os.File
Expand All @@ -208,9 +209,14 @@ func findSPDXIdentifierInFile(filePath string, maxLines int) (licenseMatches []l
}
if foundLine != "" {
idx := strings.Index(foundLine, SPDX_ID_KEY)
// find start index of where the actual SPDX ID is by
// adding in the length of the SPDX License Identifier key
// Then trim any whitespace to extract the actual SPDX ID value
idx += LEN_SPDX_ID_KEY
spdxIdPlus := foundLine[idx:]
//fmt.Printf("line (%v): `%s`; id: `%s`\n", idx, foundLine, spdxIdPlus)
var match licenseMatch
match.LicenseId = spdxIdPlus
match.LicenseId = strings.TrimSpace(spdxIdPlus)
licenseMatches = append(licenseMatches, match)
}
return
Expand Down

0 comments on commit 7bb08d1

Please sign in to comment.