4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
41 void call_notify(struct uuu_notify nf
);
46 int get_libusb_debug_level() noexcept
;
48 class string_ex
: public std::string
52 int format(const char *fmt
, ...)
56 size_t len
= std::vsnprintf(nullptr, 0, fmt
, args
);
62 std::vsnprintf((char*)c_str(), len
+1, fmt
, args
);
67 void replace(char a
, char b
)
69 for (size_t i
= 0; i
< size(); i
++)
75 class Path
: public string_ex
78 string
get_file_name()
83 if (pos
== string::npos
)
85 return substr(pos
+ 1);
89 inline uint64_t EndianSwap(uint64_t x
) {
90 return (((x
& 0x00000000000000ffLL
) << 56) |
91 ((x
& 0x000000000000ff00LL
) << 40) |
92 ((x
& 0x0000000000ff0000LL
) << 24) |
93 ((x
& 0x00000000ff000000LL
) << 8) |
94 ((x
& 0x000000ff00000000LL
) >> 8) |
95 ((x
& 0x0000ff0000000000LL
) >> 24) |
96 ((x
& 0x00ff000000000000LL
) >> 40) |
97 ((x
& 0xff00000000000000LL
) >> 56));
100 inline uint32_t EndianSwap(uint32_t x
)
103 ((x
<< 8) & 0x00FF0000) |
104 ((x
>> 8) & 0x0000FF00) |
107 inline uint16_t EndianSwap(uint16_t x
)
113 inline string
str_to_upper(const string
&str
)
118 for (size_t i
= 0; i
< str
.size(); i
++)
119 s
.push_back(std::toupper(str
[i
], loc
));
124 inline string
remove_quota(string str
)
131 if (!str
.empty() && str
[str
.size() - 1] == '"')
132 str
.erase(str
.size() - 1, 1);
138 inline bool compare_str(const string
&str1
, const string
&str2
, bool ignore_case
)
141 return str_to_upper(str1
) == str_to_upper(str2
);
146 uint16_t str_to_uint16(const string
&str
, bool * conversion_succeeded
= nullptr);
147 uint32_t str_to_uint32(const string
&str
, bool * conversion_succeeded
= nullptr);
148 uint64_t str_to_uint64(const string
&str
, bool * conversion_succeeded
= nullptr);
151 inline T
round_up(T x
, T align
)
153 return (x
+ align
- 1) / align
* align
;
157 inline T
div_round_up(T x
, T align
)
159 return (x
+ align
- 1) / align
;
162 inline std::string
trim(const std::string
&s
)
164 auto wsfront
= std::find_if_not(s
.begin(), s
.end(), [](int c
) {return std::isspace(c
); });
165 return std::string(wsfront
, std::find_if_not(s
.rbegin(), std::string::const_reverse_iterator(wsfront
), [](int c
) {return std::isspace(c
); }).base());