STYLE: return const char* in CStringList::data()

- and other code style adjustments
This commit is contained in:
Mark Olesen
2017-08-03 09:16:09 +02:00
parent 5148e4f860
commit 41c103b769
3 changed files with 6 additions and 11 deletions

View File

@ -128,7 +128,7 @@ public:
inline size_t length() const; inline size_t length() const;
//- The flattened character content, with interspersed nul-chars //- The flattened character content, with interspersed nul-chars
inline char* data() const; inline const char* data() const;
// Edit // Edit

View File

@ -97,7 +97,7 @@ inline char** Foam::CStringList::strings() const
} }
inline char* Foam::CStringList::data() const inline const char* Foam::CStringList::data() const
{ {
return data_; return data_;
} }

View File

@ -31,10 +31,7 @@ Foam::CStringList::CStringList
const UList<StringType>& input const UList<StringType>& input
) )
: :
argc_(0), CStringList()
len_(0),
argv_(nullptr),
data_(nullptr)
{ {
reset(input); reset(input);
} }
@ -63,12 +60,10 @@ void Foam::CStringList::reset
{ {
len_ += str.size() + 1; len_ += str.size() + 1;
} }
--len_; // No final nul in overall count
argv_ = new char*[input.size()+1]; argv_ = new char*[input.size()+1]; // Extra +1 for terminating nullptr
data_ = new char[len_]; data_ = new char[len_+1]; // Extra +1 for terminating nul char
--len_; // Do not include final nul terminator in overall count
argv_[argc_] = nullptr; // extra terminator
// Copy contents // Copy contents
char* ptr = data_; char* ptr = data_;