mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #327 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-update-vendor-20181020-2.2.0 to release/2.2.0
* commit '12ae5b6aca3af606b47e58e8d9afa1345006324e': 更新vendor
This commit is contained in:
Generated
+4
-4
@@ -1223,11 +1223,11 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:49ffc35ec8d3f7789393cd132acd359e8ac1f5d38c7a2b91c484b041840c62c0"
|
||||
digest = "1:54554b3c72f4fcbd3c27c5137f9acd9d153d7e7150d77cd509af50c75fcb41b9"
|
||||
name = "yunion.io/x/jsonutils"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "d1290e94d4753c1748fc7c89f472a523cc0a5c08"
|
||||
revision = "7079aada4c7e9a37e4c3b183bddb0ef684e038f2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -1242,7 +1242,7 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:211ecaed7d1d87e5d216b598c3cd5b7c47977b73a06308e1b39c08fd03c9c417"
|
||||
digest = "1:201bff9d99a538dd71fd8e55bbbfda8a301fd89676d0668a2cedc574e1aeaa03"
|
||||
name = "yunion.io/x/pkg"
|
||||
packages = [
|
||||
"gotypes",
|
||||
@@ -1276,7 +1276,7 @@
|
||||
"utils",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "9d246215b0a167b153bcdbc7d75031ced7138cf8"
|
||||
revision = "122c7d4ce76b4611b63d86af8e9bb2610ab55c20"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package jsonutils
|
||||
|
||||
func (val *JSONValue) isCompond() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (val *JSONDict) isCompond() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (val *JSONArray) isCompond() bool {
|
||||
return true
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package jsonutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
)
|
||||
|
||||
func normalizeUSCurrency(currency string) string {
|
||||
return strings.Replace(currency, ",", "", -1)
|
||||
}
|
||||
|
||||
func normalizeEUCurrency(currency string) string {
|
||||
commaPos := strings.IndexByte(currency, ',')
|
||||
if commaPos >= 0 {
|
||||
return fmt.Sprintf("%s.%s", strings.Replace(currency[:commaPos], ".", "", -1), currency[commaPos+1:])
|
||||
} else {
|
||||
return strings.Replace(currency, ".", "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeCurrencyString(currency string) string {
|
||||
if regutils.MatchUSCurrency(currency) {
|
||||
return normalizeUSCurrency(currency)
|
||||
}
|
||||
if regutils.MatchEUCurrency(currency) {
|
||||
return normalizeEUCurrency(currency)
|
||||
}
|
||||
return currency
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package jsonutils
|
||||
|
||||
func (self *JSONValue) Interface() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *JSONBool) Interface() interface{} {
|
||||
return self.data
|
||||
}
|
||||
|
||||
func (self *JSONInt) Interface() interface{} {
|
||||
return self.data
|
||||
}
|
||||
|
||||
func (self *JSONFloat) Interface() interface{} {
|
||||
return self.data
|
||||
}
|
||||
|
||||
func (self *JSONString) Interface() interface{} {
|
||||
return self.data
|
||||
}
|
||||
|
||||
func (self *JSONArray) Interface() interface{} {
|
||||
ret := make([]interface{}, len(self.data))
|
||||
for i := 0; i < len(self.data); i += 1 {
|
||||
ret[i] = self.data[i].Interface()
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *JSONDict) Interface() interface{} {
|
||||
mapping := make(map[string]interface{})
|
||||
|
||||
for k, v := range self.data {
|
||||
mapping[k] = v.Interface()
|
||||
}
|
||||
|
||||
return mapping
|
||||
}
|
||||
+2
@@ -65,6 +65,8 @@ type JSONObject interface {
|
||||
Equals(obj JSONObject) bool
|
||||
unmarshalValue(val reflect.Value) error
|
||||
// IsZero() bool
|
||||
Interface() interface{}
|
||||
isCompond() bool
|
||||
}
|
||||
|
||||
type JSONValue struct {
|
||||
|
||||
+2
-1
@@ -321,7 +321,7 @@ func (this *JSONString) unmarshalValue(val reflect.Value) error {
|
||||
}
|
||||
val.SetInt(intVal)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
floatVal, err := strconv.ParseFloat(this.data, 64)
|
||||
floatVal, err := strconv.ParseFloat(normalizeCurrencyString(this.data), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -348,6 +348,7 @@ func (this *JSONArray) unmarshalValue(val reflect.Value) error {
|
||||
if this.data != nil {
|
||||
array.Add(this.data...)
|
||||
}
|
||||
val.Set(reflect.ValueOf(array))
|
||||
return nil
|
||||
case JSONArrayPtrType, JSONObjectType:
|
||||
val.Set(reflect.ValueOf(this))
|
||||
|
||||
+38
-26
@@ -61,43 +61,49 @@ func parseYAMLDict(lines []string) (map[string]JSONObject, error) {
|
||||
} else {
|
||||
key := lines[i][0:keypos]
|
||||
val := strings.Trim(lines[i][keypos+1:], " ")
|
||||
|
||||
if len(val) > 0 && val != "|" {
|
||||
o, e := Parse([]byte(val))
|
||||
if e != nil {
|
||||
return dict, e
|
||||
} else {
|
||||
dict[key] = o
|
||||
}
|
||||
dict[key] = NewString(val)
|
||||
i++
|
||||
} else {
|
||||
sublines := make([]string, 0)
|
||||
j := i + 1
|
||||
for j < len(lines) && len(strings.Trim(lines[j], " ")) == 0 {
|
||||
sublines = append(sublines, "")
|
||||
j++
|
||||
}
|
||||
if j >= len(lines) || lines[j][0] != ' ' {
|
||||
return dict, fmt.Errorf("Illformat")
|
||||
}
|
||||
indent := 0
|
||||
for indent < len(lines[j]) && lines[j][indent] == ' ' {
|
||||
indent++
|
||||
}
|
||||
sublines := make([]string, 0)
|
||||
for j < len(lines) {
|
||||
if indent >= len(lines[j]) && len(strings.Trim(lines[j], " ")) == 0 {
|
||||
j++
|
||||
} else if indent < len(lines[j]) && len(strings.Trim(lines[j][:indent], " ")) == 0 {
|
||||
sublines = append(sublines, lines[j][indent:])
|
||||
j++
|
||||
} else {
|
||||
break
|
||||
if j < len(lines) {
|
||||
if lines[j][0] != ' ' {
|
||||
return dict, fmt.Errorf("Illformat")
|
||||
}
|
||||
|
||||
indent := 0
|
||||
for indent < len(lines[j]) && lines[j][indent] == ' ' {
|
||||
indent++
|
||||
}
|
||||
|
||||
for j < len(lines) {
|
||||
if indent >= len(lines[j]) && len(strings.Trim(lines[j], " ")) == 0 {
|
||||
sublines = append(sublines, "")
|
||||
j++
|
||||
} else if indent < len(lines[j]) && len(strings.Trim(lines[j][:indent], " ")) == 0 {
|
||||
sublines = append(sublines, lines[j][indent:])
|
||||
j++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
o, e := parseYAMLLines(sublines)
|
||||
if e != nil {
|
||||
return dict, e
|
||||
if val == "|" {
|
||||
dict[key] = NewString(strings.Join(sublines, "\n"))
|
||||
} else {
|
||||
o, e := parseYAMLLines(sublines)
|
||||
if e != nil {
|
||||
return dict, e
|
||||
}
|
||||
dict[key] = o
|
||||
}
|
||||
|
||||
i = j
|
||||
}
|
||||
}
|
||||
@@ -192,8 +198,14 @@ func (this *JSONDict) yamlLines() []string {
|
||||
var ret = make([]string, 0)
|
||||
for _, key := range this.SortedKeys() {
|
||||
val := this.data[key]
|
||||
if val.IsZero() {
|
||||
switch val.(type) {
|
||||
case *JSONString, *JSONDict, *JSONArray, *JSONValue:
|
||||
continue
|
||||
}
|
||||
}
|
||||
lines := val.yamlLines()
|
||||
if len(lines) == 1 {
|
||||
if !val.isCompond() && len(lines) == 1 {
|
||||
ret = append(ret, fmt.Sprintf("%s: %s", key, lines[0]))
|
||||
} else {
|
||||
switch val.(type) {
|
||||
|
||||
+12
@@ -32,6 +32,8 @@ var RFC2882_TIME_REG *regexp.Regexp
|
||||
var EMAIL_REG *regexp.Regexp
|
||||
var CHINA_MOBILE_REG *regexp.Regexp
|
||||
var FS_FORMAT_REG *regexp.Regexp
|
||||
var US_CURRENCY_REG *regexp.Regexp
|
||||
var EU_CURRENCY_REG *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
FUNCTION_REG = regexp.MustCompile(`^\w+\(.*\)$`)
|
||||
@@ -62,6 +64,8 @@ func init() {
|
||||
EMAIL_REG = regexp.MustCompile(`^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$`)
|
||||
CHINA_MOBILE_REG = regexp.MustCompile(`^1[0-9-]{10}$`)
|
||||
FS_FORMAT_REG = regexp.MustCompile(`^(ext|fat|hfs|xfs|swap|ntfs|reiserfs|ufs|btrfs)`)
|
||||
US_CURRENCY_REG = regexp.MustCompile(`^(\d{0,3}|((\d{1,3},)+\d{3}))(\.\d*)?$`)
|
||||
EU_CURRENCY_REG = regexp.MustCompile(`^(\d{0,3}|((\d{1,3}\.)+\d{3}))(,\d*)?$`)
|
||||
}
|
||||
|
||||
func MatchFunction(str string) bool {
|
||||
@@ -179,3 +183,11 @@ func MatchMobile(str string) bool {
|
||||
func MatchFS(str string) bool {
|
||||
return FS_FORMAT_REG.MatchString(str)
|
||||
}
|
||||
|
||||
func MatchUSCurrency(str string) bool {
|
||||
return US_CURRENCY_REG.MatchString(str)
|
||||
}
|
||||
|
||||
func MatchEUCurrency(str string) bool {
|
||||
return EU_CURRENCY_REG.MatchString(str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user