summaryrefslogtreecommitdiffstats
path: root/kbugbuster/backend/person.cpp
blob: 40cf72b7a0076347ce4c64e55f4c0c44fca312a8 (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.find( '<' );
    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.find( '<' );
    if ( ltPos != -1 )
    {
        int gtPos = str.find( '>', ltPos );
        if ( gtPos != -1 )
        {
            res.name = str.left( ltPos - 1 );
            str = str.mid( ltPos + 1, gtPos - ( ltPos + 1 ) );
        }
    }
   
    int atPos = str.find( '@' );
    int spacedAtPos = str.find( TQString::fromLatin1( " at " ) );
    if ( atPos == -1 && spacedAtPos != -1 )
        str.replace( spacedAtPos, 4, TQString::fromLatin1( "@" ) );

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

    return res;
}

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