]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/strescape.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / strescape.h
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2021 Red Hat, Inc.
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef CEPH_STRESCAPE_H
16#define CEPH_STRESCAPE_H
17
20effc67 18#include <algorithm>
f67539c2
TL
19#include <ostream>
20#include <string_view>
21
22#include <ctype.h>
23
24inline std::string binstrprint(std::string_view sv, size_t maxlen=0)
25{
26 std::string s;
27 if (maxlen == 0 || sv.size() < maxlen) {
28 s = std::string(sv);
29 } else {
30 maxlen = std::max<size_t>(8, maxlen);
20effc67 31 s = std::string(sv.substr(0, maxlen-3)) + "...";
f67539c2
TL
32 }
33 std::replace_if(s.begin(), s.end(), [](char c){ return !(isalnum(c) || ispunct(c)); }, '.');
34 return s;
35}
36
37#endif