PostgreSQL Source Code  git master
json.h File Reference
#include "lib/stringinfo.h"
Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void escape_json (StringInfo buf, const char *str)
 

Function Documentation

◆ escape_json()

void escape_json ( StringInfo  buf,
const char *  str 
)

Definition at line 2461 of file json.c.

References appendStringInfo(), appendStringInfoCharMacro, and appendStringInfoString().

Referenced by composite_to_json(), datum_to_json(), escape_yaml(), ExplainDummyGroup(), ExplainOpenGroup(), ExplainProperty(), ExplainPropertyList(), ExplainPropertyListNested(), hstore_to_json(), hstore_to_json_loose(), json_object(), json_object_two_arg(), jsonb_put_escaped_value(), sn_object_field_start(), sn_scalar(), transform_string_values_object_field_start(), and transform_string_values_scalar().

2462 {
2463  const char *p;
2464 
2465  appendStringInfoCharMacro(buf, '"');
2466  for (p = str; *p; p++)
2467  {
2468  switch (*p)
2469  {
2470  case '\b':
2471  appendStringInfoString(buf, "\\b");
2472  break;
2473  case '\f':
2474  appendStringInfoString(buf, "\\f");
2475  break;
2476  case '\n':
2477  appendStringInfoString(buf, "\\n");
2478  break;
2479  case '\r':
2480  appendStringInfoString(buf, "\\r");
2481  break;
2482  case '\t':
2483  appendStringInfoString(buf, "\\t");
2484  break;
2485  case '"':
2486  appendStringInfoString(buf, "\\\"");
2487  break;
2488  case '\\':
2489  appendStringInfoString(buf, "\\\\");
2490  break;
2491  default:
2492  if ((unsigned char) *p < ' ')
2493  appendStringInfo(buf, "\\u%04x", (int) *p);
2494  else
2495  appendStringInfoCharMacro(buf, *p);
2496  break;
2497  }
2498  }
2499  appendStringInfoCharMacro(buf, '"');
2500 }
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:127
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157