From e6820f5b59a3d9615863740bb16cec150206e326 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 19 Dec 2016 20:09:53 +0100 Subject: Compact id representation for sinksh list. Id clashes are possible but unlikely, but the compact id can't be used for other operations. --- sinksh/syntax_modules/sink_list.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'sinksh') diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 60a70c1..8c59064 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -40,6 +40,19 @@ namespace SinkList { +static QByteArray compressId(bool compress, const QByteArray &id) +{ + if (!compress) { + return id; + } + auto compactId = id.mid(1, id.length() - 2).split('-'); + if (compactId.isEmpty()) { + //Failed to compress id + return id; + } + return compactId.first(); +} + bool list(const QStringList &args_, State &state) { if (args_.isEmpty()) { @@ -71,6 +84,13 @@ bool list(const QStringList &args_, State &state) } + bool compact = false; + auto compactIndex = args.indexOf("--compact"); + if (compactIndex >= 0) { + args.removeAt(compactIndex); + compact = true; + } + auto allIndex = args.indexOf("--all"); if (allIndex >= 0) { args.removeAt(allIndex); @@ -102,11 +122,13 @@ bool list(const QStringList &args_, State &state) QStringList line; line << o.resourceInstanceIdentifier(); - line << o.identifier(); + line << compressId(compact, o.identifier()); for (const auto &prop: toPrint) { const auto value = o.getProperty(prop); if (value.isValid()) { - if (value.canConvert()) { + if (value.canConvert()) { + line << compressId(compact, value.toByteArray()); + } else if (value.canConvert()) { line << value.toString(); } else if (value.canConvert()) { line << value.toByteArray(); -- cgit v1.2.3