| 2960 | } |
| 2961 | |
| 2962 | bool Value::isConvertibleTo(ValueType other) const { |
| 2963 | switch (other) { |
| 2964 | case nullValue: |
| 2965 | return (isNumeric() && asDouble() == 0.0) || |
| 2966 | (type_ == booleanValue && value_.bool_ == false) || |
| 2967 | (type_ == stringValue && asString() == "") || |
| 2968 | (type_ == arrayValue && value_.map_->size() == 0) || |
| 2969 | (type_ == objectValue && value_.map_->size() == 0) || |
| 2970 | type_ == nullValue; |
| 2971 | case intValue: |
| 2972 | return isInt() || |
| 2973 | (type_ == realValue && InRange(value_.real_, minInt, maxInt)) || |
| 2974 | type_ == booleanValue || type_ == nullValue; |
| 2975 | case uintValue: |
| 2976 | return isUInt() || |
| 2977 | (type_ == realValue && InRange(value_.real_, 0, maxUInt)) || |
| 2978 | type_ == booleanValue || type_ == nullValue; |
| 2979 | case realValue: |
| 2980 | return isNumeric() || type_ == booleanValue || type_ == nullValue; |
| 2981 | case booleanValue: |
| 2982 | return isNumeric() || type_ == booleanValue || type_ == nullValue; |
| 2983 | case stringValue: |
| 2984 | return isNumeric() || type_ == booleanValue || type_ == stringValue || |
| 2985 | type_ == nullValue; |
| 2986 | case arrayValue: |
| 2987 | return type_ == arrayValue || type_ == nullValue; |
| 2988 | case objectValue: |
| 2989 | return type_ == objectValue || type_ == nullValue; |
| 2990 | } |
| 2991 | JSON_ASSERT_UNREACHABLE; |
| 2992 | return false; |
| 2993 | } |
| 2994 | |
| 2995 | /// Number of values in array or object |
| 2996 | ArrayIndex Value::size() const { |