Beispiel #1
0
static wi_string_t * _wi_set_description(wi_runtime_instance_t *instance) {
	wi_set_t				*set = instance;
	_wi_set_bucket_t		*bucket;
	wi_mutable_string_t		*string;
	wi_string_t				*description;
	wi_uinteger_t			i;

	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{count = %lu, mutable = %u, values = (\n"),
		wi_runtime_class_name(set),
		set,
		set->data_count,
		wi_runtime_options(set) & WI_RUNTIME_OPTION_MUTABLE ? 1 : 0);

	for(i = 0; i < set->buckets_count; i++) {
		for(bucket = set->buckets[i]; bucket; bucket = bucket->next) {
			if(set->callbacks.description)
				description = (*set->callbacks.description)(bucket->data);
			else
				description = wi_string_with_format(WI_STR("%p"), bucket->data);

			wi_mutable_string_append_format(string, WI_STR("    %@\n"), description);
		}
	}
	
	wi_mutable_string_append_string(string, WI_STR(")}"));
	
	wi_runtime_make_immutable(string);

	return string;
}
Beispiel #2
0
static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) {
	wi_p7_message_t			*p7_message = instance;
	wi_enumerator_t			*enumerator;
	wi_dictionary_t			*fields;
	wi_mutable_string_t		*string;
	wi_string_t				*field_name, *field_value;
	
	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{name = %@, buffer = %@, fields = (\n"),
        wi_runtime_class_name(p7_message),
        p7_message,
		p7_message->name,
		wi_data_with_bytes_no_copy(p7_message->binary_buffer, p7_message->binary_size, false));
	
	fields		= wi_p7_message_fields(p7_message);
	enumerator	= wi_dictionary_key_enumerator(fields);
	
	while((field_name = wi_enumerator_next_data(enumerator))) {
		field_value = wi_dictionary_data_for_key(fields, field_name);

		wi_mutable_string_append_format(string, WI_STR("    %@ = %@\n"),
			field_name, field_value);
	}
	
	wi_mutable_string_append_string(string, WI_STR(")}"));
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Beispiel #3
0
static wi_string_t * _wi_dictionary_description(wi_runtime_instance_t *instance) {
    wi_dictionary_t             *dictionary = instance;
    _wi_dictionary_bucket_t     *bucket;
    wi_mutable_string_t         *string;
    wi_string_t                 *key_description, *value_description;
    wi_uinteger_t               i;

    string = wi_mutable_string_with_format(WI_STR("<%@ %p>{count = %lu, mutable = %u, values = (\n"),
                                           wi_runtime_class_name(dictionary),
                                           dictionary,
                                           dictionary->key_count,
                                           wi_runtime_options(dictionary) & WI_RUNTIME_OPTION_MUTABLE ? 1 : 0);

    for(i = 0; i < dictionary->buckets_count; i++) {
        for(bucket = dictionary->buckets[i]; bucket; bucket = bucket->next) {
            if(dictionary->key_callbacks.description)
                key_description = (*dictionary->key_callbacks.description)(bucket->key);
            else
                key_description = wi_string_with_format(WI_STR("%p"), bucket->key);

            if(dictionary->value_callbacks.description)
                value_description = (*dictionary->value_callbacks.description)(bucket->data);
            else
                value_description = wi_string_with_format(WI_STR("%p"), bucket->data);

            wi_mutable_string_append_format(string, WI_STR("    %@: %@\n"), key_description, value_description);
        }
    }

    wi_mutable_string_append_string(string, WI_STR(")}"));

    wi_runtime_make_immutable(string);

    return string;
}
Beispiel #4
0
void wr_draw_transfers(wi_boolean_t force) {
	static wi_time_interval_t	update;
	wi_enumerator_t				*enumerator;
	wi_mutable_string_t			*string;
    wi_string_t					*status;
	wr_transfer_t				*transfer;
	wi_time_interval_t			interval;
	wi_uinteger_t				i = 0;
	
	interval = wi_time_interval();
	
	if(!force && interval - update < 1.0)
		return;
	
	update = interval;
	
	wi_terminal_set_scroll(wr_terminal, wi_make_range(1 + wi_array_count(wr_transfers),
													  wi_terminal_size(wr_terminal).height - 4));
	
	enumerator = wi_array_data_enumerator(wr_transfers);
	
	while((transfer = wi_enumerator_next_data(enumerator))) {
		wi_terminal_move(wr_terminal, wi_make_point(0, i + 1));
		wi_terminal_clear_line(wr_terminal);
		
		if(transfer->state == WR_TRANSFER_RUNNING && interval - transfer->start_time > 0.0) {
			transfer->speed = ((double) transfer->total_transferred - transfer->total_offset) / (interval - transfer->start_time);
			
			status = wi_string_with_format(WI_STR("%@/%@, %@/s"),
                                           wr_files_string_for_size(transfer->total_transferred),
                                           wr_files_string_for_size(transfer->total_size),
                                           wr_files_string_for_size(transfer->speed));
		}
		else if(transfer->state == WR_TRANSFER_QUEUED) {
			status = wi_string_with_format(WI_STR("queued at %u"),
                                           transfer->queue);
		}
		else {
			status = wi_string_with_cstring("waiting");
		}
		
		string = wi_mutable_string_with_format(WI_STR("%u %3.0f%%  %@"),
                                               transfer->tid,
                                               transfer->total_size > 0
                                               ? 100 * ((double) transfer->total_transferred / (double) transfer->total_size)
                                               : 0,
                                               transfer->name);
		
		wi_terminal_adjust_string_to_fit_width(wr_terminal, string);
		wi_mutable_string_delete_characters_from_index(string, wi_string_length(string) - wi_string_length(status));
		wi_mutable_string_append_string(string, status);
		
		wi_terminal_printf(wr_terminal, WI_STR("%@"), string);
		
		i++;
	}
	
	wr_terminal_reset_location();
}
void wi_test_regexp_replacing_by_mutating(void) {
    wi_regexp_t             *regexp;
    wi_mutable_string_t     *string;
    wi_uinteger_t           count;
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR(""));
    
    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("heo word"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("x"));

    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxo worxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("l"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("xxx"));
    
    WI_TEST_ASSERT_EQUALS(count, 3U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hexxxxxxo worxxxd"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("hi $1"));
    
    WI_TEST_ASSERT_EQUALS(count, 1U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi world"), "");
    
    regexp = wi_regexp_with_pattern(WI_STR("hello (world)"), 0);
    string = wi_mutable_string_with_format(WI_STR("hello world"));
    count = wi_regexp_replace_matches_in_string(regexp, string, WI_STR("hi $0"));
    
    WI_TEST_ASSERT_EQUALS(count, 1U, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(string, WI_STR("hi hello world"), "");
}
Beispiel #6
0
static wi_string_t * _wi_number_description(wi_runtime_instance_t *instance) {
	wi_number_t				*number = instance;
	wi_mutable_string_t		*string;
	
	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{value = "),
		wi_runtime_class_name(number),
		number);
	
	if(_wi_number_is_float(number))
		wi_mutable_string_append_format(string, WI_STR("%f"), wi_number_double(number));
	else
		wi_mutable_string_append_format(string, WI_STR("%lld"), wi_number_int64(number));
	
	wi_mutable_string_append_string(string, WI_STR("}"));
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Beispiel #7
0
void wr_draw_divider(void) {
	wi_enumerator_t			*enumerator;
	wi_mutable_string_t		*string, *action;
	wi_string_t				*position;
	wr_window_t				*window;
	wi_size_t				size;
	wi_range_t				scroll;
	wi_point_t				location;
	const char				*color;
	wi_uinteger_t			users, line, lines, windows;
	
	string = wi_mutable_string_with_format(WI_STR("%s%@"), WR_PREFIX, wr_nick);
	
	if(wr_connected && wr_server) {
		users = wi_array_count(wr_chat_users(wr_console_window->chat));
		
		wi_mutable_string_append_format(string, WI_STR(" - %@ - %u %@"),
										wr_server_name(wr_server),
										users,
										users == 1
											? WI_STR("user")
											: WI_STR("users"));
	}
	
	action = wi_mutable_string();
	windows = 0;
	
	enumerator = wi_array_data_enumerator(wr_windows);
	
	while((window = wi_enumerator_next_data(enumerator))) {
		switch(window->status) {
			case WR_WINDOW_STATUS_ACTION:
				color = WR_INTERFACE_COLOR;
				break;

			case WR_WINDOW_STATUS_CHAT:
				color = WR_STATUS_COLOR;
				break;

			case WR_WINDOW_STATUS_HIGHLIGHT:
				color = WR_HIGHLIGHT_COLOR;
				break;
				
			default:
				color = NULL;
				break;
		}
		
		if(color) {
			if(windows > 0)
				wi_mutable_string_append_string(action, WI_STR(","));
			
			wi_mutable_string_append_format(action, WI_STR("%s%s%s%u%s%s"),
				WR_TERMINATE_COLOR,
				WR_INTERFACE_COLOR,
				color,
				window->wid,
				WR_TERMINATE_COLOR,
				WR_INTERFACE_COLOR);
			
			windows++;
		}
	}

	if(windows > 0)
		wi_mutable_string_append_format(string, WI_STR(" [%@]"), action);
	
	line = wi_terminal_buffer_current_line(wr_current_window->buffer);
	lines = wi_terminal_buffer_lines(wr_current_window->buffer);
	scroll = wi_terminal_scroll(wr_terminal);
	
	if(lines == 0 || line == lines)
		position = NULL;
	else if(line <= scroll.length)
		position = wi_string_with_cstring("TOP");
	else
		position = wi_string_with_format(WI_STR("%.0f%%"), 100 * ((double) (line - scroll.length)  / (double) lines));
	
	wi_terminal_adjust_string_to_fit_width(wr_terminal, string);
	
	if(position) {
		wi_mutable_string_delete_characters_from_index(string, wi_string_length(string) - wi_string_length(position));
		wi_mutable_string_append_string(string, position);
	}

	size = wi_terminal_size(wr_terminal);

	location = wi_terminal_location(wr_terminal);
	wi_terminal_move_printf(wr_terminal, wi_make_point(0, size.height - 3), WI_STR("%s%@%s"),
		WR_INTERFACE_COLOR,
		string,
		WR_TERMINATE_COLOR);
	wi_terminal_move(wr_terminal, location);
}