for (string s; cin>>s && s!=terminator; ) // read a word
for (string s; cin>>s && s!=terminator; ) // read a word
res.push_back(s);
return res;
}
@ -17259,7 +17259,7 @@ The `gsl::string_span` is a current alternative offering most of the benefits of
vector<string> read_until(string_span terminator)
{
vector<string> res;
for (string s; cin>>s && s!=terminator; ) // read a word
for (string s; cin>>s && s!=terminator; ) // read a word
res.push_back(s);
return res;
}
@ -17274,9 +17274,9 @@ Don't use C-style strings for operations that require non-trivial memory managem
int l1 = strlen(s1);
int l2 = strlen(s2);
char* p = (char*)malloc(l1+l2+2);
strcpy(p,s1,l1);
strcpy(p,s1,l1);
p[l1] = '.';
strcpy(p+l1+1,s2,l2);
strcpy(p+l1+1,s2,l2);
p[l1+l2+1] = 0;
return res;
}
@ -17321,20 +17321,20 @@ those sequences are allocated and stored.
???
### <aname="Rstr-zstring"></a>SL.str.3: Use `zstring` or `czstring` to refere to a C-style, zero-terminated, sequence of characters
### <aname="Rstr-zstring"></a>SL.str.3: Use `zstring` or `czstring` to refer to a C-style, zero-terminated, sequence of characters
##### Reason
Readability.
Statement of intent.
A plain `char*` can be a pointer to a single character, a pointer to an arry of characters, a pointer to a C-style (zero terminated) string, or event to a small integer.
A plain `char*` can be a pointer to a single character, a pointer to an array of characters, a pointer to a C-style (zero terminated) string, or even to a small integer.
Distinguishing these alternatives prevents misunderstandings and bugs.
##### Example
void f1(const char* s); // s is probably a string
All we know is that it is supposetot bet the nullptr or point to at least one character
All we know is that it is supposed to be the nullptr or point to at least one character
void f1(zstring s); // s is a C-style string or the nullptr
void f1(czstring s); // s is a C-style string that is not the nullptr
@ -17346,14 +17346,14 @@ Don't convert a C-style string to `string` unless there is a reason to.
##### Note
Linke any other "plain pointer", a `zstring` should not represent ownership.
Like any other "plain pointer", a `zstring` should not represent ownership.
##### Note
There are billions of lines of C++ "out there", most use `char*` and `const char*` without documenting intent.
They are use in a wide varity of ways, including to represent ownership and as generic pointers to memory (instead of `void*`).
They are used in a wide variety of ways, including to represent ownership and as generic pointers to memory (instead of `void*`).
It is hard to separate these uses, so this guideline is hard to follow.
This is one of the major sources of bugs in C and C++ programs, so it it worth while to follow this guideline wherever feasible..
This is one of the major sources of bugs in C and C++ programs, so it is worthwhile to follow this guideline wherever feasible..
##### Enforcement
@ -17395,8 +17395,8 @@ See [`zstring`](#Rstr-zstring), [`string`](#Rstr-string), and [`string_span`](#R
##### Reason
Use of `char*` to represent a pinter to something that is not necessarily a character cause confusion
and disable valuable optimizations.
Use of `char*` to represent a pointer to something that is not necessarily a character causes confusion
and disables valuable optimizations.
##### Example
@ -17415,7 +17415,7 @@ C++17
##### Reason
`std::string` support standard-library [`locale` facilities](#Rstr-locale)