| 1 |
|
| #include <string.h> |
| 2 |
|
| #include <stdarg.h> |
| 3 |
|
| #include <stdio.h> |
| 4 |
|
| #include <stdlib.h> |
| 5 |
|
| #include <string> |
| 6 |
|
| #include <vector> |
| 7 |
|
| |
| 8 |
|
| #include "utils.h" |
| 9 |
|
| |
| 10 |
0 |
| std::string string_format(const std::string &fmt, ...) { |
| 11 |
0 |
| int n, size=100; |
| 12 |
0 |
| std::string str; |
| 13 |
|
| va_list ap; |
| 14 |
|
| while (1) { |
| 15 |
0 |
▶ | str.resize(size); |
Branch: 1 branch
| Branch | True | False | Total |
| str.resize(size); |
0 |
0 |
0 |
|
| 16 |
0 |
| va_start(ap, fmt); |
| 17 |
0 |
| int n = vsnprintf((char *)str.c_str(), size, fmt.c_str(), ap); |
| 18 |
0 |
| va_end(ap); |
| 19 |
0 |
▶ | if (n > -1 && n < size) |
Branch: 2 branches
| Branch | True | False | Total |
| if (n > -1 && n < size) |
0 |
0 |
0 |
| if (n > -1 && n < size) |
0 |
0 |
0 |
|
| 20 |
0 |
| return str; |
| 21 |
0 |
▶ | if (n > -1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > -1) |
0 |
0 |
0 |
|
| 22 |
0 |
| size=n+1; |
| 23 |
|
| else |
| 24 |
0 |
| size*=2; |
| 25 |
0 |
| } |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
0 |
| std::vector<char *> split(char* str,const char* delim) |
| 29 |
|
| { |
| 30 |
0 |
| char* token = strtok(str,delim); |
| 31 |
0 |
| std::vector<char *> result; |
| 32 |
0 |
▶ | while(token != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| while(token != NULL) |
0 |
0 |
0 |
|
| 33 |
|
| { |
| 34 |
0 |
▶ | result.push_back(token); |
Branch: 1 branch
| Branch | True | False | Total |
| result.push_back(token); |
0 |
0 |
0 |
|
| 35 |
0 |
| token = strtok(NULL,delim); |
| 36 |
|
| } |
| 37 |
0 |
| return result; |
| 38 |
|
| } |
| 39 |
|
| |