mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // ArduinoJson - https://arduinojson.org
 | |
| // Copyright Benoit Blanchon 2014-2021
 | |
| // MIT License
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <stddef.h>  // size_t
 | |
| #include <string.h>  // strcmp
 | |
| 
 | |
| #include <ArduinoJson/Polyfills/assert.hpp>
 | |
| #include <ArduinoJson/Polyfills/safe_strcmp.hpp>
 | |
| #include <ArduinoJson/Strings/StoragePolicy.hpp>
 | |
| #include <ArduinoJson/Strings/StringAdapter.hpp>
 | |
| 
 | |
| namespace ARDUINOJSON_NAMESPACE {
 | |
| 
 | |
| template <>
 | |
| class StringAdapter<const char*> {
 | |
|  public:
 | |
|   StringAdapter(const char* str = 0) : _str(str) {}
 | |
| 
 | |
|   int compare(const char* other) const {
 | |
|     return safe_strcmp(_str, other);
 | |
|   }
 | |
| 
 | |
|   bool isNull() const {
 | |
|     return !_str;
 | |
|   }
 | |
| 
 | |
|   size_t size() const {
 | |
|     if (!_str)
 | |
|       return 0;
 | |
|     return strlen(_str);
 | |
|   }
 | |
| 
 | |
|   char operator[](size_t i) const {
 | |
|     ARDUINOJSON_ASSERT(_str != 0);
 | |
|     ARDUINOJSON_ASSERT(i <= size());
 | |
|     return _str[i];
 | |
|   }
 | |
| 
 | |
|   const char* data() const {
 | |
|     return _str;
 | |
|   }
 | |
| 
 | |
|   typedef storage_policies::store_by_address storage_policy;
 | |
| 
 | |
|  protected:
 | |
|   const char* _str;
 | |
| };
 | |
| 
 | |
| template <int N>
 | |
| class StringAdapter<const char[N]> : public StringAdapter<const char*> {
 | |
|  public:
 | |
|   StringAdapter(const char* s) : StringAdapter<const char*>(s) {}
 | |
| };
 | |
| 
 | |
| }  // namespace ARDUINOJSON_NAMESPACE
 |