File: helpers.go

package info (click to toggle)
golang-github-sagikazarmark-locafero 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 176 kB
  • sloc: makefile: 2
file content (41 lines) | stat: -rw-r--r-- 928 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package locafero

import "fmt"

// NameWithExtensions creates a list of names from a base name and a list of extensions.
//
// TODO: find a better name for this function.
func NameWithExtensions(baseName string, extensions ...string) []string {
	var names []string

	if baseName == "" {
		return names
	}

	for _, ext := range extensions {
		if ext == "" {
			continue
		}

		names = append(names, fmt.Sprintf("%s.%s", baseName, ext))
	}

	return names
}

// NameWithOptionalExtensions creates a list of names from a base name and a list of extensions,
// plus it adds the base name (without any extensions) to the end of the list.
//
// TODO: find a better name for this function.
func NameWithOptionalExtensions(baseName string, extensions ...string) []string {
	var names []string

	if baseName == "" {
		return names
	}

	names = NameWithExtensions(baseName, extensions...)
	names = append(names, baseName)

	return names
}