utils.cpp

filter: Statementstmt 0.0% 0 / 20 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 32 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« tidx.h ↑ Summary
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
while(token != NULL) 0 0 0
33 {
34 0 ▶ result.push_back(token);
Branch: 1 branch
BranchTrueFalseTotal
result.push_back(token); 0 0 0
35 0 token = strtok(NULL,delim);
36 }
37 0 return result;
38 }
39  
« tidx.h ↑ Summary