How can I format an acceleration object without quotes?

Here is my code:

fs::path datadir = ...; std::string dataDirOption((boost::format("--datadir=%1%") % datadir).str()); 

For datadir=="c:/db" I get dataDirOption=="--datadir=\"c:/db\"" instead of "--datadir=c:/db"

Is it possible to tell boost::filesystem::path skip quotation marks when formatting?

Now I know that I can replace datadir.string() with datadir and get rid of the quotes this way, but I'm wondering if I can do this without an extra line.

Thanks.

+4
source share
3 answers

I would suggest another option: post-processing.

 boost::replace_all(dataDirOption, "\"", ""); 

This way you can easily switch to another quote character, for example, ' .

0
source

No, this is not a bug file in boost version 1.47.0, which has not yet received a milestone when to fix it.

Workaround:

 std::cout << path("/foo/bar.txt").filename().string() 
+4
source

The % operator for format uses the stream operator << for custom types , and the documentation tells us that this is effective for path :

 os << boost::io::quoted(p.string<std::basic_string<Char>>(), static_cast<Char>('&')); 

To exclude quotation marks, you need to pass something else to the format object, for example, the result of the string method that you already found.

+3
source

Source: https://habr.com/ru/post/1391869/


All Articles