00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "documentSpec.h"
00016 #include "indent.h"
00017
00018
00019
00020
00021
00022
00023
00024 int DocumentSpec::
00025 compare_to(const DocumentSpec &other) const {
00026 if (_flags != other._flags) {
00027 return (_flags - other._flags);
00028 }
00029 int c = _url.compare_to(other._url);
00030 if (c != 0) {
00031 return c;
00032 }
00033 if (has_tag()) {
00034 c = _tag.compare_to(other._tag);
00035 if (c != 0) {
00036 return c;
00037 }
00038 }
00039 if (has_date()) {
00040 c = _date.compare_to(other._date);
00041 if (c != 0) {
00042 return c;
00043 }
00044 }
00045
00046
00047
00048
00049 return 0;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059 bool DocumentSpec::
00060 input(istream &in) {
00061
00062 (*this) = DocumentSpec();
00063
00064 char ch;
00065 in >> ch;
00066 if (ch != '[') {
00067 return false;
00068 }
00069 in >> _url;
00070 in >> ch;
00071 if (ch == '(') {
00072
00073 string tag;
00074 in >> ch;
00075 while (!in.fail() && !in.eof() && ch != ')') {
00076 tag += ch;
00077
00078 ch = in.get();
00079 }
00080 set_tag(HTTPEntityTag(tag));
00081
00082
00083
00084 in >> ch;
00085 }
00086
00087
00088 if (ch != ']') {
00089 string date;
00090 while (!in.fail() && !in.eof() && ch != ']') {
00091 date += ch;
00092 ch = in.get();
00093 }
00094
00095 set_date(HTTPDate(date));
00096 if (!get_date().is_valid()) {
00097 return false;
00098 }
00099 }
00100
00101 return true;
00102 }
00103
00104
00105
00106
00107
00108
00109 void DocumentSpec::
00110 output(ostream &out) const {
00111 out << "[ " << get_url();
00112 if (has_tag()) {
00113 out << " (" << get_tag() << ")";
00114 }
00115 if (has_date()) {
00116 out << " " << get_date();
00117 }
00118 out << " ]";
00119 }
00120
00121
00122
00123
00124
00125
00126 void DocumentSpec::
00127 write(ostream &out, int indent_level) const {
00128 indent(out, indent_level)
00129 << "[ " << get_url();
00130 if (has_tag()) {
00131 out << "\n";
00132 indent(out, indent_level + 2)
00133 << "(" << get_tag() << ")";
00134 }
00135 if (has_date()) {
00136 out << "\n";
00137 indent(out, indent_level + 2)
00138 << get_date();
00139 }
00140 out << " ]\n";
00141 }