1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 2 3package saver2v1 4 5import ( 6 "fmt" 7 "io" 8 9 "github.com/spdx/tools-golang/spdx/common" 10 "github.com/spdx/tools-golang/spdx/v2_1" 11) 12 13func renderSnippet2_1(sn *v2_1.Snippet, w io.Writer) error { 14 if sn.SnippetSPDXIdentifier != "" { 15 fmt.Fprintf(w, "SnippetSPDXID: %s\n", common.RenderElementID(sn.SnippetSPDXIdentifier)) 16 } 17 snFromFileIDStr := common.RenderElementID(sn.SnippetFromFileSPDXIdentifier) 18 if snFromFileIDStr != "" { 19 fmt.Fprintf(w, "SnippetFromFileSPDXID: %s\n", snFromFileIDStr) 20 } 21 22 for _, snippetRange := range sn.Ranges { 23 if snippetRange.StartPointer.Offset != 0 && snippetRange.EndPointer.Offset != 0 { 24 fmt.Fprintf(w, "SnippetByteRange: %d:%d\n", snippetRange.StartPointer.Offset, snippetRange.EndPointer.Offset) 25 } 26 if snippetRange.StartPointer.LineNumber != 0 && snippetRange.EndPointer.LineNumber != 0 { 27 fmt.Fprintf(w, "SnippetLineRange: %d:%d\n", snippetRange.StartPointer.LineNumber, snippetRange.EndPointer.LineNumber) 28 } 29 } 30 if sn.SnippetLicenseConcluded != "" { 31 fmt.Fprintf(w, "SnippetLicenseConcluded: %s\n", sn.SnippetLicenseConcluded) 32 } 33 for _, s := range sn.LicenseInfoInSnippet { 34 fmt.Fprintf(w, "LicenseInfoInSnippet: %s\n", s) 35 } 36 if sn.SnippetLicenseComments != "" { 37 fmt.Fprintf(w, "SnippetLicenseComments: %s\n", textify(sn.SnippetLicenseComments)) 38 } 39 if sn.SnippetCopyrightText != "" { 40 fmt.Fprintf(w, "SnippetCopyrightText: %s\n", textify(sn.SnippetCopyrightText)) 41 } 42 if sn.SnippetComment != "" { 43 fmt.Fprintf(w, "SnippetComment: %s\n", textify(sn.SnippetComment)) 44 } 45 if sn.SnippetName != "" { 46 fmt.Fprintf(w, "SnippetName: %s\n", sn.SnippetName) 47 } 48 49 fmt.Fprintf(w, "\n") 50 51 return nil 52} 53