LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
taintedstring.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <QString>
12 
13 namespace LC::Util
14 {
15  template<typename L, typename R>
16  concept Concatable = requires (L&& l, R&& r) { std::forward<L> (l) + std::forward<R> (r); };
17 
19  {
20  QString String_;
21  public:
22  template<typename... Args>
23  requires std::constructible_from<QString, Args&&...>
24  explicit TaintedString (Args&&... args)
25  : String_ { std::forward<Args> (args)... }
26  {
27  }
28 
29  TaintedString (const TaintedString&) = default;
30  TaintedString (TaintedString&&) = default;
31  TaintedString& operator= (const TaintedString&) = default;
33 
34  [[nodiscard]] QString ToHtmlEscaped () const
35  {
36  return String_.toHtmlEscaped ();
37  }
38 
39  [[nodiscard]] QString UnsafeGetRaw () const
40  {
41  return String_;
42  }
43 
44  bool IsEmpty () const
45  {
46  return String_.isEmpty ();
47  }
48 
49  template<typename... Args>
50  requires (std::is_same_v<TaintedString, std::decay_t<Args>>&& ...)
51  friend TaintedString Format (const QString& pattern, Args&&... args)
52  {
53  return TaintedString { pattern.arg (std::forward_like<Args> (args.String_)...) };
54  }
55 
57  {
58  return TaintedString { l.String_ + r.String_ };
59  }
60 
61  template<typename T>
62  requires (!std::same_as<std::decay_t<T>, TaintedString>) && Concatable<const QString&, T&&>
63  friend TaintedString operator+ (const TaintedString& l, T&& r)
64  {
65  return TaintedString { l.String_ + std::forward<T> (r) };
66  }
67 
68  template<typename T>
69  requires (!std::same_as<std::decay_t<T>, TaintedString>) && Concatable<T&&, const QString&>
70  friend TaintedString operator+ (T&& l, const TaintedString& r)
71  {
72  return TaintedString { std::forward<T> (l) + r.String_ };
73  }
74  };
75 }
QString ToHtmlEscaped() const
Definition: taintedstring.h:34
friend TaintedString operator+(const TaintedString &l, const TaintedString &r)
Definition: taintedstring.h:56
requires std::constructible_from< QString, Args &&... > TaintedString(Args &&... args)
Definition: taintedstring.h:24
requires(std::is_same_v< TaintedString, std::decay_t< Args >> &&...) friend TaintedString Format(const QString &pattern
concept Concatable
Definition: taintedstring.h:16
requires(Tup1Size==Tup2Size) const expr auto ZipWith(Tup1 &&tup1
QString UnsafeGetRaw() const
Definition: taintedstring.h:39
TaintedString & operator=(const TaintedString &)=default