cppx-core
monospaced_bullet_block.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 #include <cppx-core/collections/String_value_view_.hpp> // cppx::String_value_view
3 #include <cppx-core/text/string-util.hpp> // cppx::(spaces, left)
4 
5 namespace cppx
6 {
7  CPPX_USE_STD( string, string_view );
8 
10  const string_view& s,
11  const string_view& bullet = best_effort::bullet_str,
12  const int indent_size = 4
13  ) -> string
14  {
15  if( is_empty( s ) ) { return ""; }
16  const auto indent = spaces( indent_size );
17 
18  string formatted = left( bullet, indent_size );
19  char prev_ch = '\0';
20  for( const char ch : s )
21  {
22  if( prev_ch == '\n' ) { formatted += indent; }
23  formatted += ch;
24  prev_ch = ch;
25  }
26  return formatted;
27  }
28 
29 } // namespace cppx
auto left(const string_view &s, const int width) -> string
Definition: string-util.hpp:48
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
auto is_empty(const Collection &c) -> Truth
Definition: is_empty.hpp:33
auto spaces(const int n) -> string
Definition: string-util.hpp:23
auto monospaced_bullet_block(const string_view &s, const string_view &bullet=best_effort::bullet_str, const int indent_size=4) -> string
constexpr auto & bullet_str