diff options
Diffstat (limited to 'rdfloader/parser2v2/utils.go')
-rw-r--r-- | rdfloader/parser2v2/utils.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/rdfloader/parser2v2/utils.go b/rdfloader/parser2v2/utils.go index 27207d2..9f51a3c 100644 --- a/rdfloader/parser2v2/utils.go +++ b/rdfloader/parser2v2/utils.go @@ -5,11 +5,12 @@ package parser2v2 import ( "errors" "fmt" + "strings" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" urilib "github.com/spdx/gordf/uri" - "github.com/spdx/tools-golang/spdx" - "strings" + "github.com/spdx/tools-golang/spdx/common" ) // a uri is of type baseURI#fragment or baseFragment/subFragment @@ -67,7 +68,7 @@ func boolFromString(boolString string) (bool, error) { // used to extract DocumentRef and SPDXRef values from an SPDX Identifier // which can point either to this document or to a different one -func ExtractDocElementID(value string) (spdx.DocElementID, error) { +func ExtractDocElementID(value string) (common.DocElementID, error) { docRefID := "" idStr := value @@ -77,16 +78,16 @@ func ExtractDocElementID(value string) (spdx.DocElementID, error) { strs := strings.Split(idStr, ":") // should be exactly two, part before and part after if len(strs) < 2 { - return spdx.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") + return common.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") } if len(strs) > 2 { - return spdx.DocElementID{}, fmt.Errorf("more than one colon found") + return common.DocElementID{}, fmt.Errorf("more than one colon found") } // trim the prefix and confirm non-empty docRefID = strings.TrimPrefix(strs[0], "DocumentRef-") if docRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") } // and use remainder for element ID parsing idStr = strs[1] @@ -94,48 +95,48 @@ func ExtractDocElementID(value string) (spdx.DocElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(idStr, "SPDXRef-") { - return spdx.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(idStr, ":") { // we know this means there was no DocumentRef- prefix, because // we would have handled multiple colons above if it was - return spdx.DocElementID{}, fmt.Errorf("invalid colon in element identifier") + return common.DocElementID{}, fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(idStr, "SPDXRef-") if eltRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.DocElementID{DocumentRefID: docRefID, ElementRefID: spdx.ElementID(eltRefID)}, nil + return common.DocElementID{DocumentRefID: docRefID, ElementRefID: common.ElementID(eltRefID)}, nil } // used to extract SPDXRef values only from an SPDX Identifier which can point // to this document only. Use extractDocElementID for parsing IDs that can // refer either to this document or a different one. -func ExtractElementID(value string) (spdx.ElementID, error) { +func ExtractElementID(value string) (common.ElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(value, "SPDXRef-") { - return spdx.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(value, ":") { - return spdx.ElementID(""), fmt.Errorf("invalid colon in element identifier") + return common.ElementID(""), fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(value, "SPDXRef-") if eltRefID == "" { - return spdx.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") + return common.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.ElementID(eltRefID), nil + return common.ElementID(eltRefID), nil } // used to extract key / value from embedded substrings |