github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/packages/packages.go (about) 1 // Copyright 2021 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Package packages contains utilities to deal with package names in a robust 6 // manner. This will be useful on ensuring our code being robust against 7 // package prefix changes. 8 package packages 9 10 import ( 11 "strings" 12 ) 13 14 // FrameworkPrefix is the newer common framework package prefix. 15 const FrameworkPrefix = "go.chromium.org/tast/core/" 16 17 // Normalize normalizes old framework package path to a newer corresponding one. 18 // Normalize return the unmodified string. 19 // TODO: b/187792551 -- Remove after issue is closed. 20 func Normalize(s string) string { 21 return s 22 } 23 24 // SplitFuncName splits runtime.Func.Name() into package and function name. 25 func SplitFuncName(fn string) (fullPkg, name string) { 26 lastSlash := strings.LastIndex(fn, "/") 27 lastPkgAndFunc := strings.SplitN(fn[lastSlash+1:], ".", 2) 28 return fn[0:lastSlash+1] + lastPkgAndFunc[0], lastPkgAndFunc[1] 29 } 30 31 // Same returns true if x and y are identical after normalization. 32 func Same(x, y string) bool { 33 return Normalize(x) == Normalize(y) 34 }