summaryrefslogtreecommitdiffstats
path: root/kbugbuster/backend/person.cpp
blob: 368ea07c0bcb91469e1237dffcf3c65ee85f9267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <kdebug.h>

#include "person.h"

Person::Person( const TQString &fullName )
{
    int emailPos = fullName.tqfind( '<' );
    if ( emailPos < 0 ) {
        email = fullName;
    } else {
        email = fullName.mid( emailPos + 1, fullName.length() - 1 );
        name = fullName.left( emailPos - 1 );
    }
}

TQString Person::fullName(bool html) const
{
    if( name.isEmpty() )
    {
        if( email.isEmpty() )
            return i18n( "Unknown" );
        else
            return email;
    }
    else
    {
        if( email.isEmpty() )
            return name;
        else
            if ( html ) {
                return name + " &lt;" + email + "&gt;";
            } else {
                return name + " <" + email + ">";
            }
    }
}

Person Person::parseFromString( const TQString &_str )
{
    Person res;

    TQString str = _str;

    int ltPos = str.tqfind( '<' );
    if ( ltPos != -1 )
    {
        int gtPos = str.tqfind( '>', ltPos );
        if ( gtPos != -1 )
        {
            res.name = str.left( ltPos - 1 );
            str = str.mid( ltPos + 1, gtPos - ( ltPos + 1 ) );
        }
    }
   
    int atPos = str.tqfind( '@' );
    int spacedAtPos = str.tqfind( TQString::tqfromLatin1( " at " ) );
    if ( atPos == -1 && spacedAtPos != -1 )
        str.tqreplace( spacedAtPos, 4, TQString::tqfromLatin1( "@" ) );

    int spacePos = str.tqfind( ' ' );
    while ( spacePos != -1 )
    {
        str[ spacePos ] = '.'; 
        spacePos = str.tqfind( ' ', spacePos );
    }
  
    res.email = str;

    return res;
}

/**
 * vim:et:ts=4:sw=4
 */