Changeset e3e2059 for nick.c


Ignore:
Timestamp:
2015-04-06T12:35:57Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
8bcd160
Parents:
69982f8
git-author:
dequis <dx@…> (06-04-15 12:30:30)
git-committer:
dequis <dx@…> (06-04-15 12:35:57)
Message:

irc: split bee_irc_chat_name_hint in a few functions

Also split underscore_dedupe from nick_dedupe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nick.c

    r69982f8 re3e2059  
    214214}
    215215
     216/* Used for nicks and channel names too! */
     217void underscore_dedupe(char nick[MAX_NICK_LENGTH + 1])
     218{
     219        if (strlen(nick) < (MAX_NICK_LENGTH - 1)) {
     220                nick[strlen(nick) + 1] = 0;
     221                nick[strlen(nick)] = '_';
     222        } else {
     223                /* We've got no more space for underscores,
     224                   so truncate it and replace the last three
     225                   chars with a random "_XX" suffix */
     226                int len = truncate_utf8(nick, MAX_NICK_LENGTH - 3);
     227                nick[len] = '_';
     228                g_snprintf(nick + len + 1, 3, "%2x", rand());
     229        }
     230}
     231
    216232void nick_dedupe(bee_user_t *bu, char nick[MAX_NICK_LENGTH + 1])
    217233{
     
    224240        while (!nick_ok(irc, nick) ||
    225241               ((iu = irc_user_by_name(irc, nick)) && iu->bu != bu)) {
    226                 if (strlen(nick) < (MAX_NICK_LENGTH - 1)) {
    227                         nick[strlen(nick) + 1] = 0;
    228                         nick[strlen(nick)] = '_';
    229                 } else {
    230                         /* We've got no more space for underscores,
    231                            so truncate it and replace the last three
    232                            chars with a random "_XX" suffix */
    233                         int len = truncate_utf8(nick, MAX_NICK_LENGTH - 3);
    234                         nick[len] = '_';
    235                         g_snprintf(nick + len + 1, 3, "%2x", rand());
    236                 }
     242
     243                underscore_dedupe(nick);
    237244
    238245                if (inf_protection-- == 0) {
Note: See TracChangeset for help on using the changeset viewer.