(tag string, in string)
| 124 | var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) |
| 125 | |
| 126 | func resolve(tag string, in string) (rtag string, out interface{}) { |
| 127 | tag = shortTag(tag) |
| 128 | if !resolvableTag(tag) { |
| 129 | return tag, in |
| 130 | } |
| 131 | |
| 132 | defer func() { |
| 133 | switch tag { |
| 134 | case "", rtag, strTag, binaryTag: |
| 135 | return |
| 136 | case floatTag: |
| 137 | if rtag == intTag { |
| 138 | switch v := out.(type) { |
| 139 | case int64: |
| 140 | rtag = floatTag |
| 141 | out = float64(v) |
| 142 | return |
| 143 | case int: |
| 144 | rtag = floatTag |
| 145 | out = float64(v) |
| 146 | return |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | failf("cannot decode %s `%s` as a %s", shortTag(rtag), in, shortTag(tag)) |
| 151 | }() |
| 152 | |
| 153 | // Any data is accepted as a !!str or !!binary. |
| 154 | // Otherwise, the prefix is enough of a hint about what it might be. |
| 155 | hint := byte('N') |
| 156 | if in != "" { |
| 157 | hint = resolveTable[in[0]] |
| 158 | } |
| 159 | if hint != 0 && tag != strTag && tag != binaryTag { |
| 160 | // Handle things we can lookup in a map. |
| 161 | if item, ok := resolveMap[in]; ok { |
| 162 | return item.tag, item.value |
| 163 | } |
| 164 | |
| 165 | // Base 60 floats are a bad idea, were dropped in YAML 1.2, and |
| 166 | // are purposefully unsupported here. They're still quoted on |
| 167 | // the way out for compatibility with other parser, though. |
| 168 | |
| 169 | switch hint { |
| 170 | case 'M': |
| 171 | // We've already checked the map above. |
| 172 | |
| 173 | case '.': |
| 174 | // Not in the map, so maybe a normal float. |
| 175 | floatv, err := strconv.ParseFloat(in, 64) |
| 176 | if err == nil { |
| 177 | return floatTag, floatv |
| 178 | } |
| 179 | |
| 180 | case 'D', 'S': |
| 181 | // Int, float, or timestamp. |
| 182 | // Only try values as a timestamp if the value is unquoted or there's an explicit |
| 183 | // !!timestamp tag. |
no test coverage detected