Skip to content

Commit afdc394

Browse files
authored
book: add line breaks for code formatting (changkun#226)
1 parent 1db84fe commit afdc394

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

book/en-us/05-pointers.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,26 @@ auto pointer = std::make_shared<int>(10);
5858
auto pointer2 = pointer; // reference count+1
5959
auto pointer3 = pointer; // reference count+1
6060
int *p = pointer.get(); // no increase of reference count
61+
6162
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 3
6263
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 3
6364
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 3
6465
6566
pointer2.reset();
6667
std::cout << "reset pointer2:" << std::endl;
68+
6769
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 2
68-
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 0, pointer2 has reset
70+
std::cout << "pointer2.use_count() = "
71+
<< pointer2.use_count() << std::endl; // 0, pointer2 has reset
6972
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 2
73+
7074
pointer3.reset();
7175
std::cout << "reset pointer3:" << std::endl;
76+
7277
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 1
7378
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 0
74-
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 0, pointer3 has reset
79+
std::cout << "pointer3.use_count() = "
80+
<< pointer3.use_count() << std::endl; // 0, pointer3 has reset
7581
```
7682

7783
## 5.3 `std::unique_ptr`

book/en-us/06-regex.md

+21-17
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ We use a simple example to briefly introduce the use of this library. Consider t
8484

8585
int main() {
8686
std::string fnames[] = {"foo.txt", "bar.txt", "test", "a0.txt", "AAA.txt"};
87-
// In C++, `\` will be used as an escape character in the string. In order for `\.` to be passed as a regular expression, it is necessary to perform second escaping of `\`, thus we have `\\.`
87+
// In C++, `\` will be used as an escape character in the string. In order for `\.`
88+
// to be passed as a regular expression, it is necessary to perform second escaping of `\`, thus we have `\\.`
8889
std::regex txt_regex("[a-z]+\\.txt");
8990
for (const auto &fname: fnames)
9091
std::cout << fname << ": " << std::regex_match(fname, txt_regex) << std::endl;
@@ -186,29 +187,32 @@ Please implement the member functions `start()` and `parse_request`. Enable serv
186187
template<typename SERVER_TYPE>
187188
void start_server(SERVER_TYPE &server) {
188189
189-
// process GET request for /match/[digit+numbers], e.g. GET request is /match/abc123, will return abc123
190+
// process GET request for /match/[digit+numbers], e.g.
191+
// GET request is /match/abc123, will return abc123
190192
server.resource["fill_your_reg_ex"]["GET"] = [](ostream& response, Request& request) {
191193
string number=request.path_match[1];
192-
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
194+
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length()
195+
<< "\r\n\r\n" << number;
193196
};
194197
195198
// peocess default GET request; anonymous function will be called if no other matches
196199
// response files in folder web/
197200
// default: index.html
198-
server.default_resource["fill_your_reg_ex"]["GET"] = [](ostream& response, Request& request) {
199-
string filename = "www/";
200-
201-
string path = request.path_match[1];
202-
203-
// forbidden use `..` access content outside folder web/
204-
size_t last_pos = path.rfind(".");
205-
size_t current_pos = 0;
206-
size_t pos;
207-
while((pos=path.find('.', current_pos)) != string::npos && pos != last_pos) {
208-
current_pos = pos;
209-
path.erase(pos, 1);
210-
last_pos--;
211-
}
201+
server.default_resource["fill_your_reg_ex"]["GET"] =
202+
[](ostream& response, Request& request) {
203+
string filename = "www/";
204+
205+
string path = request.path_match[1];
206+
207+
// forbidden use `..` access content outside folder web/
208+
size_t last_pos = path.rfind(".");
209+
size_t current_pos = 0;
210+
size_t pos;
211+
while((pos=path.find('.', current_pos)) != string::npos && pos != last_pos) {
212+
current_pos = pos;
213+
path.erase(pos, 1);
214+
last_pos--;
215+
}
212216
213217
// (...)
214218
};

0 commit comments

Comments
 (0)