MythTV  master
Functions
StringUtil Namespace Reference

Functions

MBASE_PUBLIC bool isValidUTF8 (const QByteArray &data)
 
QString intToPaddedString (int n, int width=2)
 Creates a zero padded string representation of an integer. More...
 
QString indentSpaces (unsigned int level, unsigned int size=4)
 
QString bool_to_string (bool val)
 This is equivalent to QVariant(bool).toString() More...
 
MBASE_PUBLIC int naturalCompare (const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 This method chops the input a and b into pieces of digits and non-digits (a1.05 becomes a | 1 | . More...
 
bool naturalSortCompare (const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 naturalCompare as a std::sort compatible function (ignoring the third parameter, which is never used). More...
 
MBASE_PUBLIC QString formatKBytes (int64_t sizeKB, int prec=1)
 
MBASE_PUBLIC QString formatBytes (int64_t sizeB, int prec=1)
 

Function Documentation

◆ isValidUTF8()

bool StringUtil::isValidUTF8 ( const QByteArray &  data)

◆ intToPaddedString()

QString StringUtil::intToPaddedString ( int  n,
int  width = 2 
)
inline

Creates a zero padded string representation of an integer.

Parameters
ninteger to convert
widthminimum string length including sign, if any
Note
per the QString::arg() documentation the padding may prefix the sign of a negative number

Definition at line 24 of file stringutil.h.

Referenced by MythDate::formatTime(), VideoMetadata::GetText(), AvFormatDecoder::OpenFile(), PlaybackBox::saveRecMetadata(), VideoMetadata::toMap(), ResultItem::toMap(), ProgramInfo::ToMap(), RecordingSelector::updateRecordingList(), and MythBDBuffer::UpdateTitleInfo().

◆ indentSpaces()

QString StringUtil::indentSpaces ( unsigned int  level,
unsigned int  size = 4 
)
inline

◆ bool_to_string()

QString StringUtil::bool_to_string ( bool  val)
inline

◆ naturalCompare()

int StringUtil::naturalCompare ( const QString &  _a,
const QString &  _b,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)

This method chops the input a and b into pieces of digits and non-digits (a1.05 becomes a | 1 | .

| 05) and compares these pieces of a and b to each other (first with first, second with second, ...).

This is based on the natural sort order code code by Martin Pool http://sourcefrog.net/projects/natsort/ Martin Pool agreed to license this under LGPL or GPL.

Todo:
FIXME: Using toLower() to implement case insensitive comparison is sub-optimal, but is needed because we compare strings with localeAwareCompare(), which does not know about case sensitivity. A task has been filled for this in Qt Task Tracker with ID 205990. http://trolltech.com/developer/task-tracker/index_html?method=entry&id=205990 Dead link. QCollator might be of relevance.

Definition at line 160 of file stringutil.cpp.

Referenced by lt_callsign(), lt_smart(), naturalSortCompare(), TitleSort::operator()(), ProgramCountSort::operator()(), ProgramRecCountSort::operator()(), ProgramLastRecordSort::operator()(), ProgramAvgDelaySort::operator()(), plPrevTitleSort(), plTitleSort(), VideoMetadataImp::sortBefore(), Bookmark::sortByName(), and NewsSite::sortByName().

◆ naturalSortCompare()

bool StringUtil::naturalSortCompare ( const QString &  a,
const QString &  b,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)
inline

naturalCompare as a std::sort compatible function (ignoring the third parameter, which is never used).

Definition at line 54 of file stringutil.h.

Referenced by comp_sorttitle_lt(), comp_sorttitle_lt_rev(), VideoFilterSettings::meta_less_than(), SingleValueImp::sort(), and metadata_path_sort::sort().

◆ formatKBytes()

QString StringUtil::formatKBytes ( int64_t  sizeKB,
int  prec = 1 
)

◆ formatBytes()

QString StringUtil::formatBytes ( int64_t  sizeB,
int  prec = 1 
)

Definition at line 378 of file stringutil.cpp.

Referenced by CheckRecordings().