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