forked from qt-creator/qt-creator
Utils: Add io support for all BasicSmallStrings
Change-Id: I4c37d0f5940f9424175db7dbf4d6b057f8ced9ef Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -39,8 +39,8 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
inline
|
template <uint Size>
|
||||||
QDataStream &operator<<(QDataStream &out, const SmallString &string)
|
QDataStream &operator<<(QDataStream &out, const BasicSmallString<Size> &string)
|
||||||
{
|
{
|
||||||
if (string.isEmpty())
|
if (string.isEmpty())
|
||||||
out << quint32(0);
|
out << quint32(0);
|
||||||
@@ -50,8 +50,8 @@ QDataStream &operator<<(QDataStream &out, const SmallString &string)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
template <uint Size>
|
||||||
QDataStream &operator>>(QDataStream &in, SmallString &string)
|
QDataStream &operator>>(QDataStream &in, BasicSmallString<Size> &string)
|
||||||
{
|
{
|
||||||
quint32 size;
|
quint32 size;
|
||||||
|
|
||||||
@@ -83,13 +83,25 @@ std::ostream &operator<<(std::ostream &stream, const BasicSmallString<Size> &str
|
|||||||
{
|
{
|
||||||
using std::operator<<;
|
using std::operator<<;
|
||||||
|
|
||||||
return stream << std::string(string.data(), string.size());
|
stream.write(string.data(), std::streamsize(string.size()));
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
std::ostream &operator<<(std::ostream &stream, SmallStringView string)
|
||||||
|
{
|
||||||
|
using std::operator<<;
|
||||||
|
|
||||||
|
stream.write(string.data(), std::streamsize(string.size()));
|
||||||
|
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <uint Size>
|
template <uint Size>
|
||||||
void PrintTo(const BasicSmallString<Size> &string, ::std::ostream *os)
|
void PrintTo(const BasicSmallString<Size> &string, ::std::ostream *os)
|
||||||
{
|
{
|
||||||
Utils::SmallString formatedString = string.clone();
|
BasicSmallString<Size> formatedString = string.clone();
|
||||||
|
|
||||||
formatedString.replace("\n", "\\n");
|
formatedString.replace("\n", "\\n");
|
||||||
formatedString.replace("\t", "\\t");
|
formatedString.replace("\t", "\\t");
|
||||||
@@ -101,7 +113,8 @@ void PrintTo(const BasicSmallString<Size> &string, ::std::ostream *os)
|
|||||||
*os<< "'";
|
*os<< "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QDataStream &operator<<(QDataStream &out, const SmallStringVector &stringVector)
|
template <uint Size>
|
||||||
|
QDataStream &operator<<(QDataStream &out, const BasicSmallStringVector<Size> &stringVector)
|
||||||
{
|
{
|
||||||
out << quint64(stringVector.size());
|
out << quint64(stringVector.size());
|
||||||
|
|
||||||
@@ -111,8 +124,8 @@ inline QDataStream &operator<<(QDataStream &out, const SmallStringVector &string
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
template <uint Size>
|
||||||
QDataStream &operator>>(QDataStream &in, SmallStringVector &stringVector)
|
QDataStream &operator>>(QDataStream &in, BasicSmallStringVector<Size> &stringVector)
|
||||||
{
|
{
|
||||||
stringVector.clear();
|
stringVector.clear();
|
||||||
|
|
||||||
@@ -123,7 +136,7 @@ QDataStream &operator>>(QDataStream &in, SmallStringVector &stringVector)
|
|||||||
stringVector.reserve(size);
|
stringVector.reserve(size);
|
||||||
|
|
||||||
for (quint64 i = 0; i < size; ++i) {
|
for (quint64 i = 0; i < size; ++i) {
|
||||||
SmallString string;
|
BasicSmallString<Size> string;
|
||||||
|
|
||||||
in >> string;
|
in >> string;
|
||||||
|
|
||||||
@@ -133,18 +146,18 @@ QDataStream &operator>>(QDataStream &in, SmallStringVector &stringVector)
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
template <uint Size>
|
||||||
QDebug operator<<(QDebug debug, const SmallStringVector &stringVector)
|
QDebug operator<<(QDebug debug, const BasicSmallStringVector<Size> &stringVector)
|
||||||
{
|
{
|
||||||
debug << "StringVector(" << stringVector.join(Utils::SmallString(", ")).constData() << ")";
|
debug << "StringVector(" << stringVector.join(BasicSmallString<Size>(", ")).constData() << ")";
|
||||||
|
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
template <uint Size>
|
||||||
void PrintTo(const SmallStringVector &textVector, ::std::ostream* os)
|
void PrintTo(const BasicSmallStringVector<Size> &textVector, ::std::ostream* os)
|
||||||
{
|
{
|
||||||
*os << "[" << textVector.join(Utils::SmallString(", ")).constData() << "]";
|
*os << "[" << textVector.join(BasicSmallString<Size>(", ")).constData() << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
Reference in New Issue
Block a user