added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / util / hex_dump.hpp
1 /*************************************************************************
2  *
3  * Copyright 2016 Realm Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **************************************************************************/
18
19 #ifndef REALM_UTIL_HEX_DUMP_HPP
20 #define REALM_UTIL_HEX_DUMP_HPP
21
22 #include <cstddef>
23 #include <type_traits>
24 #include <limits>
25 #include <string>
26 #include <sstream>
27 #include <iomanip>
28
29 #include <realm/util/safe_int_ops.hpp>
30
31 namespace realm {
32 namespace util {
33
34 template <class T>
35 std::string hex_dump(const T* data, size_t size, const char* separator = " ", int min_digits = -1)
36 {
37     using U = typename std::make_unsigned<T>::type;
38
39     if (min_digits < 0)
40         min_digits = (std::numeric_limits<U>::digits + 3) / 4;
41
42     std::ostringstream out;
43     for (const T* i = data; i != data + size; ++i) {
44         if (i != data)
45             out << separator;
46         out << std::setw(min_digits) << std::setfill('0') << std::hex << std::uppercase << util::promote(U(*i));
47     }
48     return out.str();
49 }
50
51 } // namespace util
52 } // namespace realm
53
54 #endif // REALM_UTIL_HEX_DUMP_HPP