|
46 | 46 |
|
47 | 47 | #include "util.h" |
48 | 48 |
|
| 49 | +namespace |
| 50 | +{ |
| 51 | +// Capture layout: |
| 52 | +// (1)=major, (2)=minor, (3)=patch, |
| 53 | +// (4)=suffix (may include dev-<sha>), (5)=timestamp. |
| 54 | +// Examples: |
| 55 | +// 3.10.1 -> (3,10,1,"","") |
| 56 | +// 3.10.1dev-2f2d2a1:1756656363 -> (3,10,1,"dev-2f2d2a1","1756656363") |
| 57 | +// 3.10.1dev-2f2d2a1 -> (3,10,1,"dev-2f2d2a1","") |
| 58 | +// 3.10.2rc1 -> (3,10,2,"rc1","") |
| 59 | +// v3.10.1 -> no match |
| 60 | +const QRegularExpression& GetSemVerRegex() |
| 61 | +{ |
| 62 | + static const QRegularExpression semVerRegex ( R"(^(\d+)\.(\d+)\.(\d+)-?([^:]*):?(.*)$)" ); |
| 63 | + return semVerRegex; |
| 64 | +} |
| 65 | +} // namespace |
| 66 | + |
| 67 | +bool IsMappedReleaseVersion ( const QString& mappedVersion ) |
| 68 | +{ |
| 69 | + // Mapped release keys are exactly "mmmnnnppp=" and contain no dot placeholders. |
| 70 | + return ( mappedVersion.size() == 10 ) && ( mappedVersion.at ( 9 ) == QLatin1Char ( '=' ) ) && ( !mappedVersion.contains ( QLatin1Char ( '.' ) ) ); |
| 71 | +} |
| 72 | + |
| 73 | +QString MapVersionStrForCompare ( const QString& versionStr ) |
| 74 | +{ |
| 75 | + QString key; |
| 76 | + QString x = ">"; // default suffix is later (git, dev, nightly, etc) |
| 77 | + |
| 78 | + // Build a lexicographically sortable key from regex captures so ordering is: |
| 79 | + // pre-release (alpha/beta/rc) < release (x.y.z) < post-release/dev/homebrew. |
| 80 | + // If capture (5) timestamp exists, it is used as the tie-break payload. |
| 81 | + QRegularExpressionMatch match = GetSemVerRegex().match ( versionStr ); |
| 82 | + |
| 83 | + if ( !match.hasMatch() ) |
| 84 | + { |
| 85 | + return QString ( "..." ) + versionStr; |
| 86 | + } |
| 87 | + |
| 88 | + bool majorOk = false; |
| 89 | + bool minorOk = false; |
| 90 | + bool patchOk = false; |
| 91 | + int major = match.captured ( 1 ).toInt ( &majorOk ); |
| 92 | + int minor = match.captured ( 2 ).toInt ( &minorOk ); |
| 93 | + int patch = match.captured ( 3 ).toInt ( &patchOk ); |
| 94 | + |
| 95 | + if ( !majorOk || !minorOk || !patchOk ) |
| 96 | + { |
| 97 | + return QString ( "..." ) + versionStr; |
| 98 | + } |
| 99 | + |
| 100 | + QString suffix = match.captured ( 4 ); // suffix, if present |
| 101 | + QString tstamp = match.captured ( 5 ); // timestamp, if present |
| 102 | + |
| 103 | + if ( suffix.isEmpty() ) |
| 104 | + { |
| 105 | + x = "="; // bare version number |
| 106 | + } |
| 107 | + else if ( suffix.startsWith ( "rc" ) || suffix.startsWith ( "beta" ) || suffix.startsWith ( "alpha" ) ) |
| 108 | + { |
| 109 | + x = "<"; // pre-release version |
| 110 | + } |
| 111 | + |
| 112 | + // construct a sortable key mmmnnnpppksuffix, where: |
| 113 | + // mmm = major |
| 114 | + // nnn = minor |
| 115 | + // ppp = patch |
| 116 | + // k = sort key to sort alpha, beta, rc before bare version number, and other suffixes after (<, =, >) |
| 117 | + // suffix = supplied suffix |
| 118 | + const QString majorPart = QString ( "%1" ).arg ( major, 3, 10, QLatin1Char ( '0' ) ); |
| 119 | + const QString minorPart = QString ( "%1" ).arg ( minor, 3, 10, QLatin1Char ( '0' ) ); |
| 120 | + const QString patchPart = QString ( "%1" ).arg ( patch, 3, 10, QLatin1Char ( '0' ) ); |
| 121 | + |
| 122 | + key = QString ( "%1%2%3%4%5" ).arg ( majorPart ).arg ( minorPart ).arg ( patchPart ).arg ( x ).arg ( tstamp.isEmpty() ? suffix : tstamp ); |
| 123 | + |
| 124 | + return key; |
| 125 | +} |
| 126 | + |
49 | 127 | /* Implementation *************************************************************/ |
50 | 128 | // Input level meter implementation -------------------------------------------- |
51 | 129 | void CStereoSignalLevelMeter::Update ( const CVector<short>& vecsAudio, const int iMonoBlockSizeSam, const bool bIsStereoIn ) |
|
0 commit comments