diff --git a/src/OpenFOAM/primitives/strings/lists/CStringList.C b/src/OpenFOAM/primitives/strings/lists/CStringList.C index 7f918060fd..88d16f872e 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringList.C +++ b/src/OpenFOAM/primitives/strings/lists/CStringList.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,10 +34,15 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const CStringList& list) { const int n = list.size(); - for (int i = 0; i inline int Foam::CStringList::reset(const UList& input) { @@ -165,6 +155,12 @@ inline int Foam::CStringList::reset(const SubStrings& input) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +inline const char* Foam::CStringList::get(int i) const +{ + return argv_[i]; +} + + inline const char* Foam::CStringList::operator[](int i) const { return argv_[i]; diff --git a/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C b/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C index 6ba99497b9..9d52052659 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C +++ b/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C @@ -30,10 +30,7 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -int Foam::CStringList::resetContent -( - const ListType& input -) +int Foam::CStringList::resetContent(const ListType& input) { clear(); @@ -48,12 +45,12 @@ int Foam::CStringList::resetContent // Count overall required string length, including each trailing nul char for (const auto& str : input) { - len_ += str.length() + 1; + nbytes_ += str.length() + 1; } - --len_; // No final nul in overall count + --nbytes_; // Do not include final nul char in overall count argv_ = new char*[input.size()+1]; // Extra +1 for terminating nullptr - data_ = new char[len_+1]; // Extra +1 for terminating nul char + data_ = new char[nbytes_+1]; // Extra +1 for terminating nul char argv_[0] = data_; // Starts here @@ -75,14 +72,14 @@ template Foam::List Foam::CStringList::asList(int argc, const char * const argv[]) { - List lst(argc); + List list(argc); for (int i=0; i < argc; ++i) { - lst[i] = argv[i]; + list[i] = argv[i]; } - return lst; + return list; }