MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / EncodeChar

Method EncodeChar

src/Platform/OutputMemory.cpp:268–303  ·  view source on GitHub ↗

Encode a character in JSON format, and append it to the buffer and return the number of bytes written

Source from the content-addressed store, hash-verified

266
267// Encode a character in JSON format, and append it to the buffer and return the number of bytes written
268size_t OutputBuffer::EncodeChar(char c) noexcept
269{
270 char esc;
271 switch (c)
272 {
273 case '\r':
274 esc = 'r';
275 break;
276 case '\n':
277 esc = 'n';
278 break;
279 case '\t':
280 esc = 't';
281 break;
282 case '"':
283 case '\\':
284#if 1
285 // Escaping '/' is optional in JSON, although doing so so confuses PanelDue (fixed in PanelDue firmware version 1.15 and later). As it's optional, we don't do it.
286#else
287 case '/':
288#endif
289 esc = c;
290 break;
291 default:
292 esc = 0;
293 break;
294 }
295
296 if (esc != 0)
297 {
298 const size_t written = cat('\\');
299 return (written == 0) ? written : written + cat(esc);
300 }
301
302 return cat(c);
303}
304
305size_t OutputBuffer::EncodeReply(OutputBuffer *_ecv_null src) noexcept
306{

Callers 1

THROWSFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected