mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	properties: just use the parser in all cases
We can just use the json parser to parse the old key=val syntax as well now.
This commit is contained in:
		
							parent
							
								
									f29bc42b4d
								
							
						
					
					
						commit
						2fd35488c7
					
				
					 2 changed files with 21 additions and 42 deletions
				
			
		| 
						 | 
				
			
			@ -150,11 +150,12 @@ int pw_properties_update_string(struct pw_properties *props, const char *str, si
 | 
			
		|||
{
 | 
			
		||||
	struct properties *impl = SPA_CONTAINER_OF(props, struct properties, this);
 | 
			
		||||
	struct spa_json it[2];
 | 
			
		||||
	char key[1024], *val;
 | 
			
		||||
	int count = 0;
 | 
			
		||||
 | 
			
		||||
	spa_json_init(&it[0], str, size);
 | 
			
		||||
	if (spa_json_enter_object(&it[0], &it[1]) > 0) {
 | 
			
		||||
		char key[1024], *val;
 | 
			
		||||
	if (spa_json_enter_object(&it[0], &it[1]) <= 0)
 | 
			
		||||
		spa_json_init(&it[1], str, size);
 | 
			
		||||
 | 
			
		||||
	while (spa_json_get_string(&it[1], key, sizeof(key)-1)) {
 | 
			
		||||
		int len;
 | 
			
		||||
| 
						 | 
				
			
			@ -180,28 +181,6 @@ int pw_properties_update_string(struct pw_properties *props, const char *str, si
 | 
			
		|||
		count += pw_properties_set(&impl->this, key, val);
 | 
			
		||||
		free(val);
 | 
			
		||||
	}
 | 
			
		||||
	} else {
 | 
			
		||||
		const char *state = NULL, *s = NULL;
 | 
			
		||||
		size_t len;
 | 
			
		||||
 | 
			
		||||
		s = pw_split_walk(str, " \t\n\r", &len, &state);
 | 
			
		||||
		while (s) {
 | 
			
		||||
			char *val, *eq;
 | 
			
		||||
 | 
			
		||||
			if (s[0] == '#')
 | 
			
		||||
				continue;
 | 
			
		||||
			if ((val = strndup(s, len)) == NULL)
 | 
			
		||||
				return -errno;
 | 
			
		||||
 | 
			
		||||
			eq = strchr(val, '=');
 | 
			
		||||
			if (eq && eq != val) {
 | 
			
		||||
				*eq = '\0';
 | 
			
		||||
				count += pw_properties_set(&impl->this, val, eq+1);
 | 
			
		||||
			}
 | 
			
		||||
			free(val);
 | 
			
		||||
			s = pw_split_walk(str, " \t\n\r", &len, &state);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -211,7 +211,7 @@ static void test_new_string(void)
 | 
			
		|||
{
 | 
			
		||||
	struct pw_properties *props;
 | 
			
		||||
 | 
			
		||||
	props = pw_properties_new_string("foo=bar bar=baz ignore him=too empty= =gg");
 | 
			
		||||
	props = pw_properties_new_string("foo=bar bar=baz \"#ignore\"=ignore him=too empty=\"\" =gg");
 | 
			
		||||
	spa_assert(props != NULL);
 | 
			
		||||
	spa_assert(props->flags == 0);
 | 
			
		||||
	spa_assert(props->dict.n_items == 4);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue