Standard.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Standard.h
8  *
9  * @author mikee47 <mike@sillyhouse.net> Nov 2020
10  *
11  ****/
12 
13 #pragma once
14 
15 #include "Formatter.h"
16 
17 namespace Format
18 {
19 class Standard : public Formatter
20 {
21 public:
22  void escape(String& value) const override
23  {
24  }
25 
26  void quote(String& value) const override
27  {
28  char cQuote{'"'};
29  auto len = value.length();
30  value.setLength(len + 2);
31  memmove(&value[1], value.c_str(), len);
32  value[0] = cQuote;
33  value[len + 1] = cQuote;
34  }
35 
36  void unQuote(String& value) const override
37  {
38  char quote = value[0];
39  if(quote == '"' || quote == '\'') {
40  auto len = value.length();
41  if(len > 1 && value[len - 1] == quote) {
42  value.remove(len - 1, 1);
43  value.remove(0, 1);
44  }
45  }
46  }
47 
48  MimeType mimeType() const override
49  {
50  return MIME_TEXT;
51  }
52 };
53 
54 extern Standard standard;
55 
56 } // namespace Format
Standard standard
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:641
void escape(String &value) const override
Perform any necessary text escaping so output is valid.
Definition: Standard.h:22
The String class.
Definition: WString.h:136
void quote(String &value) const override
Convert a value into quoted string.
Definition: Standard.h:26
Definition: Formatter.h:18
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:237
bool setLength(size_t length)
set the string length accordingly, expanding if necessary
Virtual class to perform format-specific String adjustments.
Definition: Formatter.h:23
void remove(size_t index)
Definition: WString.h:774
MimeType
Definition: WebConstants.h:53
void unQuote(String &value) const override
Remove any quotes from a value.
Definition: Standard.h:36
Definition: Standard.h:19
MimeType mimeType() const override
Correspdoning MIME type for this format.
Definition: Standard.h:48