Changeset 6f0ea57


Ignore:
Timestamp:
2010-07-17T14:37:33Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0d691ea
Parents:
5e98ff0
Message:

Making nick_format a tiny bit more complicated: Allow truncating a variable
to a certain length.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/user-guide/misc.xml

    r5e98ff0 r6f0ea57  
    204204
    205205<para>
    206 One modifier is currently available: %-@variable will remove all characters from the first @ in the string.
    207 </para>
    208 
    209 <para>
    210 In all cases, invalid characters (like spaces) will be stripped. Depending
    211 on your locale settings, characters with accents will be converted to ASCII.
     206Invalid characters (like spaces) will always be stripped. Depending on your
     207locale settings, characters with accents will be converted to ASCII.
     208</para>
     209
     210<para>
     211See <emphasis>set nick_format2</emphasis> for some more information.
     212</para>
     213
     214</sect1>
     215
     216<sect1 id="nick_format2">
     217<title>Nickname formatting - modifiers</title>
     218
     219<para>
     220Two modifiers ares currently available: You can include only the first few
     221characters of a variable by putting a number right after the %. For example,
     222<emphasis>[%3group]%-@nick</emphasis> will include only the first three
     223characters of the group name in the nick.
     224</para>
     225
     226<para>
     227Also, you can truncate variables from a certain character using
     228the <emphasis>-</emphasis>modifier. For example, you may want to leave out
     229everything after the @. <emphasis>%-@handle</emphasis> will expand to
     230everything in the handle up to the first @.
    212231</para>
    213232
  • nick.c

    r5e98ff0 r6f0ea57  
    117117        {
    118118                char *part, chop = '\0', *asc = NULL;
     119                int len = MAX_NICK_LENGTH;
    119120               
    120121                if( *fmt != '%' )
     
    135136                                        return NULL;
    136137                                fmt += 2;
     138                        }
     139                        else if( isdigit( *fmt ) )
     140                        {
     141                                len = 0;
     142                                /* Grab a number. */
     143                                while( isdigit( *fmt ) )
     144                                        len = len * 10 + ( *(fmt++) - '0' );
    137145                        }
    138146                        else if( g_strncasecmp( fmt, "nick", 4 ) == 0 )
     
    188196                        g_string_append_c( ret, '_' );
    189197               
    190                 while( part && *part && *part != chop )
     198                while( part && *part && *part != chop && len > 0 )
    191199                {
    192200                        if( strchr( nick_lc_chars, *part ) ||
     
    195203                       
    196204                        part ++;
     205                        len --;
    197206                }
    198207                g_free( asc );
Note: See TracChangeset for help on using the changeset viewer.