| 919 | } |
| 920 | |
| 921 | bool Value::isConvertibleTo(ValueType other) const { |
| 922 | switch (other) { |
| 923 | case nullValue: |
| 924 | return (isNumeric() && asDouble() == 0.0) || |
| 925 | (type() == booleanValue && !value_.bool_) || |
| 926 | (type() == stringValue && asString().empty()) || |
| 927 | (type() == arrayValue && value_.map_->empty()) || |
| 928 | (type() == objectValue && value_.map_->empty()) || |
| 929 | type() == nullValue; |
| 930 | case intValue: |
| 931 | return isInt() || |
| 932 | (type() == realValue && InRange(value_.real_, minInt, maxInt)) || |
| 933 | type() == booleanValue || type() == nullValue; |
| 934 | case uintValue: |
| 935 | return isUInt() || |
| 936 | (type() == realValue && InRange(value_.real_, 0u, maxUInt)) || |
| 937 | type() == booleanValue || type() == nullValue; |
| 938 | case realValue: |
| 939 | return isNumeric() || type() == booleanValue || type() == nullValue; |
| 940 | case booleanValue: |
| 941 | return isNumeric() || type() == booleanValue || type() == nullValue; |
| 942 | case stringValue: |
| 943 | return isNumeric() || type() == booleanValue || type() == stringValue || |
| 944 | type() == nullValue; |
| 945 | case arrayValue: |
| 946 | return type() == arrayValue || type() == nullValue; |
| 947 | case objectValue: |
| 948 | return type() == objectValue || type() == nullValue; |
| 949 | } |
| 950 | JSON_ASSERT_UNREACHABLE; |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | /// Number of values in array or object |
| 955 | ArrayIndex Value::size() const { |