]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/pretty_binary.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "pretty_binary.h"
8 std::string
pretty_binary_string_reverse(const std::string
& pretty
)
11 auto raise
= [&](size_t failpos
) {
12 std::ostringstream ss
;
13 ss
<< "invalid char at pos " << failpos
<< " of " << pretty
;
14 throw std::invalid_argument(ss
.str());
16 auto hexdigit
= [&](unsigned char c
) -> int32_t {
17 if (c
>= '0' && c
<= '9') return c
- '0';
18 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 10;
19 if (c
>= 'A' && c
<= 'F') return c
- 'A' + 10;
22 auto require
= [&](unsigned char c
) {
23 if (i
>= pretty
.length() || pretty
[i
] != c
) {
31 bin
.reserve(pretty
.length());
41 if (i
== pretty
.length()) {
49 for (; i
< pretty
.length();) {
51 if (pretty
[i
] == '\'') {
52 if (i
+ 1 < pretty
.length() && pretty
[i
+ 1] == '\'') {
58 if (i
+ 1 < pretty
.length()) {
61 if (i
== pretty
.length()) {
67 bin
.push_back(pretty
[i
]);
71 if (pretty
[i
] != '\'') {
72 int32_t hex0
= hexdigit(pretty
[i
]);
77 if (i
>= pretty
.length()) {
80 int32_t hex1
= hexdigit(pretty
[i
]);
84 bin
.push_back(hex0
* 0x10 + hex1
);