Parse a size string like "100M", "1G", "512K", "12345" (bytes default). Suffixes are case-insensitive and use binary multipliers (K=1024, M=1024*1024, G=1024*1024*1024). Returns true on success.
| 118 | // Suffixes are case-insensitive and use binary multipliers |
| 119 | // (K=1024, M=1024*1024, G=1024*1024*1024). Returns true on success. |
| 120 | static bool ParseSizeWithSuffix(const wxString& s, uint64& out) |
| 121 | { |
| 122 | if (s.IsEmpty()) { |
| 123 | return false; |
| 124 | } |
| 125 | wxString digits = s; |
| 126 | uint64 multiplier = 1; |
| 127 | const wxUniChar last = s.Last(); |
| 128 | if (!wxIsdigit(last)) { |
| 129 | switch (static_cast<int>(wxTolower(last))) { |
| 130 | case 'k': multiplier = 1024ULL; break; |
| 131 | case 'm': multiplier = 1024ULL * 1024; break; |
| 132 | case 'g': multiplier = 1024ULL * 1024 * 1024; break; |
| 133 | case 'b': multiplier = 1; break; |
| 134 | default: return false; |
| 135 | } |
| 136 | digits = s.Left(s.length() - 1); |
| 137 | } |
| 138 | unsigned long long n = 0; |
| 139 | if (!digits.ToULongLong(&n)) { |
| 140 | return false; |
| 141 | } |
| 142 | out = static_cast<uint64>(n) * multiplier; |
| 143 | return true; |
| 144 | } |
| 145 | |
| 146 | // Strip optional --type / --extension / --avail / --min-size / --max-size |
| 147 | // flags from `args`, leaving only the search keyword(s). Each flag takes |
no test coverage detected