Article View: borland.public.cppbuilder.internet.socket
Article #3741Re: Paths into URL
From: Markus Pesti
Date: Wed, 15 Jun 2005 15:07
Date: Wed, 15 Jun 2005 15:07
43 lines
1769 bytes
1769 bytes
Michele Santucci wrote:
> Hello NG,
>
> How can I translate a File Path into an URL?
> I mean something like that:
> C:\Program files\MyApp\Data\File.txt
> into:
> file://C|:/Program files/My App/Data/File.txt
>
This is not an internet problem but standard c++.
And mind the spaces in file names:
#include <string>
#include <functional>
#include <algorithm>
#include <iostream>
class same : public std::unary_function<char, bool>
{
char rc;
public:
same(const char& c) : rc(c) { }
bool operator() (const char& x) { return x == rc; }
};
int main()
{
std::string s("C:\\Program Files\\My App\\Data\\File.txt");
std::string::size_type n = s.find(" ");
while(n != std::string::npos)
{
s.replace(n, 1, "%20");
n = s.find(" ", n + 3);
}
std::replace_if(s.begin(), s.end(), same('\\'), '/');
s = "file:///" + s;
std::cout << s << std::endl;
}
Technical Details
Message-ID:
<3hauieFg4j7vU1@individual.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mailReferences:
<42b0320e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,2772c7903ef79719 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Markus Pesti <news@pesti.de> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Paths into URL Date: Wed, 15 Jun 2005 17:07:56 +0200 Organization: The Internet Lines: 43 Message-ID: <3hauieFg4j7vU1@individual.net> References: <42b0320e$1@newsgroups.borland.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Pfa31tQy+19AVMFD4AoVtwiHf4K5oKZVl2ui763ac9cnJcGNU= User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: <42b0320e$1@newsgroups.borland.com>