bitcoin_string/
string.rs

1crate::ix!();
2
3//-------------------------------------------[.cpp/bitcoin/src/util/string.h]
4//-------------------------------------------[.cpp/bitcoin/src/util/string.cpp]
5
6#[inline] pub fn trim_string(
7        str_:    &String,
8        pattern: Option<&str>) -> String {
9
10    //note: removed \f and \v from the c++ default
11    //pattern
12    let pattern: &str = pattern.unwrap_or(" \n\r\t");
13
14    todo!();
15        /*
16            std::string::size_type front = str.find_first_not_of(pattern);
17        if (front == std::string::npos) {
18            return std::string();
19        }
20        std::string::size_type end = str.find_last_not_of(pattern);
21        return str.substr(front, end - front + 1);
22        */
23}
24
25#[inline] pub fn remove_prefix(
26        str_:   &String,
27        prefix: &String) -> String {
28    
29    todo!();
30        /*
31            if (str.substr(0, prefix.size()) == prefix) {
32            return str.substr(prefix.size());
33        }
34        return str;
35        */
36}
37
38/**
39  | Join a list of items
40  | 
41  | -----------
42  | @param list
43  | 
44  | The list to join
45  | ----------
46  | @param separator
47  | 
48  | The separator
49  | ----------
50  | @param unary_op
51  | 
52  | Apply this operator to each item in the
53  | list
54  |
55  */
56lazy_static!{
57    /*
58    template <typename T, typename BaseType, typename UnaryOp>
59    auto Join(const std::vector<T>& list, const BaseType& separator, UnaryOp unary_op)
60        -> decltype(unary_op(list.at(0)))
61    {
62        decltype(unary_op(list.at(0))) ret;
63        for (size_t i = 0; i < list.size(); ++i) {
64            if (i > 0) ret += separator;
65            ret += unary_op(list.at(i));
66        }
67        return ret;
68    }
69    */
70}
71
72pub fn join(
73        list:      &Vec<String>,
74        separator: &str) -> String {
75
76    todo!();
77        /*
78            return Join(list, separator, [](const T& i) { return i; });
79        */
80}
81
82/**
83  | Create an unordered multi-line list
84  | of items.
85  |
86  */
87#[inline] pub fn make_unordered_list(items: &Vec<String>) -> String {
88    
89    todo!();
90        /*
91            return Join(items, "\n", [](const std::string& item) { return "- " + item; });
92        */
93}
94
95/**
96  | Check if a string does not contain any
97  | embedded NUL (\0) characters
98  |
99  */
100#[inline] pub fn valid_as_cstring(str_: &str) -> bool {
101    
102    todo!();
103        /*
104            return str.size() == strlen(str.c_str());
105        */
106}
107
108/**
109  | Locale-independent version of std::to_string
110  |
111  */
112
113pub fn to_string<T>(t: &T) -> String {
114
115    todo!();
116        /*
117            std::ostringstream oss;
118        oss.imbue(std::locale::classic());
119        oss << t;
120        return oss.str();
121        */
122}
123
124/**
125  | Check whether a container begins with
126  | the given prefix.
127  |
128  */
129#[inline] pub fn has_prefix<T1, const PREFIX_LEN: usize>(
130        obj:    &T1,
131        prefix: &[u8;PREFIX_LEN]) -> bool {
132
133    todo!();
134        /*
135            return obj.size() >= PREFIX_LEN &&
136               std::equal(std::begin(prefix), std::end(prefix), std::begin(obj));
137        */
138}