Andrew Dunstan avatar Andrew Dunstan committed 5e31342

pgindent jsonfuncs.c

Comments (0)

Files changed (1)

src/backend/utils/adt/jsonfuncs.c

 static void get_array_element_start(void *state, bool isnull);
 static void get_array_element_end(void *state, bool isnull);
 static void get_scalar(void *state, char *token, JsonTokenType tokentype);
+
 /* common worker function for json_get* functions */
-static text *get_worker(char *json, char *field, int elem_index, char **path, 
-						int npath, bool normalize_results);
+static text *get_worker(char *json, char *field, int elem_index, char **path,
+		   int npath, bool normalize_results);
 
 /* semantic action functions for json_array_length */
 static void alen_object_start(void *state);
 static void unnest_scalar(void *state, char *token, JsonTokenType tokentype);
 
 /* turn a json object into a hash table */
-static HTAB *get_json_object_as_hash(char * jsonstr, char *funcname);
+static HTAB *get_json_object_as_hash(char *jsonstr, char *funcname);
+
 /* semantic action functions for get_json_object_as_hash */
 static void hash_object_start(void *state);
 static void hash_object_field_start(void *state, char *fname, bool isnull);
 	bool		result_is_null;
 	bool		normalize_results;
 	bool		next_scalar;
-	char      **path;
-	int         npath;
-	char      **current_path;
-	bool       *pathok;
-	int        *array_level_index;
-	int        *path_level_index;
+	char	  **path;
+	int			npath;
+	char	  **current_path;
+	bool	   *pathok;
+	int		   *array_level_index;
+	int		   *path_level_index;
 }	getState, *GetState;
 
 /* state for json_array_length */
 typedef struct
 {
 	int			lex_level;
-	int         count;
+	int			count;
 }	alenState, *AlenState;
 
 /* state for json_each */
 {
 	JsonLexContext *lex;
 	int			lex_level;
-    Tuplestorestate *tuple_store;
-    TupleDesc   ret_tdesc;
+	Tuplestorestate *tuple_store;
+	TupleDesc	ret_tdesc;
 	MemoryContext tmp_cxt;
-	char  *result_start;
-	bool  normalize_results;
-	bool  next_scalar;
-	char  *normalized_scalar;
-} eachState, *EachState;
+	char	   *result_start;
+	bool		normalize_results;
+	bool		next_scalar;
+	char	   *normalized_scalar;
+}	eachState, *EachState;
 
 /* state for json_unnest */
 typedef struct
 {
 	JsonLexContext *lex;
 	int			lex_level;
-    Tuplestorestate *tuple_store;
-    TupleDesc   ret_tdesc;
+	Tuplestorestate *tuple_store;
+	TupleDesc	ret_tdesc;
 	MemoryContext tmp_cxt;
-	char  *result_start;
-} unnestState, *UnnestState;
+	char	   *result_start;
+}	unnestState, *UnnestState;
 
 /* state for get_json_object_as_hash */
 typedef struct
 {
 	JsonLexContext *lex;
 	int			lex_level;
-    HTAB        *hash;
-    char        *saved_scalar;
-	char  *function_name;
-} jhashState, *JHashState;
+	HTAB	   *hash;
+	char	   *saved_scalar;
+	char	   *function_name;
+}	jhashState, *JHashState;
 
 /* used to build the hashtable */
-typedef struct 
+typedef struct
 {
-	char fname[NAMEDATALEN];
-	char *val;
-	char *json;
-	bool isnull;
-} jsonHashEntry, *JsonHashEntry;
+	char		fname[NAMEDATALEN];
+	char	   *val;
+	char	   *json;
+	bool		isnull;
+}	jsonHashEntry, *JsonHashEntry;
 
 /* these two are stolen from hstore / record_out, used in populate_record */
 typedef struct ColumnIOData
 	Oid			typiofunc;
 	Oid			typioparam;
 	FmgrInfo	proc;
-} ColumnIOData;
+}	ColumnIOData;
 
 typedef struct RecordIOData
 {
 	int32		record_typmod;
 	int			ncolumns;
 	ColumnIOData columns[1];	/* VARIABLE LENGTH ARRAY */
-} RecordIOData;
+}	RecordIOData;
 
 /*
  * SQL function json_object-keys
 	ArrayType  *path = PG_GETARG_ARRAYTYPE_P(1);
 	char	   *jsonstr = text_to_cstring(json);
 	text	   *result;
-    Datum      *pathtext;
-    bool       *pathnulls;
-    int         npath;
-    char      **pathstr;
-	int         i;
+	Datum	   *pathtext;
+	bool	   *pathnulls;
+	int			npath;
+	char	  **pathstr;
+	int			i;
 
 	if (array_contains_nulls(path))
 		ereport(ERROR,
 						"json_get_path_as_text")));
 
 
-    deconstruct_array(path, TEXTOID, -1, false, 'i',
-                      &pathtext, &pathnulls, &npath);
-    
-    pathstr = palloc(npath * sizeof(char *));
+	deconstruct_array(path, TEXTOID, -1, false, 'i',
+					  &pathtext, &pathnulls, &npath);
 
-    for (i = 0; i < npath; i++)
+	pathstr = palloc(npath * sizeof(char *));
+
+	for (i = 0; i < npath; i++)
 	{
 		pathstr[i] = TextDatumGetCString(pathtext[i]);
 		if (*pathstr[i] == '\0')
 			ereport(
-				ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("cannot call %s with empty path elements",
-						"json_get_path_as_text")));
+					ERROR,
+					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					 errmsg("cannot call %s with empty path elements",
+							"json_get_path_as_text")));
 	}
 
 	result = get_worker(jsonstr, NULL, -1, pathstr, npath, false);
 	ArrayType  *path = PG_GETARG_ARRAYTYPE_P(1);
 	char	   *jsonstr = text_to_cstring(json);
 	text	   *result;
-    Datum      *pathtext;
-    bool       *pathnulls;
-    int         npath;
-    char      **pathstr;
-	int         i;
+	Datum	   *pathtext;
+	bool	   *pathnulls;
+	int			npath;
+	char	  **pathstr;
+	int			i;
 
 	if (array_contains_nulls(path))
 		ereport(ERROR,
 						"json_get_path_as_text")));
 
 
-    deconstruct_array(path, TEXTOID, -1, false, 'i',
-                      &pathtext, &pathnulls, &npath);
-    
-    pathstr = palloc(npath * sizeof(char *));
+	deconstruct_array(path, TEXTOID, -1, false, 'i',
+					  &pathtext, &pathnulls, &npath);
 
-    for (i = 0; i < npath; i++)
+	pathstr = palloc(npath * sizeof(char *));
+
+	for (i = 0; i < npath; i++)
 	{
 		pathstr[i] = TextDatumGetCString(pathtext[i]);
 		if (*pathstr[i] == '\0')
 			ereport(
-				ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("cannot call %s with empty path elements",
-						"json_get_path_as_text")));
+					ERROR,
+					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					 errmsg("cannot call %s with empty path elements",
+							"json_get_path_as_text")));
 	}
 
 	result = get_worker(jsonstr, NULL, -1, pathstr, npath, true);
 }
 
 static text *
-get_worker(char *json, 
-		   char *field, 
-		   int elem_index, 
-		   char **path, 
-		   int npath, 
+get_worker(char *json,
+		   char *field,
+		   int elem_index,
+		   char **path,
+		   int npath,
 		   bool normalize_results)
 {
 	GetState	state;
 	}
 	else if (path != NULL)
 	{
-		int i;
-		long int ind;
-		char *endptr;
+		int			i;
+		long int	ind;
+		char	   *endptr;
 
 		state->search_type = JSON_SEARCH_PATH;
 		state->path = path;
 		state->pathok[0] = true;
 		state->array_level_index = palloc(sizeof(int) * npath);
 		state->path_level_index = palloc(sizeof(int) * npath);
-		for (i=0; i < npath; i++)
+		for (i = 0; i < npath; i++)
 		{
-			ind = strtol(path[i],&endptr,10);
+			ind = strtol(path[i], &endptr, 10);
 			if (*endptr == '\0' && ind <= INT_MAX && ind >= 0)
 				state->path_level_index[i] = (int) ind;
 			else
 				state->path_level_index[i] = -1;
- 		}
+		}
 	}
 	else
 	{
 get_object_field_start(void *state, char *fname, bool isnull)
 {
 	GetState	_state = (GetState) state;
-	bool        get_next = false;
+	bool		get_next = false;
 
 	if (_state->lex_level == 1 && _state->search_type == JSON_SEARCH_OBJECT &&
 		strcmp(fname, _state->search_term) == 0)
 	{
 		get_next = true;
 	}
-	else if (_state->search_type == JSON_SEARCH_PATH && 
+	else if (_state->search_type == JSON_SEARCH_PATH &&
 			 _state->lex_level <= _state->npath &&
 			 _state->pathok[_state->lex_level - 1] &&
 			 strcmp(fname, _state->path[_state->lex_level - 1]) == 0)
 					(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 					 errmsg("field name is not unique in json object")));
 
-		if (_state->normalize_results && 
+		if (_state->normalize_results &&
 			_state->lex->token_type == JSON_TOKEN_STRING)
 		{
 			_state->next_scalar = true;
 get_object_field_end(void *state, char *fname, bool isnull)
 {
 	GetState	_state = (GetState) state;
-	bool        get_last = false;
+	bool		get_last = false;
 
 	if (_state->lex_level == 1 && _state->search_type == JSON_SEARCH_OBJECT &&
-	 strcmp(fname, _state->search_term) == 0)
+		strcmp(fname, _state->search_term) == 0)
 	{
 		get_last = true;
 	}
-	else if (_state->search_type == JSON_SEARCH_PATH && 
+	else if (_state->search_type == JSON_SEARCH_PATH &&
 			 _state->lex_level <= _state->npath &&
 			 _state->pathok[_state->lex_level - 1] &&
 			 strcmp(fname, _state->path[_state->lex_level - 1]) == 0)
 
 		_state->tresult = cstring_to_text_with_len(_state->result_start, len);
 	}
-	/* 
-	 * don't need to reset _state->result_start b/c we're only returning one datum,
-	 * the conditions should not occur more than once, and this lets us check 
-	 * cheaply that they don't (see object_field_start() )
+
+	/*
+	 * don't need to reset _state->result_start b/c we're only returning one
+	 * datum, the conditions should not occur more than once, and this lets us
+	 * check cheaply that they don't (see object_field_start() )
 	 */
 }
 
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 				 errmsg("cannot call json_get(fieldname) on a non-object")));
-	else if (_state->search_type == JSON_SEARCH_PATH && 
+	else if (_state->search_type == JSON_SEARCH_PATH &&
 			 _state->lex_level <= _state->npath)
-		_state->array_level_index[_state->lex_level  - 1] = -1;
+		_state->array_level_index[_state->lex_level - 1] = -1;
 }
 
 static void
 get_array_element_start(void *state, bool isnull)
 {
 	GetState	_state = (GetState) state;
-	bool        get_next = false;
+	bool		get_next = false;
 
 	if (_state->lex_level == 1 && _state->search_type == JSON_SEARCH_ARRAY)
 	{
 		if (_state->array_index == _state->search_index)
 			get_next = true;
 	}
-	else if (_state->search_type == JSON_SEARCH_PATH &&  
-			 _state->lex_level <= _state->npath && 
+	else if (_state->search_type == JSON_SEARCH_PATH &&
+			 _state->lex_level <= _state->npath &&
 			 _state->pathok[_state->lex_level - 1])
 	{
-		if (++_state->array_level_index[_state->lex_level  - 1] == 
-			_state->path_level_index[_state->lex_level  - 1])
+		if (++_state->array_level_index[_state->lex_level - 1] ==
+			_state->path_level_index[_state->lex_level - 1])
 		{
-			if (_state->lex_level ==  _state->npath)
+			if (_state->lex_level == _state->npath)
 				get_next = true;
-			else 
+			else
 				_state->pathok[_state->lex_level] = true;
 		}
-		
+
 	}
 
 	if (get_next)
 	{
-		if (_state->normalize_results && 
+		if (_state->normalize_results &&
 			_state->lex->token_type == JSON_TOKEN_STRING)
 		{
 			_state->next_scalar = true;
 get_array_element_end(void *state, bool isnull)
 {
 	GetState	_state = (GetState) state;
-	bool        get_last = false;
+	bool		get_last = false;
 
 	if (_state->lex_level == 1 && _state->search_type == JSON_SEARCH_ARRAY &&
 		_state->array_index == _state->search_index)
 	{
 		get_last = true;
 	}
-	else if (_state->search_type == JSON_SEARCH_PATH && 
+	else if (_state->search_type == JSON_SEARCH_PATH &&
 			 _state->lex_level <= _state->npath &&
 			 _state->pathok[_state->lex_level - 1] &&
-			 _state->array_level_index[_state->lex_level  - 1] == 
-			 _state->path_level_index[_state->lex_level  - 1])
+			 _state->array_level_index[_state->lex_level - 1] ==
+			 _state->path_level_index[_state->lex_level - 1])
 	{
 		/* done with this element so reset pathok */
 		if (_state->lex_level < _state->npath)
 	}
 	if (get_last && _state->result_start != NULL)
 	{
-		int	len = _state->lex->prev_token_terminator - _state->result_start;
+		int			len = _state->lex->prev_token_terminator - _state->result_start;
 
 		_state->tresult = cstring_to_text_with_len(_state->result_start, len);
 	}
 {
 	GetState	_state = (GetState) state;
 
-	if (_state->lex_level == 0 && _state->search_type != JSON_SEARCH_PATH) 
+	if (_state->lex_level == 0 && _state->search_type != JSON_SEARCH_PATH)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
 				 errmsg("cannot call json_get on a scalar")));
 	text	   *json = PG_GETARG_TEXT_P(0);
 	char	   *jsonstr = text_to_cstring(json);
 
-	AlenState	   state;
+	AlenState	state;
 	JsonLexContext lex;
-	JsonSemAction  sem;
+	JsonSemAction sem;
 
 	state = palloc0(sizeof(alenState));
 	sem = palloc0(sizeof(jsonSemAction));
 
 	/* palloc0 does this for us */
-#if 0	 
+#if 0
 	state->lex_level = 0;
 	state->count = 0;
 #endif
 	lex.token_terminator = lex.input;
 	lex.line_number = 1;
 	lex.line_start = jsonstr;
-	lex.strval = NULL ; /* just counting, so this is faster */
+	lex.strval = NULL;			/* just counting, so this is faster */
 
 	pg_parse_json(&lex, sem);
 
 Datum
 json_each(PG_FUNCTION_ARGS)
 {
-
 	text	   *json = PG_GETARG_TEXT_P(0);
 	char	   *jsonstr = text_to_cstring(json);
 	JsonLexContext lex;
 	JsonSemAction sem;
 	ReturnSetInfo *rsi;
 	MemoryContext old_cxt;
-	TupleDesc   tupdesc;
+	TupleDesc	tupdesc;
 	EachState	state;
 
 	state = palloc0(sizeof(eachState));
 	old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
 
 	state->ret_tdesc = CreateTupleDescCopy(tupdesc);
-	BlessTupleDesc(	state->ret_tdesc);
-	state->tuple_store = 
+	BlessTupleDesc(state->ret_tdesc);
+	state->tuple_store =
 		tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
 							  false, work_mem);
 
 	state->lex = &lex;
 	state->lex_level = 0;
 	state->tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
-                                  "json_each temporary cxt",
-                                  ALLOCSET_DEFAULT_MINSIZE,
-                                  ALLOCSET_DEFAULT_INITSIZE,
-                                  ALLOCSET_DEFAULT_MAXSIZE);
+										   "json_each temporary cxt",
+										   ALLOCSET_DEFAULT_MINSIZE,
+										   ALLOCSET_DEFAULT_INITSIZE,
+										   ALLOCSET_DEFAULT_MAXSIZE);
 
 	pg_parse_json(&lex, sem);
-	
+
 	rsi->setResult = state->tuple_store;
 	rsi->setDesc = state->ret_tdesc;
 
 Datum
 json_each_as_text(PG_FUNCTION_ARGS)
 {
-
 	text	   *json = PG_GETARG_TEXT_P(0);
 	char	   *jsonstr = text_to_cstring(json);
 	JsonLexContext lex;
 	JsonSemAction sem;
 	ReturnSetInfo *rsi;
 	MemoryContext old_cxt;
-	TupleDesc   tupdesc;
+	TupleDesc	tupdesc;
 	EachState	state;
 
 	state = palloc0(sizeof(eachState));
 	old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
 
 	state->ret_tdesc = CreateTupleDescCopy(tupdesc);
-	BlessTupleDesc(	state->ret_tdesc);
-	state->tuple_store = 
+	BlessTupleDesc(state->ret_tdesc);
+	state->tuple_store =
 		tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
 							  false, work_mem);
 
 	state->lex = &lex;
 	state->lex_level = 0;
 	state->tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
-                                  "json_each temporary cxt",
-                                  ALLOCSET_DEFAULT_MINSIZE,
-                                  ALLOCSET_DEFAULT_INITSIZE,
-                                  ALLOCSET_DEFAULT_MAXSIZE);
+										   "json_each temporary cxt",
+										   ALLOCSET_DEFAULT_MINSIZE,
+										   ALLOCSET_DEFAULT_INITSIZE,
+										   ALLOCSET_DEFAULT_MAXSIZE);
 
 	pg_parse_json(&lex, sem);
-	
+
 	rsi->setResult = state->tuple_store;
 	rsi->setDesc = state->ret_tdesc;
 
 	PG_RETURN_NULL();
 }
 
-static void each_object_start(void *state)
+static void
+each_object_start(void *state)
 {
 	EachState	_state = (EachState) state;
 
 	_state->lex_level++;
 }
-static void each_object_end(void *state)
+static void
+each_object_end(void *state)
 {
 	EachState	_state = (EachState) state;
 
 	_state->lex_level--;
 }
-static void each_object_field_start(void *state, char *fname, bool isnull)
+static void
+each_object_field_start(void *state, char *fname, bool isnull)
 {
 	EachState	_state = (EachState) state;
 
 	/* save a pointer to where the value starts */
 	if (_state->lex_level == 1)
 	{
-		/* 
-		 * next_scalar will be reset in the object_field_end handler, and since
-		 * we know the value is a scalar there is no danger of it being on while
-		 * recursing down the tree.
+		/*
+		 * next_scalar will be reset in the object_field_end handler, and
+		 * since we know the value is a scalar there is no danger of it being
+		 * on while recursing down the tree.
 		 */
 		if (_state->normalize_results && _state->lex->token_type == JSON_TOKEN_STRING)
 			_state->next_scalar = true;
 	}
 }
 
-static void each_object_field_end(void *state, char *fname, bool isnull)
+static void
+each_object_field_end(void *state, char *fname, bool isnull)
 {
 	EachState	_state = (EachState) state;
 	MemoryContext old_cxt;
-	int len;
-	text *val;
-	HeapTuple   tuple;
-	Datum values[2];
-	static bool nulls[2] = {false,false};
+	int			len;
+	text	   *val;
+	HeapTuple	tuple;
+	Datum		values[2];
+	static bool nulls[2] = {false, false};
 
 	/* skip over nested objects */
 	if (_state->lex_level != 1)
 
 
 	tuple = heap_form_tuple(_state->ret_tdesc, values, nulls);
-	
+
 	tuplestore_puttuple(_state->tuple_store, tuple);
 
 	/* clean up and switch back */
 	MemoryContextSwitchTo(old_cxt);
-    MemoryContextReset(_state->tmp_cxt);
+	MemoryContextReset(_state->tmp_cxt);
 }
 
-static void each_array_start(void *state)
+static void
+each_array_start(void *state)
 {
 	EachState	_state = (EachState) state;
 
 				 errmsg("cannot call json_each on an array")));
 }
 
-static void each_scalar(void *state, char *token, JsonTokenType tokentype)
+static void
+each_scalar(void *state, char *token, JsonTokenType tokentype)
 {
 	EachState	_state = (EachState) state;
 
 Datum
 json_unnest(PG_FUNCTION_ARGS)
 {
-
 	text	   *json = PG_GETARG_TEXT_P(0);
 	char	   *jsonstr = text_to_cstring(json);
 	JsonLexContext lex;
 	JsonSemAction sem;
 	ReturnSetInfo *rsi;
 	MemoryContext old_cxt;
-	TupleDesc   tupdesc;
-	UnnestState	state;
+	TupleDesc	tupdesc;
+	UnnestState state;
 
 	state = palloc0(sizeof(unnestState));
 	sem = palloc0(sizeof(jsonSemAction));
 	old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
 
 	state->ret_tdesc = CreateTupleDescCopy(tupdesc);
-	BlessTupleDesc(	state->ret_tdesc);
-	state->tuple_store = 
+	BlessTupleDesc(state->ret_tdesc);
+	state->tuple_store =
 		tuplestore_begin_heap(rsi->allowedModes & SFRM_Materialize_Random,
 							  false, work_mem);
 
 	state->lex = &lex;
 	state->lex_level = 0;
 	state->tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
-                                  "json_unnest temporary cxt",
-                                  ALLOCSET_DEFAULT_MINSIZE,
-                                  ALLOCSET_DEFAULT_INITSIZE,
-                                  ALLOCSET_DEFAULT_MAXSIZE);
+										   "json_unnest temporary cxt",
+										   ALLOCSET_DEFAULT_MINSIZE,
+										   ALLOCSET_DEFAULT_INITSIZE,
+										   ALLOCSET_DEFAULT_MAXSIZE);
 
 	pg_parse_json(&lex, sem);
-	
+
 	rsi->setResult = state->tuple_store;
 	rsi->setDesc = state->ret_tdesc;
 
 	PG_RETURN_NULL();
 }
 
-static void unnest_array_start(void *state)
+static void
+unnest_array_start(void *state)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 
 	_state->lex_level++;
 }
 
-static void unnest_array_end(void *state)
+static void
+unnest_array_end(void *state)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 
 	_state->lex_level--;
 }
 
-static void unnest_array_element_start(void *state, bool isnull)
+static void
+unnest_array_element_start(void *state, bool isnull)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 
 	/* save a pointer to where the value starts */
 	if (_state->lex_level == 1)
 		_state->result_start = _state->lex->token_start;
 }
 
-static void unnest_array_element_end(void *state, bool isnull)
+static void
+unnest_array_element_end(void *state, bool isnull)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 	MemoryContext old_cxt;
-	int len;
-	text *val;
-	HeapTuple   tuple;
-	Datum values[1];
+	int			len;
+	text	   *val;
+	HeapTuple	tuple;
+	Datum		values[1];
 	static bool nulls[1] = {false};
 
 	/* skip over nested objects */
 	values[0] = PointerGetDatum(val);
 
 	tuple = heap_form_tuple(_state->ret_tdesc, values, nulls);
-	
+
 	tuplestore_puttuple(_state->tuple_store, tuple);
 
 	/* clean up and switch back */
 	MemoryContextSwitchTo(old_cxt);
-    MemoryContextReset(_state->tmp_cxt);
+	MemoryContextReset(_state->tmp_cxt);
 }
 
-static void unnest_object_start(void *state)
+static void
+unnest_object_start(void *state)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 
 	if (_state->lex_level == 0)
 		ereport(ERROR,
 				 errmsg("cannot call json_unnest on an object")));
 }
 
-static void unnest_scalar(void *state, char *token, JsonTokenType tokentype)
+static void
+unnest_scalar(void *state, char *token, JsonTokenType tokentype)
 {
-	UnnestState	_state = (UnnestState) state;
+	UnnestState _state = (UnnestState) state;
 
 	if (_state->lex_level == 0)
 		ereport(ERROR,
 	Oid			argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
 	text	   *json = PG_GETARG_TEXT_P(1);
 	char	   *jsonstr = text_to_cstring(json);
-	HTAB       *json_hash;
+	HTAB	   *json_hash;
 	HeapTupleHeader rec;
 	Oid			tupType;
 	int32		tupTypmod;
 	int			i;
 	Datum	   *values;
 	bool	   *nulls;
-	char       fname[NAMEDATALEN];
+	char		fname[NAMEDATALEN];
 	JsonHashEntry hashentry;
-	
+
 
 	if (!type_is_rowtype(argtype))
 		ereport(ERROR,
 		tupTypmod = HeapTupleHeaderGetTypMod(rec);
 	}
 
-	json_hash = get_json_object_as_hash(jsonstr,"json_populate_record");
+	json_hash = get_json_object_as_hash(jsonstr, "json_populate_record");
 
 	/*
 	 * if the input hstore is empty, we can only skip the rest if we were
 	 */
 	if (hash_get_num_entries(json_hash) == 0 && rec)
 		PG_RETURN_POINTER(rec);
-		
-	
+
+
 	tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
 	ncolumns = tupdesc->natts;
 
  * error messages.
  */
 static HTAB *
-get_json_object_as_hash(char * jsonstr, char *funcname)
+get_json_object_as_hash(char *jsonstr, char *funcname)
 {
-
-	HASHCTL     ctl;
-	HTAB       *tab;
-	JHashState	   state;
+	HASHCTL		ctl;
+	HTAB	   *tab;
+	JHashState	state;
 	JsonLexContext lex;
-	JsonSemAction  sem;
+	JsonSemAction sem;
 
 
 	memset(&ctl, 0, sizeof(ctl));
-    ctl.keysize = NAMEDATALEN;
-    ctl.entrysize = sizeof(jsonHashEntry);
+	ctl.keysize = NAMEDATALEN;
+	ctl.entrysize = sizeof(jsonHashEntry);
 	tab = hash_create("json object hashtable",
 					  100,
 					  &ctl,
 	sem = palloc0(sizeof(jsonSemAction));
 
 	/* palloc0 does this for us */
-#if 0	 
+#if 0
 	state->lex_level = 0;
 #endif
 
 	return tab;
 }
 
-static void hash_object_start(void *state)
+static void
+hash_object_start(void *state)
 {
 	JHashState	_state = (JHashState) state;
 
 	_state->lex_level++;
 }
 
-static void hash_object_field_start(void *state, char *fname, bool isnull)
+static void
+hash_object_field_start(void *state, char *fname, bool isnull)
 {
 	JHashState	_state = (JHashState) state;
 
 	{
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-				 errmsg("cannot call %s on a nested object", _state->function_name)));
+		errmsg("cannot call %s on a nested object", _state->function_name)));
 	}
 }
 
-static void hash_object_field_end(void *state, char *fname, bool isnull)
+static void
+hash_object_field_end(void *state, char *fname, bool isnull)
 {
 	JHashState	_state = (JHashState) state;
 	JsonHashEntry hashentry;
-	bool          found;
-	char          name[NAMEDATALEN];
+	bool		found;
+	char		name[NAMEDATALEN];
 
-	memset(name,0,NAMEDATALEN);
-	strncpy(name,fname, NAMEDATALEN);
+	memset(name, 0, NAMEDATALEN);
+	strncpy(name, fname, NAMEDATALEN);
 
 	hashentry = hash_search(_state->hash, name, HASH_ENTER, &found);
 
 	if (found)
-		elog(ERROR,"duplicate key");
+		elog(ERROR, "duplicate key");
 
 	hashentry->isnull = isnull;
 	hashentry->val = _state->saved_scalar;
 }
 
-static void hash_array_start(void *state)
+static void
+hash_array_start(void *state)
 {
 	JHashState	_state = (JHashState) state;
 
 	if (_state->lex_level == 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-				 errmsg("cannot call %s on an array", _state->function_name)));
+			   errmsg("cannot call %s on an array", _state->function_name)));
 }
 
-static void hash_scalar(void *state, char *token, JsonTokenType tokentype)
+static void
+hash_scalar(void *state, char *token, JsonTokenType tokentype)
 {
 	JHashState	_state = (JHashState) state;
 
 	if (_state->lex_level == 0)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-				 errmsg("cannot call %s on an array", _state->function_name)));
+			   errmsg("cannot call %s on an array", _state->function_name)));
 
 	_state->saved_scalar = token;
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.