Skip to content

Commit

Permalink
tryto improve the comma format, need doublecheck
Browse files Browse the repository at this point in the history
	modified:   format.rb
	modified:   ../ch06/README.md
	modified:   ../ch07/ex7_24.h
	modified:   ../ch07/ex7_27.h
	modified:   ../ch07/ex7_32.h
	modified:   ../ch09/README.md
	modified:   ../ch09/ex9_51.cpp
	modified:   ../ch11/README.md
	modified:   ../ch11/ex11_8.cpp
	modified:   ../ch12/README.md
	modified:   ../ch14/README.md
	modified:   ../ch15/ex15.11/main.cpp
	modified:   ../ch15/ex15.26/bulk_quote.h
	modified:   ../ch15/ex15.26/main.cpp
	modified:   ../ch15/ex15.27/bulk_quote.h
	modified:   ../ch15/ex15.27/main.cpp
	modified:   ../ch15/ex15.28.29/bulk_quote.h
	modified:   ../ch15/ex15.30/bulk_quote.h
	modified:   ../ch15/ex15.30/main.cpp
	modified:   ../ch15/ex15.34.35.36.38/andquery.h
	modified:   ../ch15/ex15.39.40/andquery.h
	modified:   ../ch15/ex15.8.9.10/ex15.8.9.10.cpp
	modified:   ../ch16/ex16.12.13/Blob.h
	modified:   ../ch16/ex16.12.13/blobptr.h
	modified:   ../ch16/ex16.14.15/main.cpp
	modified:   ../ch16/ex16.24/Blob.h
	modified:   ../ch16/ex16.24/blobptr.h
	modified:   ../ch16/ex16.29/Blob.h
	modified:   ../ch16/ex16.32.33.34.35.36/main.cpp
	modified:   ../ch16/ex16.62/main.cpp
  • Loading branch information
Mooophy committed Aug 28, 2015
1 parent d864a0f commit c584af2
Show file tree
Hide file tree
Showing 30 changed files with 56 additions and 55 deletions.
5 changes: 3 additions & 2 deletions .tools/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
handlers.each do |h|
h.on_each_line do |line|
begin
line.gsub! /,(\S)/, ', \1' if !line.include? '"' and !line.include? '\''
rescue Exception => e
# line.gsub! /,(\S)/, ', \1' if !line.include? '"' and !line.include? '\''
line.gsub! /,(\S)/, ', \1' unless line.match /.*\".*,.*\".*/ or line.match /','/
rescue Exception => e
puts e.message + ", ignored."
end
end
Expand Down
6 changes: 3 additions & 3 deletions ch06/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ casue `c` maybe a temp varable. such as `find_char(s, 'a', occurs)`
bool is_empty(const string& s) { return s.empty(); }
```
Since this function doesn't change the argument,"const" shoud be added
before string&s,otherwise this function is misleading and can't be used
Since this function doesn't change the argument, "const" shoud be added
before string&s, otherwise this function is misleading and can't be used
with const string or in a const function.
## [Exercise 6.17](ex6_17.cpp)
Not the same.
For the first one "const" was used, since no change need to do for the argument.
For the second function,"const" can't be used,because the content of the agument
For the second function, "const" can't be used, because the content of the agument
should be changed.
## Exercise 6.18
Expand Down
2 changes: 1 addition & 1 deletion ch07/ex7_24.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Screen {
using pos = std::string::size_type;

Screen() = default; // 1
Screen(pos ht, pos wd):height(ht),width(wd),contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3

char get() const { return contents[cursor]; }
Expand Down
2 changes: 1 addition & 1 deletion ch07/ex7_27.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Screen {
using pos = std::string::size_type;

Screen() = default; // 1
Screen(pos ht, pos wd):height(ht),width(wd),contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3

char get() const { return contents[cursor]; }
Expand Down
2 changes: 1 addition & 1 deletion ch07/ex7_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Screen {
using pos = std::string::size_type;

Screen() = default; // 1
Screen(pos ht, pos wd):height(ht),width(wd),contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2
Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3

char get() const { return contents[cursor]; }
Expand Down
2 changes: 1 addition & 1 deletion ch09/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Fixed:
while(iter1 != iter2)
```
#### note:
operator `<` can be used in `list`,but can't be applied to iterator for `list`.
operator `<` can be used in `list`, but can't be applied to iterator for `list`.
## Exercise 9.7:
>What type should be used as the index into a vector of ints?
Expand Down
2 changes: 1 addition & 1 deletion ch09/ex9_51.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class My_date{
switch(format){

case 0x01:
day = stoi(s.substr(0,s.find_first_of("/")));
day = stoi(s.substr(0, s.find_first_of("/")));
month = stoi(s.substr(s.find_first_of("/") + 1, s.find_last_of("/")- s.find_first_of("/")));
year = stoi(s.substr(s.find_last_of("/") + 1, 4));

Expand Down
2 changes: 1 addition & 1 deletion ch11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ error: passing ‘const std::map<std::basic_string<char>, std::basic_string<char
auto key = m[s];
^
```
Because std::map's operator is not declared as **const**,but m is declared as a reference to std::map with **const**.If insert new pair,it will cause error.
Because std::map's operator is not declared as **const**, but m is declared as a reference to std::map with **const**.If insert new pair, it will cause error.
## Exercise 11.35:
>In buildMap, what effect, if any, would there be from rewriting `trans_map[key] = value.substr(1);` as `trans_map.insert({key, value.substr(1)})`?
Expand Down
2 changes: 1 addition & 1 deletion ch11/ex11_8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// to the number of items already in the vector. The time it takes
// to insert an item into a set is proportional to the log of the
// number of items. If the number of items is large, that's a huge
// difference. Log(100,000) is 17; that's a major speed improvement.
// difference. Log(100, 000) is 17; that's a major speed improvement.
// The same goes for removal.
//
// http://stackoverflow.com/questions/8686725/what-is-the-difference-between-stdset-and-stdvector
Expand Down
2 changes: 1 addition & 1 deletion ch12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Memory leakage happens. Because after `r = q` was executed, no pointer points to

- to `q2` and `r2`:

It's safe. Because after 'r2 = q2', the reference count belongs to r2 reduce to 0 and the reference count belongs to q2 increase to 2,then the memory allocated by r2 will be released automatically.
It's safe. Because after 'r2 = q2', the reference count belongs to r2 reduce to 0 and the reference count belongs to q2 increase to 2, then the memory allocated by r2 will be released automatically.

## [Exercise 12.10](ex12_10.cpp)
## [Exercise 12.11](ex12_11.cpp)
Expand Down
2 changes: 1 addition & 1 deletion ch14/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ see [Exercise 14.27](#exercise-1427)
## Exercise 14.29:
> We did not define a `const` version of the increment and decrement operators. Why not?
Because `++` and `--` change the state of the object. Hence ,it's meaningless to do so.
Because `++` and `--` change the state of the object. Hence , it's meaningless to do so.

## Exercise 14.30:
> Add dereference and arrow operators to your `StrBlobPtr` class and to the `ConstStrBlobPtr` class that you defined in exercise 12.22 from 12.1.6 (p. 476). Note that the operators in `constStrBlobPtr` must return `const` references because the `data` member in `constStrBlobPtr` points to a `const vector`.
Expand Down
6 changes: 3 additions & 3 deletions ch15/ex15.11/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void print_debug(const Quote& q);
double print_total (std::ostream& os, const Quote& item, size_t n);
int main()
{
Quote q("aaa",10.60);
Bulk_quote bq("bbb",111,10,0.3);
Limit_quote lq("ccc",222,10,0.3);
Quote q("aaa", 10.60);
Bulk_quote bq("bbb", 111, 10, 0.3);
Limit_quote lq("ccc", 222, 10, 0.3);

/** @note Not dynamic binding!
* The codes below are not dynamic binding. The compiler has known what the
Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.26/bulk_quote.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Bulk_quote : public Disc_quote
public:
Bulk_quote() {std::cout << "default constructing Bulk_quote\n"; }
Bulk_quote(const std::string& b, double p, std::size_t q, double disc) :
Disc_quote(b,p,q,disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }

// copy constructor
Bulk_quote(const Bulk_quote& bq) : Disc_quote(bq)
Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.26/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
int main()
{
Bulk_quote bq1;
Bulk_quote bq2("ss",2.05,12,0.3);
Bulk_quote bq2("ss", 2.05, 12, 0.3);
bq2 = std::move(bq2);


Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.27/bulk_quote.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Bulk_quote : public Disc_quote
// 4. the rest details are in the section section 15.7.4.
/*
Bulk_quote(const std::string& b, double p, std::size_t q, double disc) :
Disc_quote(b,p,q,disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
*/
using Disc_quote::Disc_quote;

Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.27/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

int main()
{
Bulk_quote bq("sss",20.0,2,0.3);
Bulk_quote bq("sss", 20.0, 2, 0.3);
return 0;
}
2 changes: 1 addition & 1 deletion ch15/ex15.28.29/bulk_quote.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Bulk_quote : public Disc_quote
// 4. the rest details are in the section section 15.7.4.
/*
Bulk_quote(const std::string& b, double p, std::size_t q, double disc) :
Disc_quote(b,p,q,disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
*/
using Disc_quote::Disc_quote;

Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.30/bulk_quote.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Bulk_quote : public Disc_quote
// 4. the rest details are in the section section 15.7.4.
/*
Bulk_quote(const std::string& b, double p, std::size_t q, double disc) :
Disc_quote(b,p,q,disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; }
*/
using Disc_quote::Disc_quote;

Expand Down
8 changes: 4 additions & 4 deletions ch15/ex15.30/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ int main()
Basket basket;

for (unsigned i = 0; i != 10; ++i)
basket.add_item(Bulk_quote("Bible",20.6,20,0.3));
basket.add_item(Bulk_quote("Bible", 20.6, 20, 0.3));

for (unsigned i = 0; i != 10; ++i)
basket.add_item(Bulk_quote("C++Primer",30.9,5,0.4));
basket.add_item(Bulk_quote("C++Primer", 30.9, 5, 0.4));

for (unsigned i = 0; i != 10; ++i)
basket.add_item(Quote("CLRS",40.1));
basket.add_item(Quote("CLRS", 40.1));

std::ofstream log("log.txt",std::ios_base::app|std::ios_base::out);
std::ofstream log("log.txt", std::ios_base::app|std::ios_base::out);

basket.total_receipt(log);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.34.35.36.38/andquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AndQuery : public BinaryQuery
{
friend Query operator&(const Query&, const Query&);
AndQuery(const Query& left, const Query& right):
BinaryQuery(left,right, "&")
BinaryQuery(left, right, "&")
{
std::cout << "AndQuery::AndQuery()\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.39.40/andquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AndQuery : public BinaryQuery
{
friend Query operator&(const Query&, const Query&);
AndQuery(const Query& left, const Query& right):
BinaryQuery(left,right, "&")
BinaryQuery(left, right, "&")
{
std::cout << "AndQuery::AndQuery()\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ch15/ex15.8.9.10/ex15.8.9.10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Recalling the discussion from §8.1 (p. 311), explain how the program on
// page 317 that passed an ifstream to the Sales_data read function works.
// the function takes a std::istream from which std::ifstream is derived.
// Hence the ifstream object "is a" istream ,which is why it works.
// Hence the ifstream object "is a" istream , which is why it works.
//

#include <iostream>
Expand Down
10 changes: 5 additions & 5 deletions ch16/ex16.12.13/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ void Blob<T>::check(size_type i, const std::string &msg) const
template<typename T>
T& Blob<T>::back()
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

template<typename T>
const T& Blob<T>::back() const
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

Expand All @@ -69,7 +69,7 @@ template<typename T>
T& Blob<T>::operator [](size_type i)
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

Expand All @@ -78,14 +78,14 @@ template<typename T>
const T& Blob<T>::operator [](size_type i) const
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

template<typename T>
void Blob<T>::pop_back()
{
check(0,"pop_back on empty Blob");
check(0, "pop_back on empty Blob");
data->pop_back();
}

Expand Down
4 changes: 2 additions & 2 deletions ch16/ex16.12.13/blobptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ template<typename T>
BlobPtr<T>& BlobPtr<T>::operator ++()
{
// if curr already points past the end of the container, can't increment it
check(curr,"increment past end of StrBlob");
check(curr, "increment past end of StrBlob");
++curr;
return *this;
}
Expand All @@ -66,7 +66,7 @@ template<typename T>
BlobPtr<T>& BlobPtr<T>::operator --()
{
-- curr;
check(curr,"decrement past begin of BlobPtr");
check(curr, "decrement past begin of BlobPtr");

return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion ch16/ex16.14.15/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

int main()
{
Screen<5,5> scr('c');
Screen<5, 5> scr('c');
Screen<5, 5> scr2;

// output src to the screen
Expand Down
10 changes: 5 additions & 5 deletions ch16/ex16.24/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ void Blob<T>::check(size_type i, const std::string &msg) const
template<typename T>
T& Blob<T>::back()
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

template<typename T>
const T& Blob<T>::back() const
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

Expand All @@ -89,7 +89,7 @@ template<typename T>
T& Blob<T>::operator [](size_type i)
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

Expand All @@ -98,14 +98,14 @@ template<typename T>
const T& Blob<T>::operator [](size_type i) const
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

template<typename T>
void Blob<T>::pop_back()
{
check(0,"pop_back on empty Blob");
check(0, "pop_back on empty Blob");
data->pop_back();
}

Expand Down
4 changes: 2 additions & 2 deletions ch16/ex16.24/blobptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ template<typename T>
BlobPtr<T>& BlobPtr<T>::operator ++()
{
// if curr already points past the end of the container, can't increment it
check(curr,"increment past end of StrBlob");
check(curr, "increment past end of StrBlob");
++curr;
return *this;
}
Expand All @@ -66,7 +66,7 @@ template<typename T>
BlobPtr<T>& BlobPtr<T>::operator --()
{
-- curr;
check(curr,"decrement past begin of BlobPtr");
check(curr, "decrement past begin of BlobPtr");

return *this;
}
Expand Down
10 changes: 5 additions & 5 deletions ch16/ex16.29/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ void Blob<T>::check(size_type i, const std::string &msg) const
template<typename T>
T& Blob<T>::back()
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

template<typename T>
const T& Blob<T>::back() const
{
check(0,"back on empty Blob");
check(0, "back on empty Blob");
return data->back();
}

Expand All @@ -101,7 +101,7 @@ template<typename T>
T& Blob<T>::operator [](size_type i)
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

Expand All @@ -110,14 +110,14 @@ template<typename T>
const T& Blob<T>::operator [](size_type i) const
{
// if i is too big, check function will throw, preventing access to a nonexistent element
check(i,"subscript out of range");
check(i, "subscript out of range");
return (*data)[i];
}

template<typename T>
void Blob<T>::pop_back()
{
check(0,"pop_back on empty Blob");
check(0, "pop_back on empty Blob");
data->pop_back();
}

Expand Down
Loading

0 comments on commit c584af2

Please sign in to comment.