File: errors_tinygo.go

package info (click to toggle)
golang-github-tinylib-msgp 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: makefile: 47
file content (42 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (2)
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
//go:build tinygo
// +build tinygo

package msgp

import (
	"reflect"
)

// ctxString converts the incoming interface{} slice into a single string,
// without using fmt under tinygo
func ctxString(ctx []interface{}) string {
	out := ""
	for idx, cv := range ctx {
		if idx > 0 {
			out += "/"
		}
		out += ifToStr(cv)
	}
	return out
}

type stringer interface {
	String() string
}

func ifToStr(i interface{}) string {
	switch v := i.(type) {
	case stringer:
		return v.String()
	case error:
		return v.Error()
	case string:
		return v
	default:
		return reflect.ValueOf(i).String()
	}
}

func quoteStr(s string) string {
	return simpleQuoteStr(s)
}