| 2758 | } |
| 2759 | |
| 2760 | std::string Value::asString() const { |
| 2761 | switch (type_) { |
| 2762 | case nullValue: |
| 2763 | return ""; |
| 2764 | case stringValue: { |
| 2765 | if (value_.string_ == 0) return ""; |
| 2766 | unsigned this_len; |
| 2767 | char const* this_str; |
| 2768 | decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); |
| 2769 | return std::string(this_str, this_len); |
| 2770 | } |
| 2771 | case booleanValue: |
| 2772 | return value_.bool_ ? "true" : "false"; |
| 2773 | case intValue: |
| 2774 | return valueToString(value_.int_); |
| 2775 | case uintValue: |
| 2776 | return valueToString(value_.uint_); |
| 2777 | case realValue: |
| 2778 | return valueToString(value_.real_); |
| 2779 | default: |
| 2780 | JSON_FAIL_MESSAGE("Type is not convertible to string"); |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | #ifdef JSON_USE_CPPTL |
| 2785 | CppTL::ConstString Value::asConstString() const { |
no test coverage detected