-
Notifications
You must be signed in to change notification settings - Fork 17
/
misc.go
41 lines (33 loc) · 861 Bytes
/
misc.go
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 main
import (
"regexp"
"strings"
"unicode/utf8"
)
var (
roleDefinitionIdRegExp = regexp.MustCompile("(?i)/subscriptions/[^/]+/providers/Microsoft.Authorization/roleDefinitions/([^/]*)")
)
func stringToStringLower(val string) string {
return strings.ToLower(val)
}
func extractRoleDefinitionIdFromAzureId(azureId string) (roleDefinitionId string) {
if subMatch := roleDefinitionIdRegExp.FindStringSubmatch(azureId); len(subMatch) >= 1 {
roleDefinitionId = strings.ToLower(subMatch[1])
}
return
}
func stringsTrimSuffixCI(str, suffix string) string {
if strings.HasSuffix(strings.ToLower(str), strings.ToLower(suffix)) {
str = str[0 : len(str)-len(suffix)]
}
return str
}
func truncateStrings(s string, n int, suffix string) string {
if len(s) <= n {
return s
}
for !utf8.ValidString(s[:n]) {
n--
}
return s[:n] + suffix
}