PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

void escape_json ( StringInfo  buf,
const char *  str 
)

Definition at line 2433 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().

2434 {
2435  const char *p;
2436 
2437  appendStringInfoCharMacro(buf, '"');
2438  for (p = str; *p; p++)
2439  {
2440  switch (*p)
2441  {
2442  case '\b':
2443  appendStringInfoString(buf, "\\b");
2444  break;
2445  case '\f':
2446  appendStringInfoString(buf, "\\f");
2447  break;
2448  case '\n':
2449  appendStringInfoString(buf, "\\n");
2450  break;
2451  case '\r':
2452  appendStringInfoString(buf, "\\r");
2453  break;
2454  case '\t':
2455  appendStringInfoString(buf, "\\t");
2456  break;
2457  case '"':
2458  appendStringInfoString(buf, "\\\"");
2459  break;
2460  case '\\':
2461  appendStringInfoString(buf, "\\\\");
2462  break;
2463  default:
2464  if ((unsigned char) *p < ' ')
2465  appendStringInfo(buf, "\\u%04x", (int) *p);
2466  else
2467  appendStringInfoCharMacro(buf, *p);
2468  break;
2469  }
2470  }
2471  appendStringInfoCharMacro(buf, '"');
2472 }
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:135
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189