ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Search/URL.cpp
(Generate patch)

Comparing trunk/Search/URL.cpp (file contents):
Revision 16 by douglas, 2002-12-04T20:22:59-08:00 vs.
Revision 17 by douglas, 2002-12-09T18:31:11-08:00

# Line 150 | Line 150 | ostream& operator<<(ostream& os, URL& da
150  
151          return os;
152   }
153 +
154 + string getLink(string link, URL& url)
155 + {
156 +        string hyperlink = "";
157 +
158 +        if (link.find('#') != string::npos)
159 +        {
160 +                unsigned pound = link.find('#');
161 +                link.erase(pound);
162 +        }
163 +
164 +        if (link.find("://") != string::npos)
165 +        {
166 +                if (link.find("http://") == 0) hyperlink = link;
167 +        }
168 +        else if (link.find("mailto:") == 0)
169 +        {
170 +                // do nothing we are not evil spammers!
171 +        }
172 +        else if (link.find("//") == 0)
173 +        {
174 +                hyperlink = "http:" + link;
175 +        }
176 +        else if (link.find('/') == 0)
177 +        {
178 +                hyperlink = url.getURL();
179 +
180 +                unsigned path = hyperlink.find('/', 7);
181 +                hyperlink.erase(path);
182 +
183 +                hyperlink += link;
184 +        }
185 +        else if (link == "")
186 +        {
187 +                // a blank link is useless
188 +        }
189 +        else
190 +        {
191 +                hyperlink = url.getURL();
192 +                string path = url.getPath();
193 +
194 +                unsigned cutoff = hyperlink.rfind(path);
195 +                hyperlink.erase(cutoff);
196 +
197 +                unsigned dir = path.rfind('/') + 1;
198 +                path.erase(dir);
199 +
200 +                while (link.find("../") == 0)
201 +                {
202 +                        unsigned dot = path.rfind('/') - 1;
203 +                        unsigned up = path.rfind('/', dot) + 1;
204 +
205 +                        path.erase(up);
206 +                        link.erase(0, 3);
207 +                }
208 +                while (link.find("./") == 0)
209 +                {
210 +                        link.erase(0, 2);
211 +                }
212 +
213 +                hyperlink += path + link;
214 +        }
215 +
216 +        return hyperlink;
217 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines