Skip to content

Commit 39f10b0

Browse files
committed
Move basename / prettify_symbol to utils.hpp
1 parent 9cc353b commit 39f10b0

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Cpptrace also has a C API, docs [here](docs/c-api.md).
2525
- [Utilities](#utilities)
2626
- [Formatting](#formatting)
2727
- [Transforms](#transforms)
28-
- [Formatting Utilities](#formatting-utilities)
2928
- [Configuration](#configuration)
3029
- [Logging](#logging)
3130
- [Traces From All Exceptions (`CPPTRACE_TRY` and `CPPTRACE_CATCH`)](#traces-from-all-exceptions-cpptrace_try-and-cpptrace_catch)
@@ -300,8 +299,14 @@ namespace cpptrace {
300299
301300
`cpptrace::demangle` is a helper function for name demangling, since it has to implement that helper internally anyways.
302301
303-
`cpptrace::prune_symbol` is a helper function that prunes demangled symbols by removing return types, template
304-
arguments, and function parameters. It also does some minimal normalization. For example, it prunes
302+
`cpptrace::basename` is a helper for custom formatters that extracts a base file name from a path.
303+
304+
`cpptrace::prettify_symbol` is a helper for custom formatters that applies a number of transformations to clean up long
305+
symbol names. For example, it turns `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >`
306+
into `std::string`.
307+
308+
`cpptrace::prune_symbol` is a helper for custom formatters that prunes demangled symbols by removing return types,
309+
template arguments, and function parameters. It also does some minimal normalization. For example, it prunes
305310
`ns::S<int, float>::~S()` to `ns::S::~S`.
306311
307312
`cpptrace::get_snippet` gets a text snippet, if possible, from for the given source file for +/- `context_size` lines
@@ -315,13 +320,19 @@ stack trace from a cpptrace exception (more info below) and otherwise behaves li
315320
```cpp
316321
namespace cpptrace {
317322
std::string demangle(const std::string& name);
323+
324+
std::string basename(const std::string& path);
325+
326+
std::string prettify_symbol(std::string symbol);
318327
std::string prune_symbol(const std::string& symbol);
328+
319329
std::string get_snippet(
320330
const std::string& path,
321331
std::size_t line,
322332
std::size_t context_size,
323333
bool color = false
324334
);
335+
325336
bool isatty(int fd);
326337
327338
extern const int stdin_fileno;
@@ -434,18 +445,6 @@ auto formatter = cpptrace::formatter{}
434445
});
435446
```
436447
437-
### Formatting Utilities
438-
439-
Cpptrace exports a couple formatting utilities used internally which might be useful for custom formatters that don't
440-
use `cpptrace::formatter`:
441-
442-
```cpp
443-
namespace cpptrace {
444-
std::string basename(const std::string& path);
445-
std::string prettify_symbol(std::string symbol);
446-
}
447-
```
448-
449448
## Configuration
450449
451450
`cpptrace::absorb_trace_exceptions`: Configure whether the library silently absorbs internal exceptions and continues.

include/cpptrace/formatting.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include <functional>
88

99
CPPTRACE_BEGIN_NAMESPACE
10-
CPPTRACE_EXPORT std::string basename(const std::string& path);
11-
CPPTRACE_EXPORT std::string prettify_symbol(std::string symbol);
12-
1310
class CPPTRACE_EXPORT formatter {
1411
class impl;
1512
// can't be a std::unique_ptr due to msvc awfulness with dllimport/dllexport and https://stackoverflow.com/q/4145605/15675011

include/cpptrace/utils.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515

1616
CPPTRACE_BEGIN_NAMESPACE
1717
CPPTRACE_EXPORT std::string demangle(const std::string& name);
18+
19+
CPPTRACE_EXPORT std::string basename(const std::string& path);
20+
CPPTRACE_EXPORT std::string prettify_symbol(std::string symbol);
1821
CPPTRACE_EXPORT std::string prune_symbol(const std::string& symbol);
22+
1923
CPPTRACE_EXPORT std::string get_snippet(
2024
const std::string& path,
2125
std::size_t line,
2226
std::size_t context_size,
2327
bool color = false
2428
);
29+
2530
CPPTRACE_EXPORT bool isatty(int fd);
2631

2732
CPPTRACE_EXPORT extern const int stdin_fileno;

0 commit comments

Comments
 (0)