|
|
@@ -29,7 +29,7 @@ import (
|
|
|
"gopkg.in/editorconfig/editorconfig-core-go.v1"
|
|
|
)
|
|
|
|
|
|
-// TODO: only initialize map once and save to a local variable to reduce copies.
|
|
|
+// NewFuncMap TODO: only initialize map once and save to a local variable to reduce copies.
|
|
|
func NewFuncMap() []template.FuncMap {
|
|
|
return []template.FuncMap{map[string]interface{}{
|
|
|
"GoVer": func() string {
|
|
|
@@ -120,10 +120,12 @@ func NewFuncMap() []template.FuncMap {
|
|
|
}}
|
|
|
}
|
|
|
|
|
|
+// Safe render raw as HTML
|
|
|
func Safe(raw string) template.HTML {
|
|
|
return template.HTML(raw)
|
|
|
}
|
|
|
|
|
|
+// Str2HTML render Markdown text to HTML
|
|
|
func Str2HTML(raw string) template.HTML {
|
|
|
return template.HTML(markup.Sanitize(raw))
|
|
|
}
|
|
|
@@ -133,6 +135,7 @@ func NewLine2br(raw string) string {
|
|
|
return strings.Replace(raw, "\n", "<br>", -1)
|
|
|
}
|
|
|
|
|
|
+// List traversings the list
|
|
|
func List(l *list.List) chan interface{} {
|
|
|
e := l.Front()
|
|
|
c := make(chan interface{})
|
|
|
@@ -146,10 +149,12 @@ func List(l *list.List) chan interface{} {
|
|
|
return c
|
|
|
}
|
|
|
|
|
|
+// Sha1 returns sha1 sum of string
|
|
|
func Sha1(str string) string {
|
|
|
return tool.SHA1(str)
|
|
|
}
|
|
|
|
|
|
+// ToUTF8WithErr converts content to UTF8 encoding
|
|
|
func ToUTF8WithErr(content []byte) (error, string) {
|
|
|
charsetLabel, err := tool.DetectEncoding(content)
|
|
|
if err != nil {
|
|
|
@@ -173,18 +178,18 @@ func ToUTF8WithErr(content []byte) (error, string) {
|
|
|
return err, result
|
|
|
}
|
|
|
|
|
|
-// FIXME: Unused function
|
|
|
+// ToUTF8 converts content to UTF8 encoding and ignore error
|
|
|
func ToUTF8(content string) string {
|
|
|
_, res := ToUTF8WithErr([]byte(content))
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-// Replaces all prefixes 'old' in 's' with 'new'.
|
|
|
+// ReplaceLeft replaces all prefixes 'old' in 's' with 'new'.
|
|
|
// FIXME: Unused function
|
|
|
func ReplaceLeft(s, old, new string) string {
|
|
|
- old_len, new_len, i, n := len(old), len(new), 0, 0
|
|
|
- for ; i < len(s) && strings.HasPrefix(s[i:], old); n += 1 {
|
|
|
- i += old_len
|
|
|
+ oldLen, newLen, i, n := len(old), len(new), 0, 0
|
|
|
+ for ; i < len(s) && strings.HasPrefix(s[i:], old); n++ {
|
|
|
+ i += oldLen
|
|
|
}
|
|
|
|
|
|
// simple optimization
|
|
|
@@ -193,12 +198,12 @@ func ReplaceLeft(s, old, new string) string {
|
|
|
}
|
|
|
|
|
|
// allocating space for the new string
|
|
|
- newLen := n*new_len + len(s[i:])
|
|
|
- replacement := make([]byte, newLen, newLen)
|
|
|
+ curLen := n*newLen + len(s[i:])
|
|
|
+ replacement := make([]byte, curLen, curLen)
|
|
|
|
|
|
j := 0
|
|
|
- for ; j < n*new_len; j += new_len {
|
|
|
- copy(replacement[j:j+new_len], new)
|
|
|
+ for ; j < n*newLen; j += newLen {
|
|
|
+ copy(replacement[j:j+newLen], new)
|
|
|
}
|
|
|
|
|
|
copy(replacement[j:], s[i:])
|
|
|
@@ -230,6 +235,7 @@ func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]stri
|
|
|
return fullMessage
|
|
|
}
|
|
|
|
|
|
+// Actioner describes an action
|
|
|
type Actioner interface {
|
|
|
GetOpType() int
|
|
|
GetActUserName() string
|
|
|
@@ -278,6 +284,7 @@ func ActionIcon(opType int) string {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ActionContent2Commits converts action content to push commits
|
|
|
func ActionContent2Commits(act Actioner) *models.PushCommits {
|
|
|
push := models.NewPushCommits()
|
|
|
if err := jsoniter.Unmarshal([]byte(act.GetContent()), push); err != nil {
|
|
|
@@ -287,10 +294,12 @@ func ActionContent2Commits(act Actioner) *models.PushCommits {
|
|
|
return push
|
|
|
}
|
|
|
|
|
|
+// EscapePound returns new replacer
|
|
|
func EscapePound(str string) string {
|
|
|
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
|
|
|
}
|
|
|
|
|
|
+// DiffTypeToStr returns diff type name
|
|
|
func DiffTypeToStr(diffType int) string {
|
|
|
diffTypes := map[int]string{
|
|
|
1: "add", 2: "modify", 3: "del", 4: "rename",
|
|
|
@@ -298,6 +307,7 @@ func DiffTypeToStr(diffType int) string {
|
|
|
return diffTypes[diffType]
|
|
|
}
|
|
|
|
|
|
+// DiffLineTypeToStr returns diff line type name
|
|
|
func DiffLineTypeToStr(diffType int) string {
|
|
|
switch diffType {
|
|
|
case 2:
|