1 | #include <boost/filesystem/path.hpp>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 | using boost::filesystem::path;
|
---|
5 |
|
---|
6 | void replace_extension(path p, const path& extension) {
|
---|
7 | std::cout << "replace_extension(" << p << "," << extension << ") = ";
|
---|
8 | std::cout << p.replace_extension(extension) << '\n';
|
---|
9 | }
|
---|
10 |
|
---|
11 | int main()
|
---|
12 | {
|
---|
13 | // These cases can be acceptable if we consider that filename is empty
|
---|
14 | std::cout << "\n"
|
---|
15 | << "Replace extension on root-path: (arguable)\n"
|
---|
16 | << "------------------------------------------\n\n";
|
---|
17 |
|
---|
18 | replace_extension("/","txt");
|
---|
19 | replace_extension("C:\\","txt");
|
---|
20 |
|
---|
21 | std::cout << "\n"
|
---|
22 | << "Replace extension on special file-name\n"
|
---|
23 | << "--------------------------------------\n\n";
|
---|
24 |
|
---|
25 | replace_extension(".","txt");
|
---|
26 | replace_extension("..","txt");
|
---|
27 | replace_extension("/foo/.","txt");
|
---|
28 | replace_extension("/foo/..","txt");
|
---|
29 |
|
---|
30 | std::cout << "\n"
|
---|
31 | << "Replace extension on root-name\n"
|
---|
32 | << "------------------------------\n\n";
|
---|
33 |
|
---|
34 | replace_extension("C:","txt");
|
---|
35 | replace_extension("\\\\myserver","txt");
|
---|
36 |
|
---|
37 | getchar();
|
---|
38 | return 0;
|
---|
39 | }
|
---|
40 |
|
---|