summaryrefslogtreecommitdiff
path: root/include/lib/ArduinoJson/Strings/RamStringAdapter.hpp
blob: 3aa4af155edfe4aced0eec611a69da57666ffb0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License

#pragma once

#include "lib/ArduinoJson/Strings/ConstRamStringAdapter.hpp"
#include "lib/ArduinoJson/Strings/IsString.hpp"
#include "lib/ArduinoJson/Strings/StoragePolicy.hpp"

namespace ARDUINOJSON_NAMESPACE {

class RamStringAdapter : public ConstRamStringAdapter {
 public:
  RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {}

  void copyTo(char* p, size_t n) const {
    memcpy(p, _str, n);
  }

  typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
};

template <typename TChar>
inline RamStringAdapter adaptString(const TChar* str) {
  return RamStringAdapter(reinterpret_cast<const char*>(str));
}

inline RamStringAdapter adaptString(char* str) {
  return RamStringAdapter(str);
}

template <typename TChar>
struct IsString<TChar*> {
  static const bool value = sizeof(TChar) == 1;
};

template <>
struct IsString<void*> {
  static const bool value = false;
};

}  // namespace ARDUINOJSON_NAMESPACE