Opened 12 years ago

Closed 11 years ago

Last modified 9 years ago

#5118 closed Bugs (fixed)

replace_extension doesn't work as specified in documentation

Reported by: bitfield.alex@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.45.0 Severity: Problem
Keywords: extension Cc: jonathan.jones@…

Description

  1. From Reference (see http://www.boost.org/doc/libs/1_45_0/libs/filesystem/v3/doc/reference.html#path-replace_extension):
path& replace_extension(const path& new_extension = path());

Postcondition: extension() == replacement, 
where replacement is new_extension 
  if new_extension.empty() || new_extension[0] == the dot character, 
otherwise replacement is the dot character followed by new_extension.

Returns: *this

Testing this behavior

path ph("foo.txt");
std::cout << ph.replace_extension("exe");

Output:

foo

Eather change the Reference or fix it in code.

  1. Current implementation doesn't allow to work with complex extentions.
path ph("foo.txt");
std::cout << ph.replace_extention(".tar.bz2");

Output:

foo.bz2
  1. There is no function to just add extension.

something like that:

path ph("foo.txt");
std::cout << ph.add_extension("bz2"); 

Expected output:

foo.txt.bz2

Attachments (1)

replace_ext_fix.patch (721 bytes ) - added by bitfield.alex@… 11 years ago.
Here is a patch for replace_extension method

Download all attachments as: .zip

Change History (8)

comment:1 by peter.baumann AT methodpark.de, 11 years ago

This is also a regression from V2 -> V3, because in V2 this works as documented.

by bitfield.alex@…, 11 years ago

Attachment: replace_ext_fix.patch added

Here is a patch for replace_extension method

comment:2 by anonymous, 11 years ago

This bug is still in 1.47.0. Any hopes fixing it for the next release?

comment:3 by anonymous, 11 years ago

And it is still in 1.48.0
The "Boost Filesystem Do List" found in "boost_1_48_0/libs/filesystem/v3/doc/do_list.html" indicates that the behavior has changed from v2 to v3.

On the do list for documentation: Document behavior of path::replace_extension has change WRT argument w/o a dot.

Also, "boost_1_48_0/libs/filesystem/v3/test/path_test.cpp" includes multiple tests for this "new" functionality.

The documentation should be updated or the patch should be applied!

comment:4 by Sebastian Redl, 11 years ago

Still in 1.49. This is a really nasty behavior change from v2.

comment:5 by Beman Dawes, 11 years ago

Resolution: fixed
Status: newclosed

(In [77571]) Fix #5118, replace_extension doesn't work as specified in documentation

comment:6 by Beman Dawes, 11 years ago

The documentation, implementation, and test cases have all had fixes applied. The documentation had failed to mention that any existing extension is removed. The behavior for simple cases has been reverted to the Version 2 behavior, but with corrections so that complex replacements now work. Two test cases from #5118 have been added.

This ticket also includes a request for an "add_extension" function. That's been deferred since there is a pending request for += operator that would cover the requested functionality.

Thanks,

--Beman

comment:7 by jonathan.jones@…, 9 years ago

Cc: jonathan.jones@… added
Note: See TracTickets for help on using tickets.