-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.go
More file actions
50 lines (42 loc) · 1.27 KB
/
Copy pathhelpers.go
File metadata and controls
50 lines (42 loc) · 1.27 KB
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
42
43
44
45
46
47
48
49
50
package main
import (
"strings"
"fmt"
)
// MIGRATE THIS TO stringutil eventually
// Given a string, generate a snake case string, if we have URLFriendly enabled then we add _ to make a URI string
func TitleCase(name string, urlFriendly bool) string {
uriParts := strings.Split(name, " ")
LogInDebugMode("STRING PARTS ARE: ", uriParts)
uriString := ""
for _, part := range uriParts {
compare := strings.ToLower(part)
if(compare == "the" || compare == "of" || compare == "or" || compare == "and" || compare == "a" || compare == "an" || compare == "on" || compare == "to") {
part = strings.ToLower(part)
} else {
part = strings.Title(part)
}
if urlFriendly {
uriString += part + "_"
} else {
uriString += part + " "
}
}
uriString = strings.Replace(uriString, "'S", "'s", -1)
uriString = strings.Replace(uriString, "`S", "`s", -1)
uriString = uriString[0:len(uriString)-1]
return uriString
}
func ReplaceMultiple(src string, replaceWith string, matchWith ...string) string {
out := src
for _, word := range matchWith {
out = strings.Replace(out, word, replaceWith, -1)
}
return out
}
// Replaces fmt.Println and is used for logging debug messages
func LogInDebugMode(message string, args ...interface{}) {
if DEBUG {
fmt.Println(message, args)
}
}