Exemplo n.º 1
0
void
gui_input_delete_beginning_of_line ()
{
    int length_deleted, size_deleted, pos_start;
    char *start;
    
    if (gui_current_window->buffer->input)
    {
        if (gui_current_window->buffer->input_buffer_pos > 0)
        {
            start = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                     gui_current_window->buffer->input_buffer_pos);
            pos_start = start - gui_current_window->buffer->input_buffer;
            size_deleted = start - gui_current_window->buffer->input_buffer;
            length_deleted = utf8_strnlen (gui_current_window->buffer->input_buffer, size_deleted);
            gui_input_clipboard_copy (gui_current_window->buffer->input_buffer,
                                      start - gui_current_window->buffer->input_buffer);
            
            gui_input_move (gui_current_window->buffer, gui_current_window->buffer->input_buffer, start, strlen (start));
            
            gui_current_window->buffer->input_buffer_size -= size_deleted;
            gui_current_window->buffer->input_buffer_length -= length_deleted;
            gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0';
            gui_current_window->buffer->input_buffer_pos = 0;
            gui_input_optimize_size (gui_current_window->buffer);
            gui_completion_stop (gui_current_window->buffer->completion, 1);
            gui_input_text_changed_modifier_and_signal (gui_current_window->buffer);
        }
    }
}
Exemplo n.º 2
0
void
gui_input_delete_previous_word ()
{
    int length_deleted, size_deleted;
    char *start, *string;
    
    if (gui_current_window->buffer->input)
    {
        if (gui_current_window->buffer->input_buffer_pos > 0)
        {
            start = utf8_add_offset (gui_current_window->buffer->input_buffer,
                                      gui_current_window->buffer->input_buffer_pos - 1);
            string = start;
            while (string && (string[0] == ' '))
            {
                string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
            }
            if (string)
            {
                while (string && (string[0] != ' '))
                {
                    string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
                }
                if (string)
                {
                    while (string && (string[0] == ' '))
                    {
                        string = utf8_prev_char (gui_current_window->buffer->input_buffer, string);
                    }
                }
            }
            
            if (string)
                string = utf8_next_char (utf8_next_char (string));
            else
                string = gui_current_window->buffer->input_buffer;
            
            size_deleted = utf8_next_char (start) - string;
            length_deleted = utf8_strnlen (string, size_deleted);
            
            gui_input_clipboard_copy (string, size_deleted);
            
            gui_input_move (gui_current_window->buffer, string, string + size_deleted, strlen (string + size_deleted));
            
            gui_current_window->buffer->input_buffer_size -= size_deleted;
            gui_current_window->buffer->input_buffer_length -= length_deleted;
            gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0';
            gui_current_window->buffer->input_buffer_pos -= length_deleted;
            gui_input_optimize_size (gui_current_window->buffer);
            gui_completion_stop (gui_current_window->buffer->completion, 1);
            gui_input_text_changed_modifier_and_signal (gui_current_window->buffer);
        }
    }
}
Exemplo n.º 3
0
TEST(Utf8, Size)
{
    /* char size */
    LONGS_EQUAL(0, utf8_char_size (NULL));
    LONGS_EQUAL(1, utf8_char_size (""));
    LONGS_EQUAL(1, utf8_char_size ("A"));
    LONGS_EQUAL(2, utf8_char_size ("ë"));
    LONGS_EQUAL(3, utf8_char_size ("€"));
    LONGS_EQUAL(4, utf8_char_size (han_char));

    /* char size on screen */
    LONGS_EQUAL(0, utf8_char_size_screen (NULL));
    LONGS_EQUAL(0, utf8_char_size_screen (""));
    LONGS_EQUAL(1, utf8_char_size_screen ("A"));
    LONGS_EQUAL(1, utf8_char_size_screen ("ë"));
    LONGS_EQUAL(1, utf8_char_size_screen ("€"));
    /* this test does not work on Ubuntu Precise: it returns 2 instead of 1 */
    /*LONGS_EQUAL(1, utf8_char_size_screen (han_char));*/

    /* length of string (in chars) */
    LONGS_EQUAL(0, utf8_strlen (NULL));
    LONGS_EQUAL(0, utf8_strlen (""));
    LONGS_EQUAL(1, utf8_strlen ("A"));
    LONGS_EQUAL(1, utf8_strlen ("ë"));
    LONGS_EQUAL(1, utf8_strlen ("€"));
    LONGS_EQUAL(1, utf8_strlen (han_char));

    /* length of string (in chars, for max N bytes) */
    LONGS_EQUAL(0, utf8_strnlen (NULL, 0));
    LONGS_EQUAL(0, utf8_strnlen ("", 0));
    LONGS_EQUAL(1, utf8_strnlen ("AZ", 1));
    LONGS_EQUAL(1, utf8_strnlen ("ëZ", 2));
    LONGS_EQUAL(1, utf8_strnlen ("€Z", 3));
    LONGS_EQUAL(1, utf8_strnlen (han_char_z, 4));

    /* length of string on screen (in chars) */
    LONGS_EQUAL(0, utf8_strlen_screen (NULL));
    LONGS_EQUAL(0, utf8_strlen_screen (""));
    LONGS_EQUAL(1, utf8_strlen_screen ("A"));
    LONGS_EQUAL(1, utf8_strlen_screen ("ë"));
    LONGS_EQUAL(1, utf8_strlen_screen ("€"));
    /* this test does not work on Ubuntu Precise: it returns 2 instead of 1 */
    /*LONGS_EQUAL(1, utf8_strlen_screen (han_char));*/
    LONGS_EQUAL(1, utf8_strlen_screen ("\x7f"));
}
Exemplo n.º 4
0
TEST(CoreUtf8, Size)
{
    /* char size */
    LONGS_EQUAL(0, utf8_char_size (NULL));
    LONGS_EQUAL(1, utf8_char_size (""));
    LONGS_EQUAL(1, utf8_char_size ("A"));
    LONGS_EQUAL(2, utf8_char_size ("ë"));
    LONGS_EQUAL(3, utf8_char_size ("€"));
    LONGS_EQUAL(3, utf8_char_size (cjk_yellow));
    LONGS_EQUAL(4, utf8_char_size (han_char));

    /* char size on screen */
    LONGS_EQUAL(0, utf8_char_size_screen (NULL));
    LONGS_EQUAL(0, utf8_char_size_screen (""));
    LONGS_EQUAL(1, utf8_char_size_screen ("A"));
    LONGS_EQUAL(1, utf8_char_size_screen ("ë"));
    LONGS_EQUAL(1, utf8_char_size_screen ("€"));
    LONGS_EQUAL(2, utf8_char_size_screen (cjk_yellow));

    /* length of string (in chars) */
    LONGS_EQUAL(0, utf8_strlen (NULL));
    LONGS_EQUAL(0, utf8_strlen (""));
    LONGS_EQUAL(1, utf8_strlen ("A"));
    LONGS_EQUAL(1, utf8_strlen ("ë"));
    LONGS_EQUAL(1, utf8_strlen ("€"));
    LONGS_EQUAL(1, utf8_strlen (cjk_yellow));
    LONGS_EQUAL(1, utf8_strlen (han_char));

    /* length of string (in chars, for max N bytes) */
    LONGS_EQUAL(0, utf8_strnlen (NULL, 0));
    LONGS_EQUAL(0, utf8_strnlen ("", 0));
    LONGS_EQUAL(1, utf8_strnlen ("AZ", 1));
    LONGS_EQUAL(1, utf8_strnlen ("ëZ", 2));
    LONGS_EQUAL(1, utf8_strnlen ("€Z", 3));
    LONGS_EQUAL(1, utf8_strnlen (han_char_z, 4));

    /* length of string on screen (in chars) */
    LONGS_EQUAL(0, utf8_strlen_screen (NULL));
    LONGS_EQUAL(0, utf8_strlen_screen (""));
    LONGS_EQUAL(1, utf8_strlen_screen ("A"));
    LONGS_EQUAL(1, utf8_strlen_screen ("ë"));
    LONGS_EQUAL(1, utf8_strlen_screen ("€"));
    LONGS_EQUAL(1, utf8_strlen_screen ("\x7f"));
    LONGS_EQUAL(2, utf8_strlen_screen (cjk_yellow));
}