Version upgrade 4.00 #45
|
@ -10,33 +10,24 @@ public:
|
|||
LogFileTreeWidgetItem(QTreeWidget*parent=nullptr):QTreeWidgetItem(parent){}
|
||||
bool operator < (const QTreeWidgetItem& other) const {
|
||||
const int sort_column{ this->treeWidget()->sortColumn() };
|
||||
const std::string s_str{ this->text(sort_column).toStdString() };
|
||||
const std::string o_str{ other.text(sort_column).toStdString() };
|
||||
const QString s_str{ this->text(sort_column) };
|
||||
const QString o_str{ other.text(sort_column) };
|
||||
if ( sort_column == 0 ) {
|
||||
// sort by file name
|
||||
const size_t s_sz{ s_str.size() - 1ul };
|
||||
const size_t o_sz{ o_str.size() - 1ul };
|
||||
const qsizetype s_sz{ s_str.size() };
|
||||
const qsizetype o_sz{ o_str.size() };
|
||||
if ( s_sz != o_sz ) {
|
||||
return s_sz < o_sz;
|
||||
}
|
||||
for (size_t i{0ul}; i<=s_sz; i++) {
|
||||
if ( s_str[i] != o_str[i] ) {
|
||||
return s_str[i] < o_str[i];
|
||||
}
|
||||
}
|
||||
return s_str < o_str;
|
||||
} else {
|
||||
// sort by file size
|
||||
const std::unordered_map<std::string,int> cmp{
|
||||
{"B", 0},
|
||||
{"KiB",1},
|
||||
{"MiB",2}
|
||||
};
|
||||
std::vector<std::string> s_items;
|
||||
StringOps::splitrip( s_items, s_str, ' ' );
|
||||
StringOps::splitrip( s_items, s_str.toStdString(), ' ' );
|
||||
std::vector<std::string> o_items;
|
||||
StringOps::splitrip( o_items, o_str, ' ' );
|
||||
StringOps::splitrip( o_items, o_str.toStdString(), ' ' );
|
||||
if ( s_items[1] != o_items[1] ) {
|
||||
return cmp.at( s_items[1] ) < cmp.at( o_items[1] );
|
||||
return s_items[1] < o_items[1];
|
||||
}
|
||||
return std::stof( s_items[0] ) < std::stof( o_items[0] );
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@ enum class LogType
|
|||
|
||||
|
||||
//! Holds informations about a log file
|
||||
class LogFile {
|
||||
public:
|
||||
explicit LogFile(){}
|
||||
struct LogFile {
|
||||
explicit LogFile() = default;
|
||||
explicit LogFile
|
||||
(const bool sel,const bool used,const size_t sz,const QString& nm,const std::string& hs,const std::string& pt)
|
||||
:selected{sel},used_already{used},size_{sz},name_{nm},hash_{hs},path_{pt}{}
|
||||
|
@ -60,9 +59,8 @@ Q_DECLARE_METATYPE( LogFile )
|
|||
|
||||
|
||||
//! Holds informations about a log format
|
||||
class LogsFormat {
|
||||
public:
|
||||
explicit LogsFormat(){}
|
||||
struct LogsFormat {
|
||||
explicit LogsFormat() = default;
|
||||
explicit LogsFormat
|
||||
(const std::string& str,const std::string& itl,const std::string& fnl,const std::vector<std::string>& seps,const std::vector<std::string>& flds,const unsigned nl)
|
||||
:string{str},initial{itl},final{fnl},separators{seps},fields{flds},new_lines{nl}{}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
#include "strings.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "chars.h"
|
||||
|
||||
|
||||
namespace StringOps
|
||||
{
|
||||
|
||||
size_t count( std::string_view str, const char flag )
|
||||
{
|
||||
return static_cast<size_t>( std::count( str.cbegin(), str.cend(), flag ) );
|
||||
}
|
||||
|
||||
size_t count( std::string_view str, std::string_view flag )
|
||||
{
|
||||
const size_t flg_size{ flag.size() };
|
||||
|
@ -22,139 +17,28 @@ size_t count( std::string_view str, std::string_view flag )
|
|||
}
|
||||
|
||||
|
||||
bool isNumeric( const char& chr )
|
||||
{
|
||||
return chr > 47 && chr < 58;
|
||||
}
|
||||
|
||||
bool isNumeric( std::string_view str )
|
||||
{
|
||||
if ( str.empty() ) {
|
||||
return false;
|
||||
}
|
||||
return !std::any_of( str.cbegin(), str.cend(),
|
||||
[]( const char& chr )
|
||||
{ return !isNumeric( chr ); });
|
||||
}
|
||||
|
||||
|
||||
bool isAlphabetic( const char& chr )
|
||||
{
|
||||
return (chr > 64 && chr < 91)
|
||||
|| (chr > 96 && chr < 123);
|
||||
}
|
||||
|
||||
bool isAlphabetic( std::string_view str )
|
||||
{
|
||||
if ( str.empty() ) {
|
||||
return false;
|
||||
}
|
||||
return !std::any_of( str.cbegin(), str.cend(),
|
||||
[]( const char& chr )
|
||||
{ return !isAlphabetic( chr ); });
|
||||
}
|
||||
|
||||
|
||||
bool isAlnum( const char& chr )
|
||||
{
|
||||
return isNumeric( chr )
|
||||
|| isAlphabetic( chr );
|
||||
}
|
||||
|
||||
bool isAlnum( std::string_view str )
|
||||
{
|
||||
if ( str.empty() ) {
|
||||
return false;
|
||||
}
|
||||
return !std::any_of( str.cbegin(), str.cend(),
|
||||
[]( const char& chr )
|
||||
{ return !isAlnum( chr ); });
|
||||
}
|
||||
|
||||
|
||||
bool isHex( const char& chr )
|
||||
{
|
||||
return (chr > 47 && chr < 58)
|
||||
|| (chr > 64 && chr < 71)
|
||||
|| (chr > 96 && chr < 103);
|
||||
}
|
||||
|
||||
|
||||
bool isIP( std::string_view str )
|
||||
{
|
||||
if ( str.empty() ) {
|
||||
return false;
|
||||
}
|
||||
for ( const char& chr : str ) {
|
||||
if ( chr == '.' || chr == ':' ) {
|
||||
continue;
|
||||
} else if ( ! isHex( chr ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool startsWith( std::string_view str, const char flag )
|
||||
{
|
||||
return str.front() == flag;
|
||||
}
|
||||
|
||||
bool startsWith( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.rfind( flag, 0ul ) == 0ul;
|
||||
}
|
||||
|
||||
|
||||
bool endsWith( std::string_view str, const char flag )
|
||||
{
|
||||
return str.back() == flag;
|
||||
}
|
||||
|
||||
bool endsWith( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.rfind( flag ) == str.size()-flag.size();
|
||||
}
|
||||
|
||||
|
||||
bool contains( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.find( flag ) != std::string::npos;
|
||||
}
|
||||
|
||||
|
||||
std::string strip( const std::string& str, const char chr )
|
||||
{
|
||||
size_t start{ str.find_first_not_of( chr ) };
|
||||
size_t stop{ str.find_last_not_of( chr ) };
|
||||
if ( start == std::string::npos ) {
|
||||
start++;
|
||||
if (const size_t start{ str.find_first_not_of( chr ) }; start != std::string::npos ) {
|
||||
const size_t stop{ str.find_last_not_of( chr ) };
|
||||
return str.substr( start, stop-start+1ul );
|
||||
}
|
||||
if ( stop == std::string::npos ) {
|
||||
stop = str.size();
|
||||
}
|
||||
return str.substr( start, stop-start+1ul );
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
std::string strip( const std::string& str, std::string_view chars )
|
||||
{
|
||||
size_t start{ str.find_first_not_of( chars ) };
|
||||
size_t stop{ str.find_last_not_of( chars ) };
|
||||
if ( start == std::string::npos ) {
|
||||
start++;
|
||||
if (const size_t start{ str.find_first_not_of( chars ) }; start != std::string::npos ) {
|
||||
const size_t stop{ str.find_last_not_of( chars ) };
|
||||
return str.substr( start, stop-start+1ul );
|
||||
}
|
||||
if ( stop == std::string::npos ) {
|
||||
stop = str.size();
|
||||
}
|
||||
return str.substr( start, stop-start+1ul );
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
|
||||
std::string lstrip( const std::string& str, const char chr )
|
||||
{
|
||||
const size_t start{ str.find_first_not_of( chr ) };
|
||||
if ( start != std::string::npos ) {
|
||||
if (const size_t start{ str.find_first_not_of( chr ) }; start != std::string::npos ) {
|
||||
return str.substr( start );
|
||||
}
|
||||
return std::string{};
|
||||
|
@ -162,8 +46,7 @@ std::string lstrip( const std::string& str, const char chr )
|
|||
|
||||
std::string lstrip( const std::string& str, std::string_view chars )
|
||||
{
|
||||
const size_t start{ str.find_first_not_of( chars ) };
|
||||
if ( start != std::string::npos ) {
|
||||
if (const size_t start{ str.find_first_not_of( chars ) }; start != std::string::npos ) {
|
||||
return str.substr( start );
|
||||
}
|
||||
return std::string{};
|
||||
|
@ -172,8 +55,7 @@ std::string lstrip( const std::string& str, std::string_view chars )
|
|||
|
||||
std::string rstrip( const std::string &str, const char chr )
|
||||
{
|
||||
const size_t stop{ str.find_last_not_of( chr ) };
|
||||
if ( stop != std::string::npos ) {
|
||||
if (const size_t stop{ str.find_last_not_of( chr ) }; stop != std::string::npos ) {
|
||||
return str.substr( 0ul, stop+1ul );
|
||||
}
|
||||
return std::string{};
|
||||
|
@ -181,8 +63,7 @@ std::string rstrip( const std::string &str, const char chr )
|
|||
|
||||
std::string rstrip( const std::string& str, std::string_view chars )
|
||||
{
|
||||
const size_t stop{ str.find_last_not_of( chars ) };
|
||||
if ( stop != std::string::npos ) {
|
||||
if (const size_t stop{ str.find_last_not_of( chars ) }; stop != std::string::npos ) {
|
||||
return str.substr( 0ul, stop+1ul );
|
||||
}
|
||||
return std::string{};
|
||||
|
@ -191,19 +72,21 @@ std::string rstrip( const std::string& str, std::string_view chars )
|
|||
|
||||
std::string lstripUntil( const std::string& str, const char delim, const bool inclusive, const bool consecutives )
|
||||
{
|
||||
size_t start{ str.find( delim ) };
|
||||
if ( start == std::string::npos ) {
|
||||
return str;
|
||||
}
|
||||
if ( inclusive ) {
|
||||
start ++;
|
||||
if ( consecutives ) {
|
||||
while ( str.find( delim, start ) == start ) {
|
||||
start ++;
|
||||
if (size_t start{ str.find( delim ) }; start != std::string::npos ) {
|
||||
if ( inclusive ) {
|
||||
start ++;
|
||||
if ( consecutives ) {
|
||||
if (str[start] == delim) {
|
||||
start = str.find_first_not_of( delim, start );
|
||||
if ( start == std::string::npos ) {
|
||||
return std::string{};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return str.substr( start );
|
||||
}
|
||||
return str.substr( start );
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
@ -258,7 +141,7 @@ void splitrip( std::vector<std::string>& list, const std::string& target_str, st
|
|||
{
|
||||
split( list, strip( target_str, strips ), separator );
|
||||
std::transform( list.begin(), list.end(), list.begin(),
|
||||
[&strips]( const std::string& str )
|
||||
[strips]( const std::string& str )
|
||||
{ return strip( str, strips ); } );
|
||||
}
|
||||
|
||||
|
@ -281,7 +164,7 @@ std::string toUpper( std::string_view str )
|
|||
{
|
||||
std::string up{ str };
|
||||
std::transform( up.begin(), up.end(), up.begin(),
|
||||
[]( const char& c )
|
||||
[]( const char c )
|
||||
{ return std::toupper( c ); } );
|
||||
return up;
|
||||
}
|
||||
|
@ -291,7 +174,7 @@ std::string toLower( std::string_view str )
|
|||
{
|
||||
std::string low{ str };
|
||||
std::transform( low.begin(), low.end(), low.begin(),
|
||||
[]( const char& c )
|
||||
[]( const char c )
|
||||
{ return std::tolower( c ); } );
|
||||
return low;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef LOGDOCTOR__UTILITIES__STRINGS_H
|
||||
#define LOGDOCTOR__UTILITIES__STRINGS_H
|
||||
|
||||
#include "chars.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <bits/stl_algo.h>
|
||||
|
||||
|
||||
//! StringOps
|
||||
|
@ -19,7 +21,10 @@ namespace StringOps
|
|||
\param flag The character to find
|
||||
\return The number of occurrences
|
||||
*/
|
||||
size_t count( std::string_view str, const char flag );
|
||||
inline size_t count( std::string_view str, const char flag )
|
||||
{
|
||||
return static_cast<size_t>( std::count( str.cbegin(), str.cend(), flag ) );
|
||||
}
|
||||
|
||||
//! Count the occurrences of the given sequence in the given string
|
||||
/*!
|
||||
|
@ -29,57 +34,41 @@ size_t count( std::string_view str, const char flag );
|
|||
*/
|
||||
size_t count( std::string_view str, std::string_view flag );
|
||||
|
||||
//! Checks whether character is numeric
|
||||
/*!
|
||||
\param str The target character
|
||||
\return The result of the check
|
||||
\see isNumeric()
|
||||
*/
|
||||
bool isNumeric( const char& chr );
|
||||
|
||||
//! Checks whether a string only contains numeric characters
|
||||
/*!
|
||||
\param str The target string
|
||||
\return The result of the check
|
||||
*/
|
||||
bool isNumeric( std::string_view str );
|
||||
|
||||
//! Checks whether a character is alphabetic
|
||||
/*!
|
||||
\param str The target character
|
||||
\return The result of the check
|
||||
\see isAlphabetic()
|
||||
*/
|
||||
bool isAlphabetic( const char& chr );
|
||||
inline bool isNumeric( std::string_view str )
|
||||
{
|
||||
return str.empty()
|
||||
? false
|
||||
: std::all_of( str.cbegin(), str.cend(), CharOps::isNumeric );
|
||||
}
|
||||
|
||||
//! Checks whether a string only contains alphabetic characters
|
||||
/*!
|
||||
\param str The target string
|
||||
\return The result of the check
|
||||
*/
|
||||
bool isAlphabetic( std::string_view str );
|
||||
|
||||
//! Checks whether a character is alpha-numeric
|
||||
/*!
|
||||
\param str The target character
|
||||
\return The result of the check
|
||||
\see isAlnum
|
||||
*/
|
||||
bool isAlnum( const char& chr );
|
||||
inline bool isAlphabetic( std::string_view str )
|
||||
{
|
||||
return str.empty()
|
||||
? false
|
||||
: std::all_of( str.cbegin(), str.cend(), CharOps::isAlphabetic );
|
||||
}
|
||||
|
||||
//! Checks whether a string only contains alpha-numeric characters
|
||||
/*!
|
||||
\param str The target string
|
||||
\return The result of the check
|
||||
*/
|
||||
bool isAlnum( std::string_view str );
|
||||
|
||||
//! Checks whether a string only contains hexadecimal characters
|
||||
/*!
|
||||
\param str The target character
|
||||
\return The result of the check
|
||||
*/
|
||||
bool isHex( const char& chr );
|
||||
inline bool isAlnum( std::string_view str )
|
||||
{
|
||||
return str.empty()
|
||||
? false
|
||||
: std::all_of( str.cbegin(), str.cend(), CharOps::isAlnum );
|
||||
}
|
||||
|
||||
//! Checks whether a string contains only IPv4/IPv6 chars
|
||||
/*!
|
||||
|
@ -88,7 +77,12 @@ bool isHex( const char& chr );
|
|||
\param str The target string
|
||||
\return The result of the check
|
||||
*/
|
||||
bool isIP( std::string_view str );
|
||||
inline bool isIP( std::string_view str )
|
||||
{
|
||||
return str.empty()
|
||||
? false
|
||||
: std::all_of( str.cbegin(), str.cend(), CharOps::isIP );
|
||||
}
|
||||
|
||||
//! Checks if a string starts with the given sequence
|
||||
/*!
|
||||
|
@ -96,7 +90,10 @@ bool isIP( std::string_view str );
|
|||
\param flag The character to search for
|
||||
\return The result of the check
|
||||
*/
|
||||
bool startsWith( std::string_view str, const char flag );
|
||||
inline bool startsWith( std::string_view str, const char flag )
|
||||
{
|
||||
return str.front() == flag;
|
||||
}
|
||||
|
||||
//! Checks if a string starts with the given sequence
|
||||
/*!
|
||||
|
@ -105,7 +102,10 @@ bool startsWith( std::string_view str, const char flag );
|
|||
\param flag The sequence to search for
|
||||
\return The result of the check
|
||||
*/
|
||||
bool startsWith( std::string_view str, std::string_view flag );
|
||||
inline bool startsWith( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.rfind( flag, 0ul ) == 0ul;
|
||||
}
|
||||
|
||||
//! Checks if a string ends with the given sequence
|
||||
/*!
|
||||
|
@ -113,7 +113,10 @@ bool startsWith( std::string_view str, std::string_view flag );
|
|||
\param flag The character to search for
|
||||
\return The result of the check
|
||||
*/
|
||||
bool endsWith( std::string_view str, const char flag );
|
||||
inline bool endsWith( std::string_view str, const char flag )
|
||||
{
|
||||
return str.back() == flag;
|
||||
}
|
||||
|
||||
//! Checks if a string ends with the given sequence
|
||||
/*!
|
||||
|
@ -122,7 +125,10 @@ bool endsWith( std::string_view str, const char flag );
|
|||
\param flag The sequence to search for
|
||||
\return The result of the check
|
||||
*/
|
||||
bool endsWith( std::string_view str, std::string_view flag );
|
||||
inline bool endsWith( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.rfind( flag ) == str.size()-flag.size();
|
||||
}
|
||||
|
||||
//! Checks if a string contains the given sequence
|
||||
/*!
|
||||
|
@ -130,7 +136,10 @@ bool endsWith( std::string_view str, std::string_view flag );
|
|||
\param flag The sequence to search for
|
||||
\return The result of the check
|
||||
*/
|
||||
bool contains( std::string_view str, std::string_view flag );
|
||||
inline bool contains( std::string_view str, std::string_view flag )
|
||||
{
|
||||
return str.find( flag ) != std::string::npos;
|
||||
}
|
||||
|
||||
//! Strips the given character from both the left and the right side of a string
|
||||
/*!
|
||||
|
|
Loading…
Reference in a new issue