From 230a14fcf1481681ce5d360f3a2016b5bbb315fd Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 27 Jan 2017 21:27:24 +0100 Subject: [PATCH] Use string builder rather than stringstream --- id3/id3v2tag.cpp | 4 +--- margin.h | 12 +++++++----- matroska/ebmlelement.cpp | 2 -- matroska/ebmlelement.h | 14 +++++++------- matroska/matroskaeditionentry.cpp | 5 ++--- mp4/mp4container.cpp | 10 ++++++---- size.h | 8 ++++---- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/id3/id3v2tag.cpp b/id3/id3v2tag.cpp index eb2b2ac..ace4c77 100644 --- a/id3/id3v2tag.cpp +++ b/id3/id3v2tag.cpp @@ -313,9 +313,7 @@ void Id3v2Tag::setVersion(byte majorVersion, byte revisionVersion) { m_majorVersion = majorVersion; m_revisionVersion = revisionVersion; - stringstream versionStream(stringstream::in | stringstream::out); - versionStream << "2." << static_cast(majorVersion) << "." << static_cast(revisionVersion); - m_version = versionStream.str(); + m_version = '2' % '.' % numberToString(majorVersion) % '.' + numberToString(revisionVersion); } /*! diff --git a/margin.h b/margin.h index a4e1a90..6908267 100644 --- a/margin.h +++ b/margin.h @@ -4,9 +4,10 @@ #include "./global.h" #include +#include +#include #include -#include namespace Media { @@ -122,10 +123,11 @@ inline constexpr bool Margin::isNull() const */ inline std::string Margin::toString() const { - std::stringstream res; - res << "top: " << m_top << "; left: " << m_left; - res << "; bottom: " << m_bottom << "; right: " << m_right; - return std::string(res.str()); + using namespace ConversionUtilities; + return "top: " % numberToString(m_top) + % "; left: " % numberToString(m_left) + % "; bottom: " % numberToString(m_bottom) + % "; right: " + numberToString(m_right); } } diff --git a/matroska/ebmlelement.cpp b/matroska/ebmlelement.cpp index abdc235..02e1b3f 100644 --- a/matroska/ebmlelement.cpp +++ b/matroska/ebmlelement.cpp @@ -6,8 +6,6 @@ #include "../exceptions.h" #include -#include -#include #include #include #include diff --git a/matroska/ebmlelement.h b/matroska/ebmlelement.h index aa4b126..ddb1e1e 100644 --- a/matroska/ebmlelement.h +++ b/matroska/ebmlelement.h @@ -8,11 +8,11 @@ #include "../genericfileelement.h" #include +#include +#include #include #include -#include -#include namespace Media { @@ -89,13 +89,13 @@ private: */ inline std::string EbmlElement::idToString() const { - std::stringstream ss; - ss << "0x" << std::hex << id(); + using namespace ConversionUtilities; const char *name = matroskaIdName(id()); - if(std::char_traits::length(name)) { - ss << " \"" << name << "\""; + if(*name) { + return '0' % 'x' % numberToString(id(), 16) % ' ' % '\"' % name + '\"'; + } else { + return "0x" + numberToString(id(), 16); } - return ss.str(); } /*! diff --git a/matroska/matroskaeditionentry.cpp b/matroska/matroskaeditionentry.cpp index 72bbe31..5cf6c52 100644 --- a/matroska/matroskaeditionentry.cpp +++ b/matroska/matroskaeditionentry.cpp @@ -3,6 +3,7 @@ #include "./matroskaid.h" #include +#include #include #include @@ -39,9 +40,7 @@ MatroskaEditionEntry::~MatroskaEditionEntry() */ string MatroskaEditionEntry::label() const { - stringstream ss; - ss << "ID: " << id(); - return ss.str(); + return "ID: " + numberToString(id()); } /*! diff --git a/mp4/mp4container.cpp b/mp4/mp4container.cpp index 3fe4ab5..6eeb7fd 100644 --- a/mp4/mp4container.cpp +++ b/mp4/mp4container.cpp @@ -833,10 +833,12 @@ calculatePadding: if(rewriteRequired) { // check whether track count of new file equals track count of old file if(trackCount != tracks().size()) { - stringstream error; - error << "Unable to update chunk offsets (\"stco\"-atom): Number of tracks in the output file (" << tracks().size() - << ") differs from the number of tracks in the original file (" << trackCount << ")."; - addNotification(NotificationType::Critical, error.str(), context); + addNotification(NotificationType::Critical, + "Unable to update chunk offsets (\"stco\"-atom): Number of tracks in the output file (" + % numberToString(tracks().size()) + % ") differs from the number of tracks in the original file (" + % numberToString(trackCount) + + ").", context); throw Failure(); } diff --git a/size.h b/size.h index 7977a64..7f75185 100644 --- a/size.h +++ b/size.h @@ -4,9 +4,10 @@ #include "./global.h" #include +#include +#include #include -#include namespace Media { @@ -102,9 +103,8 @@ inline constexpr bool Size::operator==(const Size &other) const */ inline std::string Size::toString() const { - std::stringstream res; - res << "width: " << m_width << ", height: " << m_height; - return std::string(res.str()); + using namespace ConversionUtilities; + return "width: " % numberToString(m_width) % ", height: " + numberToString(m_height); } }