-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil.go
44 lines (36 loc) · 857 Bytes
/
util.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
42
43
44
// Copyright 2016 Muhammad Shulhan <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
package gonduit
import (
"fmt"
"strings"
"unicode"
)
//
// ConvertToTags will convert list of string to Phabricator tag format, which is
// by replacing non alphanumeric characters with underscores.
//
func ConvertToTags(list []string) (tags []string) {
sz := len(list)
if list == nil || sz == 0 {
return
}
tags = make([]string, sz)
for x, s := range list {
tmp := make([]rune, len(s))
for y, r := range strings.ToLower(s) {
if unicode.IsLetter(r) || unicode.IsNumber(r) ||
r == '_' {
tmp[y] = r
} else {
tmp[y] = '_'
}
}
tags[x] = string(tmp)
}
if DEBUG >= 2 {
fmt.Printf("[gonduit] ConvertToTags >> %v\n", tags)
}
return
}