Opened 4 years ago

Closed 4 years ago

#6726 closed enhancement (invalid)

Add printf style constructor to CPLString

Reported by: Lucian Plesea Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords: CPLString
Cc:

Description

CPLString and it's associated Printf method are often chained together to produce a temporary string, to the point that a new function, CPLOPrintf was introduced. This patch provides a CPLString formatting constructor, which also replaces the zero terminated string assignment constructor.

Attachments (1)

CPLString.patch (4.7 KB) - added by Lucian Plesea 4 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 4 years ago by Even Rouault

I'm afraid we can't just remove the CPLString( const char *pszStr ) constructor, in case something would rely on copying a string that would contain the % character. Now that could cause segfaults.

char* foo = read from file
CPLString osStr( foo );

Changed 4 years ago by Lucian Plesea

Attachment: CPLString.patch added

comment:2 Changed 4 years ago by Lucian Plesea

Resolution: invalid
Status: newclosed

Ah, yes, didn't think of that one case, I was too happy that I got it working. One could use the append() in that case, but that would be too much.

Note: See TracTickets for help on using tickets.