zabbix-agent2/src/libs/zbxjson/json.c
/******************************************************************************
 *                                                                            *
 * Function: __zbx_json_rbracket                                              *
 *                                                                            *
 * Purpose: return position of right bracket                                  *
 *                                                                            *
 * Return value: position of right bracket                                    *
 *               NULL - an error occurred                                     *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 ******************************************************************************/
zbx_json_rbracket

Purpose: return position of right bracket

Return value: position of right bracket
NULL - an error occurred

Author: Alexander Vladishev
zbx_json_rbracket Purpose : return position of right bracket Return value : position of right bracket NULL - an error occurred Author : Alexander Vladishev
static const char	*__zbx_json_rbracket(const char *p)
{
	int	level = 0;
	int	state = 0; 
	char	lbracket, rbracket;
	assert(p);
	lbracket = *p;
	if ('{' != lbracket && '[' != lbracket)
		return NULL;
	rbracket = ('{' == lbracket ? '}' : ']');
	while ('\0' != *p)
	{
		switch (*p)
		{
			case '"':
				state = (0 == state ? 1 : 0);
				break;
			case '\\':
				if (1 == state)
					if ('\0' == *++p)
						return NULL;
				break;
			case '[':
			case '{':
				if (0 == state)
					level++;
				break;
			case ']':
			case '}':
				if (0 == state)
				{
					level--;
					if (0 == level)
						return (rbracket == *p ? p : NULL);
				}
				break;
		}
		p++;
	}
	return NULL;
}
static const char * __zbx_json_rbracket ( const char * p ) { int level = 0 ; int state = 0 ; char lbracket , rbracket ; assert ( p ) ; lbracket = * p ; if ( ' ' != lbracket && ' ' != lbracket ) return NULL ; rbracket = ( ' ' == lbracket ? ' ' : ' ' ) ; while ( ' \0 ' != * p ) { switch ( * p ) { case ' ' : state = ( 0 == state ? 1 : 0 ) ; break ; case ' \\ ' : if ( 1 == state ) if ( ' \0 ' == * ++ p ) return NULL ; break ; case ' ' : case ' ' : if ( 0 == state ) level ++ ; break ; case ' ' : case ' ' : if ( 0 == state ) { level -- ; if ( 0 == level ) return ( rbracket == * p ? p : NULL ) ; } break ; } p ++ ; } return NULL ; }
Function: __zbx_json_rbracket                                              
                                                                            
 Purpose: return position of right bracket                                  
                                                                            
 Return value: position of right bracket                                    
               NULL - an error occurred                                     
                                                                            
 Author: Alexander Vladishev
Function : __zbx_json_rbracket Purpose : return position of right bracket Return value : position of right bracket NULL - an error occurred Author : Alexander Vladishev
/* 0 - outside string; 1 - inside string */