本文整理汇总了Golang中strings.TrimRightFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang TrimRightFunc函数的具体用法?Golang TrimRightFunc怎么用?Golang TrimRightFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TrimRightFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Indexes
func (conn *Connection) Indexes() (indexes []*Index, err error) {
const sql = `SELECT RDB$INDICES.RDB$RELATION_NAME, RDB$INDICES.RDB$INDEX_NAME, RDB$INDICES.RDB$UNIQUE_FLAG, RDB$INDICES.RDB$INDEX_TYPE
FROM RDB$INDICES
JOIN RDB$RELATIONS ON RDB$INDICES.RDB$RELATION_NAME = RDB$RELATIONS.RDB$RELATION_NAME
WHERE (RDB$RELATIONS.RDB$SYSTEM_FLAG <> 1 OR RDB$RELATIONS.RDB$SYSTEM_FLAG IS NULL);`
var cursor *Cursor
if cursor, err = conn.Execute(sql); err != nil {
return
}
defer cursor.Close()
for cursor.Next() {
var index Index
if err = cursor.Scan(&index.TableName, &index.Name, &index.Unique, &index.Unique); err != nil {
return
}
index.Name = strings.TrimRightFunc(index.Name, unicode.IsSpace)
index.TableName = strings.TrimRightFunc(index.TableName, unicode.IsSpace)
if index.Columns, err = conn.IndexColumns(index.Name); err != nil {
return
}
if conn.database.LowercaseNames && !hasLowercase(index.Name) {
index.Name = strings.ToLower(index.Name)
}
if conn.database.LowercaseNames && !hasLowercase(index.TableName) {
index.TableName = strings.ToLower(index.TableName)
}
indexes = append(indexes, &index)
}
if cursor.Err() != io.EOF {
err = cursor.Err()
}
return
}
示例2: daemonIpcHandleConn
func daemonIpcHandleConn(conn *net.UnixConn) {
defer cluegetterRecover("daemonIpcHandleConn")
defer conn.Close()
for {
message, err := bufio.NewReader(conn).ReadString('\x00')
if err != nil {
if message != "" {
Log.Info("Got %s on IPC Socket. Ignoring.", err.Error())
}
return
}
kv := strings.SplitN(message, " ", 2)
handle := strings.TrimRightFunc(kv[0], func(v rune) bool { return v == '\x00' })
callback := ipcHandlers[handle]
v := ""
if len(kv) > 1 {
v = strings.TrimRightFunc(kv[1], func(v rune) bool { return v == '\x00' })
}
if callback == nil {
Log.Debug("Received IPC message but no such pattern was registered, ignoring: <%s>%s", handle, v)
return
}
callback(v)
}
}
示例3: compareVersions
// a < b = -1
// a == b = 0
// a > b = 1
func compareVersions(a, b string) int {
if a == b {
return 0
}
aParts := strings.Split(a, ".")
bParts := strings.Split(b, ".")
for i, verA := range aParts {
if len(bParts) <= i {
return 1
}
verB := bParts[i]
aInt, err := strconv.Atoi(strings.TrimRightFunc(verA, isNotNumber))
if err != nil {
aInt = 0
}
bInt, err := strconv.Atoi(strings.TrimRightFunc(verB, isNotNumber))
if err != nil {
bInt = 0
}
if aInt > bInt {
return 1
}
if aInt < bInt {
return -1
}
}
return 0
}
示例4: Columns
func (conn *Connection) Columns(tableName string) (columns []*Column, err error) {
const sqlColumns = `
SELECT r.rdb$field_name, r.rdb$field_source, f.rdb$field_type, f.rdb$field_sub_type,
f.rdb$field_length, f.rdb$field_precision, f.rdb$field_scale,
COALESCE(r.rdb$default_source, f.rdb$default_source) rdb$default_source,
COALESCE(r.rdb$null_flag, f.rdb$null_flag) rdb$null_flag
FROM rdb$relation_fields r
JOIN rdb$fields f ON r.rdb$field_source = f.rdb$field_name
WHERE r.rdb$relation_name = ?
ORDER BY r.rdb$field_position`
var cursor *Cursor
if cursor, err = conn.Execute(sqlColumns, tableName); err != nil {
return
}
defer cursor.Close()
for cursor.Next() {
var col Column
var sqlType int16
if err = cursor.Scan(
&col.Name,
&col.Domain,
&sqlType,
&col.SqlSubtype,
&col.Length,
&col.Precision,
&col.Scale,
&col.Default,
&col.Nullable); err != nil {
return
}
col.Name = strings.TrimRightFunc(col.Name, unicode.IsSpace)
if conn.database.LowercaseNames && !hasLowercase(col.Name) {
col.Name = strings.ToLower(col.Name)
}
col.Domain = strings.TrimRightFunc(col.Domain, unicode.IsSpace)
if strings.HasPrefix(col.Domain, "RDB$") {
col.Domain = ""
}
col.SqlType = sqlTypeFromCode(int(sqlType), int(col.SqlSubtype.Value))
if !col.Default.Null {
col.Default.Value = strings.Replace(col.Default.Value, "DEFAULT ", "", 1)
col.Default.Value = strings.TrimLeftFunc(col.Default.Value, unicode.IsSpace)
}
columns = append(columns, &col)
}
if cursor.Err() != io.EOF {
err = cursor.Err()
}
return
}
示例5: killSmallWordLeft
func killSmallWordLeft(ed *Editor) {
left := strings.TrimRightFunc(ed.line[:ed.dot], unicode.IsSpace)
// The case of left == "" is handled as well.
r, _ := utf8.DecodeLastRuneInString(left)
if isAlnum(r) {
left = strings.TrimRightFunc(left, isAlnum)
} else {
left = strings.TrimRightFunc(
left, func(r rune) bool { return !isAlnum(r) })
}
ed.line = left + ed.line[ed.dot:]
ed.dot = len(left)
}
示例6: handleConnection
func handleConnection(conn net.Conn) {
defer conn.Close()
tcpconn, ok := conn.(*net.TCPConn)
if ok {
tcpconn.SetLinger(-1)
tcpconn.SetKeepAlive(true)
}
readbuf := bufio.NewReader(conn)
sendError(conn, SmtpNoServiceHere, "This is not the SMTP Service you are looking for, move along.")
for {
cmd, err := readbuf.ReadString('\n')
if err != nil {
break
}
cmd = strings.TrimRightFunc(cmd, unicode.IsSpace)
if cmd == "" {
continue
}
if strings.ToLower(cmd) == "quit" {
break
}
sendError(conn, SmtpBadSequenceOfCommands, "bad sequence of commands")
}
}
示例7: Write
func (w wsCollapser) Write(p []byte) (n int, err error) {
lines := strings.Split(string(p), "\n")
for i, line := range lines {
l := line
if *w.prevNewLine {
l = strings.TrimLeftFunc(l, unicode.IsSpace)
}
curNewLine := (i < len(lines)-1) || (len(p) > 0 && p[len(p)-1] == '\n')
if curNewLine {
l = strings.TrimRightFunc(l, unicode.IsSpace)
}
if len(l) == 0 {
*w.prevNewLine = curNewLine
continue
}
if *w.prevNewLine && !*w.prevTag && l[0] != '<' {
_, err := (*w.writer).Write([]byte(" "))
if err != nil {
return 0, err
}
}
_, err := (*w.writer).Write([]byte(l))
if err != nil {
return 0, err
}
*w.prevTag = l[len(l)-1] == '>'
*w.prevNewLine = curNewLine
}
return len(p), nil
}
示例8: mainTest
func mainTest(t *testing.T, args ...string) string {
os.Args = append([]string{"tinystat"}, args...)
f, err := ioutil.TempFile(os.TempDir(), "tinystat")
if err != nil {
t.Fatal(err)
}
defer func() {
f.Close()
}()
oldStdout := os.Stdout
defer func() {
os.Stdout = oldStdout
}()
os.Stdout = f
main()
stdout, err := ioutil.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
// strip everything of trailing whitespace
lines := strings.Split(string(stdout), "\n")
for i, line := range lines {
lines[i] = strings.TrimRightFunc(line, unicode.IsSpace)
}
return strings.Join(lines, "\n")
}
示例9: Read
// Read returns a full YAML document.
func (r *YAMLReader) Read() ([]byte, error) {
var buffer bytes.Buffer
for {
line, err := r.reader.Read()
if err != nil && err != io.EOF {
return nil, err
}
sep := len([]byte(separator))
if i := bytes.Index(line, []byte(separator)); i == 0 {
// We have a potential document terminator
i += sep
after := line[i:]
if len(strings.TrimRightFunc(string(after), unicode.IsSpace)) == 0 {
if buffer.Len() != 0 {
return buffer.Bytes(), nil
}
if err == io.EOF {
return nil, err
}
}
}
if err == io.EOF {
if buffer.Len() != 0 {
// If we're at EOF, we have a final, non-terminated line. Return it.
return buffer.Bytes(), nil
}
return nil, err
}
buffer.Write(line)
}
}
示例10: PostApps_Repos_Points
func (s *Service) PostApps_Repos_Points(args *cmdArgs, env *rpcutil.Env) (err error) {
appid := args.CmdArgs[0]
repoid := args.CmdArgs[1]
data, err := ioutil.ReadAll(env.Req.Body)
if err != nil {
return err
}
reqSql := strings.TrimLeftFunc(string(data), isWhiteSpace)
point := strings.TrimRightFunc(reqSql, isWhiteSpace)
wurl := fmt.Sprintf("/v4/apps/%s/repos/%s/points", appid, repoid)
err = s.PandoraClient.CallWith(nil, nil, "POST", wurl, "text/plain", bytes.NewBuffer([]byte(point)), len(point))
if err != nil {
return fmt.Errorf("write pandora fail, error:%v", err)
}
err = s.InfluxdbClient.CallWith(nil, nil, "POST", "/write?db=pandora&rp=default", "text/plain", bytes.NewBuffer([]byte(point)), len(point))
if err != nil && err.Error() != "No Content" {
return fmt.Errorf("write influxdb fail, error:%v", err)
}
return
}
示例11: UsageFunc
func (templater *templater) UsageFunc(exposedFlags ...string) func(*cobra.Command) error {
return func(c *cobra.Command) error {
t := template.New("custom")
t.Funcs(template.FuncMap{
"trim": strings.TrimSpace,
"trimRight": func(s string) string { return strings.TrimRightFunc(s, unicode.IsSpace) },
"gt": cobra.Gt,
"eq": cobra.Eq,
"rpad": rpad,
"flagsNotIntersected": flagsNotIntersected,
"flagsUsages": flagsUsages,
"cmdGroups": templater.cmdGroups,
"rootCmd": templater.rootCmdName,
"isRootCmd": templater.isRootCmd,
"optionsCmdFor": templater.optionsCmdFor,
"exposed": func(c *cobra.Command) *flag.FlagSet {
exposed := flag.NewFlagSet("exposed", flag.ContinueOnError)
if len(exposedFlags) > 0 {
for _, name := range exposedFlags {
if flag := c.Flags().Lookup(name); flag != nil {
exposed.AddFlag(flag)
}
}
}
return exposed
},
})
template.Must(t.Parse(templater.UsageTemplate))
return t.Execute(c.Out(), c)
}
}
示例12: main
func main() {
show("original", simple)
show("leading ws removed", strings.TrimLeftFunc(simple, unicode.IsSpace))
show("trailing ws removed", strings.TrimRightFunc(simple, unicode.IsSpace))
// equivalent to strings.TrimFunc(simple, unicode.IsSpace)
show("both removed", strings.TrimSpace(simple))
}
示例13: parseEngineeringNotation
func parseEngineeringNotation(in string) (uint64, error) {
if in == "" {
return 0, nil
}
var numerics = func(r rune) bool {
return r >= '0' && r <= '9'
}
var nonNumerics = func(r rune) bool {
return !numerics(r)
}
suffix := strings.TrimLeftFunc(in, numerics)
numeric := strings.TrimRightFunc(in, nonNumerics)
val, err := strconv.ParseUint(numeric, 10, 64)
if err != nil {
return 0, fmt.Errorf("Parsing engineering notation for '%s'", in)
}
switch suffix {
case "K", "k":
val *= (1 << 10)
case "M", "m":
val *= (1 << 20)
case "G", "g":
val *= (1 << 30)
case "T", "t":
val *= (1 << 40)
case "":
break
default:
return 0, fmt.Errorf("Parsing engineering notation for '%s'", in)
}
return val, nil
}
示例14: templateFuncs
func (templater *templater) templateFuncs(exposedFlags ...string) template.FuncMap {
return template.FuncMap{
"trim": strings.TrimSpace,
"trimRight": func(s string) string { return strings.TrimRightFunc(s, unicode.IsSpace) },
"trimLeft": func(s string) string { return strings.TrimLeftFunc(s, unicode.IsSpace) },
"gt": cobra.Gt,
"eq": cobra.Eq,
"rpad": rpad,
"appendIfNotPresent": appendIfNotPresent,
"flagsNotIntersected": flagsNotIntersected,
"visibleFlags": visibleFlags,
"flagsUsages": flagsUsages,
"cmdGroups": templater.cmdGroups,
"cmdGroupsString": templater.cmdGroupsString,
"rootCmd": templater.rootCmdName,
"isRootCmd": templater.isRootCmd,
"optionsCmdFor": templater.optionsCmdFor,
"usageLine": templater.usageLine,
"exposed": func(c *cobra.Command) *flag.FlagSet {
exposed := flag.NewFlagSet("exposed", flag.ContinueOnError)
if len(exposedFlags) > 0 {
for _, name := range exposedFlags {
if flag := c.Flags().Lookup(name); flag != nil {
exposed.AddFlag(flag)
}
}
}
return exposed
},
}
}
示例15: Arg
func (cl cmdLine) Arg() string {
s := string(cl)
if idx := strings.Index(s, " "); idx != -1 {
return strings.TrimRightFunc(s[idx+1:len(s)-2], unicode.IsSpace)
}
return ""
}