本文整理匯總了Golang中github.com/robfig/soy/data.Value.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.String方法的具體用法?Golang Value.String怎麽用?Golang Value.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robfig/soy/data.Value
的用法示例。
在下文中一共展示了Value.String方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: directiveInsertWordBreaks
func directiveInsertWordBreaks(value data.Value, args []data.Value) data.Value {
var (
input = template.HTMLEscapeString(value.String())
maxChars = int(args[0].(data.Int))
chars = 0
output *bytes.Buffer // create the buffer lazily
)
for i, ch := range input {
switch {
case ch == ' ':
chars = 0
case chars >= maxChars:
if output == nil {
output = bytes.NewBufferString(input[:i])
}
output.WriteString("<wbr>")
chars = 1
default:
chars++
}
if output != nil {
output.WriteRune(ch)
}
}
if output == nil {
return value
}
return data.String(output.String())
}
示例2: directiveTruncate
func directiveTruncate(value data.Value, args []data.Value) data.Value {
if !isInt(args[0]) {
panic(fmt.Errorf("First parameter of '|truncate' is not an integer: %v", args[0]))
}
var maxLen = int(args[0].(data.Int))
var str = value.String()
if len(str) <= maxLen {
return value
}
var ellipsis = data.Bool(true)
if len(args) == 2 {
var ok bool
ellipsis, ok = args[1].(data.Bool)
if !ok {
panic(fmt.Errorf("Second parameter of '|truncate' is not a bool: %v", args[1]))
}
}
if ellipsis {
if maxLen > 3 {
maxLen -= 3
} else {
ellipsis = false
}
}
for !utf8.RuneStart(str[maxLen]) {
maxLen--
}
str = str[:maxLen]
if ellipsis {
str += "..."
}
return data.String(str)
}
示例3: directiveChangeNewlineToBr
func directiveChangeNewlineToBr(value data.Value, _ []data.Value) data.Value {
return data.String(newlinePattern.ReplaceAllString(
template.HTMLEscapeString(value.String()),
"<br>"))
}
示例4: directiveEscapeJsString
func directiveEscapeJsString(value data.Value, _ []data.Value) data.Value {
return data.String(template.JSEscapeString(value.String()))
}
示例5: directiveEscapeUri
func directiveEscapeUri(value data.Value, _ []data.Value) data.Value {
return data.String(url.QueryEscape(value.String()))
}
示例6: directiveEscapeHtml
func directiveEscapeHtml(value data.Value, _ []data.Value) data.Value {
return data.String(template.HTMLEscapeString(value.String()))
}