From 64dbccf9c683c8d1c705a3707362e538fcde0872 Mon Sep 17 00:00:00 2001 From: Daniel Phillips Date: Tue, 5 Mar 2024 15:47:14 -0600 Subject: [PATCH] Replaced merge-removed Parse function --- utils.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/utils.go b/utils.go index 04622dff..0f590df0 100644 --- a/utils.go +++ b/utils.go @@ -16,6 +16,32 @@ package scale +import "strings" + +type Parsed struct { + Organization string + Name string + Tag string +} + +// Parse parses a function or signature name of the form /: into its organization, name, and tag +func Parse(name string) *Parsed { + orgSplit := strings.Split(name, "/") + if len(orgSplit) == 1 { + orgSplit = []string{"", name} + } + tagSplit := strings.Split(orgSplit[1], ":") + if len(tagSplit) == 1 { + tagSplit = []string{tagSplit[0], ""} + } + return &Parsed{ + Organization: orgSplit[0], + Name: tagSplit[0], + Tag: tagSplit[1], + } +} + func unpackUint32(packed uint64) (uint32, uint32) { return uint32(packed >> 32), uint32(packed) } +