LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
qtutil.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 "sllconfig.h"
12#include <QLatin1String>
13
14namespace LC::Util
15{
42 template<typename Assoc>
43 auto Stlize (Assoc&& assoc)
44 {
45 struct Range
46 {
47 Assoc Assoc_;
48
49 auto begin () const { return Assoc_.keyValueBegin (); }
50 auto end () const { return Assoc_.keyValueEnd (); }
51 };
52
53 return Range { std::forward<Assoc> (assoc) };
54 }
55
68 inline QByteArray AsByteArray (std::string_view view)
69 {
70 return QByteArray::fromRawData (view.data (), view.size ());
71 }
72
83 inline QByteArray ToByteArray (std::string_view view)
84 {
85 return { view.data (), static_cast<int> (view.size ()) };
86 }
87
93 inline std::string_view AsStringView (const QByteArray& arr)
94 {
95 return { arr.constData (), static_cast<size_t> (arr.size ()) };
96 }
97}
98
99namespace LC
100{
101 constexpr QLatin1String operator"" _ql (const char *str, std::size_t size)
102 {
103 return QLatin1String { str, static_cast<int> (size) };
104 }
105}
auto Stlize(Assoc &&assoc)
Converts an Qt's associative sequence assoc to an STL-like iteratable range.
Definition: qtutil.h:43
QByteArray AsByteArray(std::string_view view)
Convert the view into a QByteArray without copying.
Definition: qtutil.h:68
QByteArray ToByteArray(std::string_view view)
Create a QByteArray with the data referenced by the view.
Definition: qtutil.h:83
std::string_view AsStringView(const QByteArray &arr)
Create a std::string_view referring the data within a QByteArray.
Definition: qtutil.h:93
Definition: constants.h:15