-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathstring_utils.h
More file actions
91 lines (65 loc) · 2.92 KB
/
Copy pathstring_utils.h
File metadata and controls
91 lines (65 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>
#include "video_decoder.h"
extern "C" {
#include <libavcodec/codec_par.h>
#include <libavutil/rational.h>
}
// Constexpr string utilities
namespace ConstexprStringUtils {
// constexpr strlen for char literals
constexpr size_t cstrlen(const char* s) {
size_t n = 0;
while (s[n] != '\0') {
++n;
}
return n;
}
// Find the longest string length in an array of const char*
template <size_t N>
constexpr size_t longest_string_length(const char* const (&strings)[N]) {
size_t max_len = 0;
for (size_t i = 0; i < N; ++i) {
const size_t len = cstrlen(strings[i]);
if (len > max_len) {
max_len = len;
}
}
return max_len;
}
} // namespace ConstexprStringUtils
// Credits to user2622016 for this C++11 approach
// https://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
template <typename... Args>
static std::string string_sprintf(const std::string& format, Args... args) {
const int length = std::snprintf(nullptr, 0, format.c_str(), args...);
assert(length >= 0);
char* buf = new char[length + 1];
std::snprintf(buf, length + 1, format.c_str(), args...);
std::string str(buf);
delete[] buf;
return str;
}
std::string string_join(const std::vector<std::string>& strings, const std::string& delim);
std::vector<std::string> string_split(const std::string& str, char delim);
std::vector<std::string> tokenize_command_line_options(const std::string& input);
std::string format_command_line_for_log(const std::vector<std::string>& args);
std::string format_position(const float position, const bool use_compact);
std::string format_duration(const float duration);
double parse_strict_double(const std::string& s);
double parse_timestamps_to_seconds(const std::string& timestamp);
std::string to_lower_case(const std::string& str);
std::string to_upper_case(const std::string& str);
std::string::const_iterator string_ci_find(std::string& str, const std::string& query);
std::string stringify_field_order(const AVFieldOrder field_order, const std::string& unknown = "") noexcept;
std::string stringify_frame_rate_only(const AVRational frame_rate) noexcept;
std::string stringify_frame_rate(const AVRational frame_rate, const AVFieldOrder field_order) noexcept;
std::string stringify_decoder(const VideoDecoder* video_decoder) noexcept;
std::string stringify_fraction(const uint64_t num, const uint64_t den, const unsigned precision);
std::string stringify_file_size(const int64_t size, const unsigned precision = 0) noexcept;
std::string stringify_bit_rate(const int64_t bit_rate, const unsigned precision = 0) noexcept;
std::string stringify_pixel_format(const AVPixelFormat pixel_format, const AVColorRange color_range, const AVColorSpace color_space, const AVColorPrimaries color_primaries, const AVColorTransferCharacteristic color_trc) noexcept;
void print_wrapped(const std::string& text, const size_t line_length);