forked from shebib/CS104-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet.cpp
53 lines (43 loc) · 949 Bytes
/
tweet.cpp
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
#include "tweet.h"
Tweet::Tweet()
{}
Tweet::Tweet(std::string usrname, User* user, DateTime& time, std::string& text)
{
usrname_ = usrname;
user_ = user;
time_ = time;
text_ = text;
if(text_.find("@") == 0)
isDM_ = true;
else
isDM_ = false;
setTags();
}
DateTime const & Tweet::time() const
{ return time_; }
std::string const & Tweet::text() const
{ return text_; }
std::set<std::string> Tweet::hashTags() const
{ return tags_; }
User* Tweet::user() const
{ return user_; }
bool Tweet::isDM() const
{ return isDM_; }
bool Tweet::operator<(const Tweet& other) const
{ return(time_<other.time_); }
std::ostream& operator<<(std::ostream& os, const Tweet& t)
{
os<<t.time_<<" " << t.usrname_ << " "<< t.text_;
return os;
}
void Tweet::setTags()
{
int n = 0;
n = text_.find("#");
while(n!=-1)
{
int sp = text_.find(" ", n);
tags_.insert(text_.substr(n+1, sp-n-1));
n = text_.find("#", n+1);
}
}