mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			754 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			754 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "StringBuilder.h"
 | |
| 
 | |
| 
 | |
| void StringBuilder::append(const char* s)
 | |
| {
 | |
|     char* tail = buffer + length;
 | |
| 
 | |
|     strcpy(tail, s);
 | |
| 
 | |
|     length += strlen(tail);
 | |
| }
 | |
| 
 | |
| void StringBuilder::appendEscaped(const char* s)
 | |
| {
 | |
|     if (length > capacity - 3) return;
 | |
| 
 | |
|     buffer[length++] = '"';
 | |
| 
 | |
|     while (*s && length<capacity-2)
 | |
|     {
 | |
|         if (*s == '"')
 | |
|             buffer[length++] = '\\';
 | |
| 
 | |
|         buffer[length++] = *s;
 | |
| 
 | |
|         s++;
 | |
|     }
 | |
| 
 | |
|     buffer[length++] = '"';
 | |
| }
 | |
| 
 | |
| void StringBuilder::appendFormatted(const char* format, ...)
 | |
| {
 | |
|     char* tail = buffer + length;
 | |
| 
 | |
|     va_list args;
 | |
|     va_start(args, format);
 | |
|     vsnprintf(tail, capacity - length, format, args);
 | |
|     va_end(args);
 | |
| 
 | |
|     length += strlen(tail);
 | |
| } |