Skip to content

Commit

Permalink
Add operator<<(std::ostream&, const JsonString&)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Nov 24, 2021
1 parent 5c2fe6b commit d2b79a1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ArduinoJson/Strings/String.hpp
Expand Up @@ -6,6 +6,10 @@

#include <ArduinoJson/Misc/SafeBoolIdiom.hpp>

#if ARDUINOJSON_ENABLE_STD_STREAM
# include <ostream>
#endif

namespace ARDUINOJSON_NAMESPACE {

class String : public SafeBoolIdom<String> {
Expand Down Expand Up @@ -61,6 +65,13 @@ class String : public SafeBoolIdom<String> {
return strcmp(lhs._data, rhs._data) != 0;
}

#if ARDUINOJSON_ENABLE_STD_STREAM
friend std::ostream& operator<<(std::ostream& lhs, const String& rhs) {
lhs.write(rhs.c_str(), static_cast<std::streamsize>(rhs.size()));
return lhs;
}
#endif

private:
const char* _data;
size_t _size;
Expand Down

0 comments on commit d2b79a1

Please sign in to comment.