Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323955

Summary: Formatter should break long strings by splitting them into two, or using a backslash
Product: [Tools] CDT Reporter: BB <bjoern.kiefer>
Component: cdt-editorAssignee: Project Inbox <cdt-editor-inbox>
Status: ASSIGNED --- QA Contact: Jonah Graham <jonah>
Severity: enhancement    
Priority: P3 CC: yevshif, zeratul976
Version: 7.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description BB CLA 2010-08-30 07:37:23 EDT
If I write this in the c++ editor:
#include <string>
std::string strError("This must be a long text in one row ...............................................");

The result of the formatting (ctrl+shift+f) of the string initialization takes 3 lines and looks like this:

#include <string>
std::string
		strError(
				"This must be a long text in one row ...............................................");
Comment 1 Anton Leherbauer CLA 2010-08-30 10:30:59 EDT
You can configure the formatter in the preferences under C/C++ > Code Style.
What would you expect?
Comment 2 BB CLA 2010-08-30 12:51:43 EDT
(In reply to comment #1)
> You can configure the formatter in the preferences under C/C++ > Code Style.
> What would you expect?


I would expect one of the following formatting:

1. Do not break the line:
std::string strError("This must be a long text in one row ......................"


2. Best looking - break with double quote:
std::string strError("This must be a long text "
        "in one row..........................");

3. Break with backslash:
std::string strError("This must be a long text \
in one row..........................");
Comment 3 Anton Leherbauer CLA 2010-08-31 02:43:58 EDT
(In reply to comment #2)
> (In reply to comment #1)
> > You can configure the formatter in the preferences under C/C++ > Code Style.
> > What would you expect?
> 
> 
> I would expect one of the following formatting:
> 
> 1. Do not break the line:
> std::string strError("This must be a long text in one row
> ......................"

You can configure this in the preferences by setting the maximum line width to a high value.

> 
> 2. Best looking - break with double quote:
> std::string strError("This must be a long text "
>         "in one row..........................");

This is not supported.  The formatter only changes whitespace.

> 3. Break with backslash:
> std::string strError("This must be a long text \
> in one row..........................");

Same as above.

I am marking this as an enhancement request. No plans to work on this in the near future, though.
Comment 4 Nathan Ridge CLA 2017-01-02 19:57:08 EST
(In reply to BB from comment #0)
> If I write this in the c++ editor:
> #include <string>
> std::string strError("This must be a long text in one row
> ...............................................");
> 
> The result of the formatting (ctrl+shift+f) of the string initialization
> takes 3 lines and looks like this:
> 
> #include <string>
> std::string
> 		strError(
> 				"This must be a long text in one row
> ...............................................");

With CDT 9.2, I'm not seeing 3 lines, only 2:

#include <string>
std::string strError(
        "This must be a long text in one row ...............................................");

which looks a lot more reasonable.
Comment 5 Nathan Ridge CLA 2017-01-02 19:58:41 EST
(In reply to Anton Leherbauer from comment #3)
> > 2. Best looking - break with double quote:
> > std::string strError("This must be a long text "
> >         "in one row..........................");
> 
> This is not supported.  The formatter only changes whitespace.
> 
> > 3. Break with backslash:
> > std::string strError("This must be a long text \
> > in one row..........................");
> 
> Same as above.
> 
> I am marking this as an enhancement request. No plans to work on this in the
> near future, though.

Updated bug title to reflect this enhancement request.