Opened 12 years ago
Closed 12 years ago
#4716 closed Bugs (fixed)
boost::filesystem::path operator>> drops leading slash.
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The problem manifests itself most obviously using boost::lexical_cast. See the attached test case.
Attachments (1)
Change History (5)
by , 12 years ago
Attachment: | comn_pathlexicalcast_test.cpp added |
---|
comment:1 by , 12 years ago
I ran into this same issue. However, I think its actually worse than dropping the leading slash. It drops the leading character whatever it is unless it is a double quote.
boost\filesystem\v3\path.hpp
template <class Char, class Traits> inline std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is, path& p) {
std::basic_string<Char> str; is >> boost::io::quoted(str, static_cast<Char>('&')); p = str; return is;
}
The problem is coming from the boost::io::quoted function.
boost\io\detail\quoted_manip.hpp
extractor for non-const std::basic_string& proxies template <class Char, class Traits, class Alloc> std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
{
Char c; is >> c; if (c != proxy.delim) {
proxy.string = c; is >> proxy.string; return is;
} proxy.string.clear(); {
boost::io::ios_flags_saver ifs(is); is >> std::noskipws; for (;;) {
is >> c; if (!is.good()) cope with I/O errors or end-of-file
break;
if (c == proxy.escape) {
is >> c; if (!is.good()) cope with I/O errors or end-of-file
break;
} else if (c == proxy.delim)
break;
proxy.string += c;
}
} return is;
}
The function is checking if the first character in the stream is a double quote, if it is all works fine. However if its not it assigns the value of the first character to the proxy.string and then uses the insertion operator to get the rest of the characters. However the insertion is not an append it is an assignment so the effect is the first character is lost. I'm not exactly sure if this is expected behavior of this function of not. A workaround is to change the proxy.string = c; to is.unget(); This will preserve the first character.
comment:2 by , 12 years ago
Component: | None → filesystem |
---|---|
Owner: | set to |
Version: | Boost 1.44.0 → Boost 1.45.0 |
This appears to have been addressed on the trunk, please can we ensure this makes it to the next (1.45) release?
http://lists.boost.org/boost-commit/2010/08/27576.php
I know this is not specifically a filesystem issue, however, AFAIK fs is the only 'client' at the moment.
comment:3 by , 12 years ago
Version: | Boost 1.45.0 → Boost 1.44.0 |
---|
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Merged to release, revision 68159
Let me know if this doesn't solve the problems.
Thanks,
--Beman
Unit test for lexical_cast<path>