2020-02-13 07:27:07 +03:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
2019-11-12 12:09:52 +03:00
|
|
|
package util
|
|
|
|
|
2019-12-24 06:21:35 +03:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
2019-11-12 12:09:52 +03:00
|
|
|
|
|
|
|
func ParseInt(s string) int {
|
|
|
|
i, err := strconv.Atoi(s)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseFloat(s string) float64 {
|
|
|
|
f, err := strconv.ParseFloat(s, 64)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return f
|
|
|
|
}
|
2019-12-24 06:21:35 +03:00
|
|
|
|
2020-08-17 12:38:48 +03:00
|
|
|
func FormatFloat(f float64) string {
|
|
|
|
return strconv.FormatFloat(f, 'f', -1, 64)
|
|
|
|
}
|
|
|
|
|
2019-12-24 06:21:35 +03:00
|
|
|
func UnescapeUserAgent(userAgent string) string {
|
|
|
|
return strings.Replace(userAgent, "#TAB#", ",", -1)
|
|
|
|
}
|
2020-02-15 12:00:10 +03:00
|
|
|
|
|
|
|
func UniqueStringSlice(l []string) []string {
|
|
|
|
keys := make(map[string]bool)
|
|
|
|
list := []string{}
|
|
|
|
for _, entry := range l {
|
|
|
|
if _, value := keys[entry]; !value {
|
|
|
|
keys[entry] = true
|
|
|
|
list = append(list, entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|