void wi_test_string_encoding_creation(void) {
#ifdef WI_STRING_ENCODING
    wi_string_encoding_t    *encoding;
    
    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), 0);
    
    WI_TEST_ASSERT_NOT_NULL(encoding, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_encoding_charset(encoding), WI_STR("ASCII"), "");
    WI_TEST_ASSERT_EQUALS(wi_string_encoding_options(encoding), 0, "");
    
    encoding = wi_string_encoding_with_charset(WI_STR("ASCII"), WI_STRING_ENCODING_IGNORE);
    
    WI_TEST_ASSERT_NOT_NULL(encoding, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_string_encoding_charset(encoding), WI_STR("ASCII"), "");
    WI_TEST_ASSERT_EQUALS(wi_string_encoding_options(encoding), WI_STRING_ENCODING_IGNORE, "");
#endif
}
Exemplo n.º 2
0
static void wr_command_save(wi_array_t *arguments) {
	wi_file_t		*file;
	wi_string_t		*path, *login, *password, *port;
	
	path = wi_user_home();
	path = wi_string_by_appending_path_component(path, WI_STR(WB_WIREBOT_USER_PATH));
	path = wi_string_by_appending_path_component(path, WI_ARRAY(arguments, 0));
	
	file = wi_file_for_writing(path);
	
	if(!file) {
		wr_printf_prefix(WI_STR("save: %@: %m"), path);
		
		return;
	}
	
	wi_file_write_format(file, WI_STR("charset %@\n"), wi_string_encoding_charset(wr_client_string_encoding));
	wi_file_write_format(file, WI_STR("timestamp %@\n"), wr_timestamp_format);
	wi_file_write_format(file, WI_STR("nick %@\n"), wr_nick);
	
	if(wi_string_length(wr_status) > 0)
		wi_file_write_format(file, WI_STR("status %@\n"), wr_status);
	
	if(wr_icon_path)
		wi_file_write_format(file, WI_STR("icon %@\n"), wr_icon_path);
	
	if(wr_connected) {
		if(wi_string_length(wi_p7_socket_user_name(wr_p7_socket)) > 0)
			login = wi_string_with_format(WI_STR("-l %@"), wi_p7_socket_user_name(wr_p7_socket));
		else
			login = NULL;
		
		if(wi_string_length(wr_password) > 0)
			password = wi_string_with_format(WI_STR("-p %@"), wr_password);
		else
			password = NULL;
		
		if(wi_address_port(wi_socket_address(wr_socket)) != WR_PORT)
			port = wi_string_with_format(WI_STR("-P %u"), wi_address_port(wi_socket_address(wr_socket)));
		else
			port = NULL;
		
		wi_file_write_format(file, WI_STR("open %#@ %#@ %#@ %@\n"),
			login, password, port, wi_address_string(wi_socket_address(wr_socket)));
	}
	
	wr_printf_prefix(WI_STR("save: \"%@\" saved"), path);
}
Exemplo n.º 3
0
wi_boolean_t wr_client_set_charset(wi_string_t *charset) {
	wi_string_encoding_t	*encoding;
	wi_integer_t			options;
	
	if(wr_client_string_encoding && wi_is_equal(charset, wi_string_encoding_charset(wr_client_string_encoding)))
		return true;
	
	options = WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE;
	encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(),
													charset,
													options);
	
	if(!encoding)
		return false;

	wi_release(wr_client_string_encoding);
	wr_client_string_encoding = encoding;
	
	wr_printf_prefix(WI_STR("Using character set %@"), charset);
	
	return true;
}