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 2397 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().

2398 {
2399  const char *p;
2400 
2401  appendStringInfoCharMacro(buf, '"');
2402  for (p = str; *p; p++)
2403  {
2404  switch (*p)
2405  {
2406  case '\b':
2407  appendStringInfoString(buf, "\\b");
2408  break;
2409  case '\f':
2410  appendStringInfoString(buf, "\\f");
2411  break;
2412  case '\n':
2413  appendStringInfoString(buf, "\\n");
2414  break;
2415  case '\r':
2416  appendStringInfoString(buf, "\\r");
2417  break;
2418  case '\t':
2419  appendStringInfoString(buf, "\\t");
2420  break;
2421  case '"':
2422  appendStringInfoString(buf, "\\\"");
2423  break;
2424  case '\\':
2425  appendStringInfoString(buf, "\\\\");
2426  break;
2427  default:
2428  if ((unsigned char) *p < ' ')
2429  appendStringInfo(buf, "\\u%04x", (int) *p);
2430  else
2431  appendStringInfoCharMacro(buf, *p);
2432  break;
2433  }
2434  }
2435  appendStringInfoCharMacro(buf, '"');
2436 }
#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