Browse Source

Merge pull request 'fix-truncate' (#82) from fix-truncate into develop

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/82
Reviewed-by: colorfulberry <senluowanxiangt@gmail.com>
pull/83/head
colorfulberry 4 years ago
parent
commit
88ec64270a
2 changed files with 7 additions and 6 deletions
  1. +1
    -1
      modules/auth/cloudbrain.go
  2. +6
    -5
      modules/base/tool.go

+ 1
- 1
modules/auth/cloudbrain.go View File

@@ -12,7 +12,7 @@ type CreateCloudBrainForm struct {
Attachment string `form:"attachment" binding:"Required"`
JobType string `form:"job_type" binding:"Required"`
BenchmarkCategory string `form:"get_benchmark_category"`
GpuType string `form:"gpu_type"`
GpuType string `form:"gpu_type"`
}

type CommitImageCloudBrainForm struct {


+ 6
- 5
modules/base/tool.go View File

@@ -21,6 +21,7 @@ import (
"strings"
"time"
"unicode"
"unicode/utf8"

"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -284,22 +285,22 @@ func Subtract(left interface{}, right interface{}) interface{} {
// EllipsisString returns a truncated short string,
// it appends '...' in the end of the length of string is too large.
func EllipsisString(str string, length int) string {
if length <= 3 {
if utf8.RuneCountInString(str) <= 3 {
return "..."
}
if len(str) <= length {
if utf8.RuneCountInString(str) <= length {
return str
}
return str[:length-3] + "..."
return string([]rune(str)[:length-3]) + "..."
}

// TruncateString returns a truncated string with given limit,
// it returns input string if length is not reached limit.
func TruncateString(str string, limit int) string {
if len(str) < limit {
if utf8.RuneCountInString(str) < limit {
return str
}
return str[:limit]
return string([]rune(str)[:limit])
}

// StringsToInt64s converts a slice of string to a slice of int64.


Loading…
Cancel
Save