made some final changes to the comments
This commit is contained in:
parent
f284a9a471
commit
bdfc14357a
@ -151,8 +151,9 @@ std::istream& operator>>(std::istream& is, String& str)
|
||||
{
|
||||
constexpr size_t BUFSIZE = 50; // set some reasonable buffer size
|
||||
char buf[BUFSIZE];
|
||||
std::unique_ptr<char[]> data(new char[1]); // istream data - I use unique_ptr for exception safety
|
||||
std::unique_ptr<char[]> data(new char[1]); // istream data - unique_ptr for exception safety
|
||||
data.get()[0] = '\0'; // init it with a null terminator
|
||||
|
||||
while (is.get(buf, BUFSIZE)) // while there is still some data in the stream
|
||||
{
|
||||
std::unique_ptr<char[]> newdata(new char[strlen(data.get()) + BUFSIZE]); // make some space
|
||||
@ -160,6 +161,7 @@ std::istream& operator>>(std::istream& is, String& str)
|
||||
data.swap(newdata); // make the old data go out of scope instead of newdata
|
||||
std::strcat(data.get(), buf); // append new input
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> newdata(new char[strlen(data.get()) + 1]); // shrink the array
|
||||
std::strcpy(newdata.get(), data.get()); // to fit the data
|
||||
data.swap(newdata);
|
||||
|
@ -28,7 +28,7 @@ const char& StringValue::operator[](size_t index) const
|
||||
return _data[index];
|
||||
}
|
||||
|
||||
// reuse const operator[], just as Scott Meyers would
|
||||
// reuse const operator[]
|
||||
char& StringValue::operator[](size_t index)
|
||||
{ return const_cast<char&>(const_cast<const StringValue*>(this)->operator[](index)); }
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
|
||||
/* This is a demonstration, that the String class and it's components work
|
||||
* correctly, basically a non-unit test. Perfect for usage with valgrind */
|
||||
* correctly, basically a non-unit test. Perfect for usage with valgrind.
|
||||
* Note that these tests are only used in case GTest is not present on the system. */
|
||||
int main()
|
||||
{
|
||||
if (std::is_default_constructible<String>::value)
|
||||
|
3
test.cpp
3
test.cpp
@ -10,7 +10,8 @@
|
||||
|
||||
|
||||
/* These unit tests were written using the Google Test framework,
|
||||
* and check everything stated in the specification. */
|
||||
* and check everything stated in the specification. Note that
|
||||
* these tests are only used in case GTest is present on the system.*/
|
||||
///////////////////////////////////////////////////////////////
|
||||
/// Testing helper classes ///
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user