1 |
douglas |
676 |
// Url |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#include <cxx/standard.hh> |
8 |
|
|
|
9 |
douglas |
705 |
#include <api/pcre/regex.hpp> |
10 |
|
|
|
11 |
douglas |
676 |
#include "Url.hpp" |
12 |
|
|
|
13 |
douglas |
677 |
Url::Url(const cse::String &location, const std::time_t &modified, Frequency frequency, uint8_t priority) : location(location), frequency(frequency), priority(priority) |
14 |
|
|
{ |
15 |
|
|
::gmtime_r(&modified, &this->modified); |
16 |
douglas |
683 |
|
17 |
|
|
_assert (priority < 11); |
18 |
douglas |
677 |
} |
19 |
|
|
|
20 |
douglas |
684 |
Url::Url(const cse::String &location, const std::tm &modified, Frequency frequency, uint8_t priority) : location(location), modified(modified), frequency(frequency), priority(priority) |
21 |
douglas |
683 |
{ |
22 |
|
|
_assert (priority < 11); |
23 |
|
|
} |
24 |
|
|
|
25 |
douglas |
676 |
cse::String Url::GetModified() const |
26 |
|
|
{ |
27 |
|
|
ext::Buffer buffer(22); |
28 |
|
|
|
29 |
douglas |
711 |
size_t size(::strftime(buffer.Begin(), buffer.GetSize(), "%FT%TZ", &modified)); |
30 |
douglas |
676 |
|
31 |
|
|
buffer.SetSize(size); |
32 |
|
|
|
33 |
|
|
return buffer; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
cse::String Url::GetFrequency() const |
37 |
|
|
{ |
38 |
|
|
switch (frequency) |
39 |
|
|
{ |
40 |
|
|
case always: |
41 |
|
|
return _B("always"); |
42 |
|
|
case hourly: |
43 |
|
|
return _B("hourly"); |
44 |
|
|
case daily: |
45 |
|
|
return _B("daily"); |
46 |
|
|
case weekly: |
47 |
|
|
return _B("weekly"); |
48 |
|
|
case monthly: |
49 |
|
|
return _B("monthly"); |
50 |
|
|
case yearly: |
51 |
|
|
return _B("yearly"); |
52 |
|
|
case never: |
53 |
|
|
return _B("never"); |
54 |
|
|
_nodefault |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
cse::String Url::GetPriority() const |
59 |
|
|
{ |
60 |
|
|
_assert (priority < 11); |
61 |
|
|
|
62 |
|
|
switch (priority) |
63 |
|
|
{ |
64 |
|
|
default: |
65 |
|
|
return _S<ios::String>() << _B("0.") << priority; |
66 |
|
|
case 10: |
67 |
|
|
return _B("1.0"); |
68 |
|
|
} |
69 |
|
|
} |
70 |
douglas |
705 |
|
71 |
|
|
Frequency GetFrequency(const cse::String &frequency) |
72 |
|
|
{ |
73 |
|
|
if (frequency == _B("always")) |
74 |
|
|
return always; |
75 |
|
|
else if (frequency == _B("hourly")) |
76 |
|
|
return hourly; |
77 |
|
|
else if (frequency == _B("daily")) |
78 |
|
|
return daily; |
79 |
|
|
else if (frequency == _B("weekly")) |
80 |
|
|
return weekly; |
81 |
|
|
else if (frequency == _B("monthly")) |
82 |
|
|
return monthly; |
83 |
|
|
else if (frequency == _B("yearly")) |
84 |
|
|
return yearly; |
85 |
|
|
else if (frequency == _B("never")) |
86 |
|
|
return never; |
87 |
|
|
else |
88 |
|
|
return always; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
uint8_t GetPriority(const cse::String &priority) |
92 |
|
|
{ |
93 |
|
|
if (priority == _B("1.0")) |
94 |
|
|
return 10; |
95 |
|
|
else if (api::Pcre::RegEx::Match match = api::Pcre::RegEx(_B("^0\\.(\\d)$"))(priority)) |
96 |
|
|
return lexical_cast<uint8_t>(match[1]); |
97 |
|
|
else |
98 |
|
|
return 5; |
99 |
|
|
} |