Audacity 3.2.0
AnonymizedMessage.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file AnonymizedMessage.cpp
6 @brief Define a class to store anonymized messages.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11#include "AnonymizedMessage.h"
12
13#include <regex>
14
15#include "CodeConversions.h"
16
17namespace audacity
18{
19namespace sentry
20{
21
23 : mMessage(std::move(message))
24{
26}
27
28AnonymizedMessage::AnonymizedMessage(const std::wstring& message)
29 : AnonymizedMessage(ToUTF8(message))
30{
31}
32
34 : AnonymizedMessage(ToUTF8(message))
35{
36}
37
39 : AnonymizedMessage(std::string(message))
40{
41}
42
44 : AnonymizedMessage(ToUTF8(message))
45{
46}
47
48bool AnonymizedMessage::Empty() const noexcept
49{
50 return mMessage.empty();
51}
52
53size_t AnonymizedMessage::Length() const noexcept
54{
55 return mMessage.size();
56}
57
58const std::string& AnonymizedMessage::GetString() const noexcept
59{
60 return mMessage;
61}
62
63wxString AnonymizedMessage::ToWXString() const noexcept
64{
66}
67
68const char* AnonymizedMessage::c_str() const noexcept
69{
70 return mMessage.c_str();
71}
72
73size_t AnonymizedMessage::length() const noexcept
74{
75 return mMessage.length();
76}
77
79{
80 // Finding the path boundary in the arbitrary text is a hard task.
81 // We assume that spaces cannot be a part of the path.
82 // In the worst case - we will get <path> <path>
83 static const std::regex re(
84 R"(\b(?:(?:[a-zA-Z]:)?[\\/]?)?(?:[^<>:"/|\\/?\s*]+[\\/]+)*(?:[^<>:"/|\\/?*\s]+\.\w+)?)");
85
86 mMessage = std::regex_replace(
87 mMessage, re, "<path>", std::regex_constants::match_not_null);
88}
89
90} // namespace sentry
91} // namespace audacity
Declare a class to store anonymized messages.
Declare functions to perform UTF-8 to std::wstring conversions.
A class, that stores anonymized message.
bool Empty() const noexcept
Checks, if the message is empty.
size_t length() const noexcept
Returns the length of the message.
const std::string & GetString() const noexcept
Returns the UTF8 representation of the message.
AnonymizedMessage()=default
Creates an empty message.
const char * c_str() const noexcept
Checks, if the message is empty.
wxString ToWXString() const noexcept
Convert the message to wxString.
size_t Length() const noexcept
Returns the length of the message.
std::string ToUTF8(const std::wstring &wstr)
wxString ToWXString(const std::string &str)
STL namespace.