12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package util
- import "strconv"
- var msgHandler map[string](chan interface{})
- func GetMsgHandler(msgPipe string) chan interface{} {
- hdr, has := msgHandler[msgPipe]
- if !has {
- hdr = make(chan interface{})
- msgHandler[msgPipe] = hdr
- }
- return hdr
- }
- func PostMessage(msgPipe string, msg interface{}) {
- hdr, has := msgHandler[msgPipe]
- if !has {
- hdr = make(chan interface{})
- msgHandler[msgPipe] = hdr
- }
- hdr <- msg
- }
- const (
- NUMBER_ALL = iota
- NUMBER_CONTINUE
- )
- func NumberFilter(in string, mode int) string {
- sbyte := make([]byte, 0)
- bnumbered := false
- for _, ss := range []byte(in) {
- if (ss >= '0' && ss <= '9') || ss == '.' || ss == '-' || ss == '+' {
- sbyte = append(sbyte, ss)
- bnumbered = true
- } else if mode != NUMBER_ALL {
- if bnumbered {
- break
- }
- }
- }
- return string(sbyte)
- }
- func init() {
- msgHandler = make(map[string]chan interface{})
- }
- func DebugLevel() int {
- return 1
- }
- func ToInt(source interface{}) int {
- res := -1
- switch val := source.(type) {
- case int:
- res = val
- case int16:
- res = int(val)
- case int32:
- res = int(val)
- case float32:
- res = int(val)
- case float64:
- res = int(val)
- case string:
- res = int(StringToInt64(val, 0))
- }
- return res
- }
- func StringToInt64(str string, dval int64) int64 {
- res, e := strconv.ParseInt(str, 10, 64)
- if e != nil {
- res = dval
- }
- return res
- }
|