Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323955 - Formatter should break long strings by splitting them into two, or using a backslash
Summary: Formatter should break long strings by splitting them into two, or using a ba...
Status: ASSIGNED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-30 07:37 EDT by BB CLA
Modified: 2020-09-04 15:17 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.