|
5 | 5 | #include "vtr_util.h"
|
6 | 6 | #include "vtr_error.h"
|
7 | 7 |
|
8 |
| -std::optional<int> try_convert_to_int(const std::string& str) |
9 |
| -{ |
| 8 | +std::optional<int> try_convert_to_int(const std::string& str) { |
10 | 9 | try {
|
11 | 10 | return vtr::atoi(str);
|
12 | 11 | } catch (const vtr::VtrError&) {
|
13 | 12 | return std::nullopt;
|
14 | 13 | }
|
15 | 14 | }
|
16 | 15 |
|
17 |
| -static std::string getPrettyStrFromFloat(float value) |
18 |
| -{ |
| 16 | +static std::string get_pretty_str_from_float(float value) { |
19 | 17 | std::ostringstream ss;
|
20 | 18 | ss << std::fixed << std::setprecision(2) << value; // Set precision to 2 digit after the decimal point
|
21 | 19 | return ss.str();
|
22 | 20 | }
|
23 | 21 |
|
24 |
| -std::string getPrettyDurationStrFromMs(int64_t durationMs) |
25 |
| -{ |
| 22 | +std::string get_pretty_duration_str_from_ms(int64_t duration_ms) { |
26 | 23 | std::string result;
|
27 |
| - if (durationMs >= 1000) { |
28 |
| - result = getPrettyStrFromFloat(durationMs / 1000.0f) + " sec"; |
| 24 | + if (duration_ms >= 1000) { |
| 25 | + result = get_pretty_str_from_float(duration_ms / 1000.0f) + " sec"; |
29 | 26 | } else {
|
30 |
| - result = std::to_string(durationMs); |
| 27 | + result = std::to_string(duration_ms); |
31 | 28 | result += " ms";
|
32 | 29 | }
|
33 | 30 | return result;
|
34 | 31 | }
|
35 | 32 |
|
36 |
| -std::string get_pretty_size_str_from_bytes_num(int64_t bytesNum) |
37 |
| -{ |
| 33 | +std::string get_pretty_size_str_from_bytes_num(int64_t bytes_num) { |
38 | 34 | std::string result;
|
39 |
| - if (bytesNum >= 1024*1024*1024) { |
40 |
| - result = getPrettyStrFromFloat(bytesNum / float(1024*1024*1024)) + "Gb"; |
41 |
| - } else if (bytesNum >= 1024*1024) { |
42 |
| - result = getPrettyStrFromFloat(bytesNum / float(1024*1024)) + "Mb"; |
43 |
| - } else if (bytesNum >= 1024) { |
44 |
| - result = getPrettyStrFromFloat(bytesNum / float(1024)) + "Kb"; |
| 35 | + if (bytes_num >= 1024*1024*1024) { |
| 36 | + result = get_pretty_str_from_float(bytes_num / float(1024*1024*1024)) + "Gb"; |
| 37 | + } else if (bytes_num >= 1024*1024) { |
| 38 | + result = get_pretty_str_from_float(bytes_num / float(1024*1024)) + "Mb"; |
| 39 | + } else if (bytes_num >= 1024) { |
| 40 | + result = get_pretty_str_from_float(bytes_num / float(1024)) + "Kb"; |
45 | 41 | } else {
|
46 |
| - result = std::to_string(bytesNum) + "bytes"; |
| 42 | + result = std::to_string(bytes_num) + "bytes"; |
47 | 43 | }
|
48 | 44 | return result;
|
49 | 45 | }
|
50 | 46 |
|
51 |
| - |
52 | 47 | std::string get_truncated_middle_str(const std::string& src, std::size_t num) {
|
53 | 48 | std::string result;
|
54 |
| - static std::size_t minimalStringSizeToTruncate = 20; |
55 |
| - if (num < minimalStringSizeToTruncate) { |
56 |
| - num = minimalStringSizeToTruncate; |
| 49 | + static std::size_t minimal_string_size_to_truncate = 20; |
| 50 | + if (num < minimal_string_size_to_truncate) { |
| 51 | + num = minimal_string_size_to_truncate; |
57 | 52 | }
|
58 |
| - static std::string middlePlaceHolder("..."); |
59 |
| - const std::size_t srcSize = src.size(); |
60 |
| - if (srcSize > num) { |
61 |
| - int prefixNum = num / 2; |
62 |
| - int suffixNum = num / 2 - middlePlaceHolder.size(); |
63 |
| - result.append(src.substr(0, prefixNum)); |
64 |
| - result.append(middlePlaceHolder); |
65 |
| - result.append(src.substr(srcSize - suffixNum)); |
| 53 | + static std::string middle_place_holder("..."); |
| 54 | + const std::size_t src_size = src.size(); |
| 55 | + if (src_size > num) { |
| 56 | + int prefix_num = num / 2; |
| 57 | + int suffix_num = num / 2 - middle_place_holder.size(); |
| 58 | + result.append(src.substr(0, prefix_num)); |
| 59 | + result.append(middle_place_holder); |
| 60 | + result.append(src.substr(src_size - suffix_num)); |
66 | 61 | } else {
|
67 | 62 | result = src;
|
68 | 63 | }
|
|
0 commit comments