Changeset 8167346


Ignore:
Timestamp:
2018-03-11T19:28:38Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
a949b43
Parents:
16ea00d
git-author:
dequis <dx@…> (11-03-18 09:13:45)
git-committer:
dequis <dx@…> (11-03-18 19:28:38)
Message:

Try to join long spaceless lines in paste_buffer without a newline

Fixes trac ticket 1302

The main use case for this is pasting long URLs and not breaking them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_im.c

    r16ea00d r8167346  
    446446}
    447447
     448#define PASTEBUF_LONG_SPACELESS_LINE_LENGTH 350
     449
     450/* Returns FALSE if the last line of the message is near the typical irc length
     451 * limit and the message has no spaces, indicating that it's probably desirable
     452 * to join messages without the newline.
     453 *
     454 * The main use case for this is pasting long URLs and not breaking them */
     455static gboolean bee_irc_pastebuf_should_start_with_newline(const char *msg)
     456{
     457        int i;
     458        const char *last_line = strrchr(msg, '\n') ? : msg;
     459
     460        if (*last_line == '\n') {
     461                last_line++;
     462        }
     463
     464        for (i = 0; last_line[i]; i++) {
     465                if (g_ascii_isspace(last_line[i])) {
     466                        return TRUE;
     467                }
     468        }
     469
     470        if (i < PASTEBUF_LONG_SPACELESS_LINE_LENGTH) {
     471                return TRUE;
     472        }
     473
     474        return FALSE;
     475}
     476
    448477/* IRC->IM calls */
    449478
     
    470499        } else {
    471500                b_event_remove(iu->pastebuf_timer);
    472                 g_string_append_printf(iu->pastebuf, "\n%s", msg);
     501                if (bee_irc_pastebuf_should_start_with_newline(iu->pastebuf->str)) {
     502                        g_string_append_c(iu->pastebuf, '\n');
     503                }
     504                g_string_append(iu->pastebuf, msg);
    473505        }
    474506
Note: See TracChangeset for help on using the changeset viewer.