zabbix-agent2/src/libs/zbxjson/json.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_json_copy_string                                             *
 *                                                                            *
 * Purpose: copies json name/string value by omitting leading/trailing " and  *
 *          converting escape sequences                                       *
 *                                                                            *
 * Parameters: p     - [IN] a pointer to the next character in string         *
 *             out   - [OUT] the output buffer                                *
 *             size  - [IN] the output buffer size                            *
 *                                                                            *
 * Return value: A pointer to the next character in input string or NULL if   *
 *               string copying failed.                                       *
 *                                                                            *
 ******************************************************************************/
zbx_json_copy_string

Purpose: copies json name/string value by omitting leading/trailing " and
converting escape sequences

Parameters: p     - [IN] a pointer to the next character in string
out   - [OUT] the output buffer
size  - [IN] the output buffer size

Return value: A pointer to the next character in input string or NULL if
string copying failed.
zbx_json_copy_string Purpose : copies json name / string value by omitting leading / trailing " and converting escape sequences Parameters : p - [ IN ] a pointer to the next character in string out - [ OUT ] the output buffer size - [ IN ] the output buffer size Return value : A pointer to the next character in input string or NULL if string copying failed .
static const char	*zbx_json_copy_string(const char *p, char *out, size_t size)
{
	char	*start = out;
	if (0 == size)
		return NULL;
	p++;
	while ('\0' != *p)
	{
		unsigned int	nbytes, i;
		unsigned char	uc[4];	
		switch (*p)
		{
			case '\\':
				++p;
				if (0 == (nbytes = zbx_json_decode_character(&p, uc)))
					return NULL;
				if ((size_t)(out - start) + nbytes >= size)
					return NULL;
				for (i = 0; i < nbytes; ++i)
					*out++ = (char)uc[i];
				break;
			case '"':
				*out = '\0';
				return ++p;
			default:
				*out++ = *p++;
		}
		if ((size_t)(out - start) == size)
			break;
	}
	return NULL;
}
static const char * zbx_json_copy_string ( const char * p , char * out , size_t size ) { char * start = out ; if ( 0 == size ) return NULL ; p ++ ; while ( ' \0 ' != * p ) { unsigned int nbytes , i ; unsigned char uc [ 4 ] ; switch ( * p ) { case ' \\ ' : ++ p ; if ( 0 == ( nbytes = zbx_json_decode_character ( & p , uc ) ) ) return NULL ; if ( ( size_t ) ( out - start ) + nbytes >= size ) return NULL ; for ( i = 0 ; i < nbytes ; ++ i ) * out ++ = ( char ) uc [ i ] ; break ; case ' ' : * out = ' \0 ' ; return ++ p ; default : * out ++ = * p ++ ; } if ( ( size_t ) ( out - start ) == size ) break ; } return NULL ; }
Function: zbx_json_copy_string                                             
                                                                            
 Purpose: copies json name/string value by omitting leading/trailing " and  
          converting escape sequences                                       
                                                                            
 Parameters: p     - [IN] a pointer to the next character in string         
             out   - [OUT] the output buffer                                
             size  - [IN] the output buffer size                            
                                                                            
 Return value: A pointer to the next character in input string or NULL if   
               string copying failed.
Function : zbx_json_copy_string Purpose : copies json name / string value by omitting leading / trailing " and converting escape sequences Parameters : p - [ IN ] a pointer to the next character in string out - [ OUT ] the output buffer size - [ IN ] the output buffer size Return value : A pointer to the next character in input string or NULL if string copying failed .
/* decoded Unicode character takes 1-4 bytes in UTF-8 */