* opt: getFileName

* opt: audio-pitch-correction

* opt: spring dialog

* opt: account dialog

* update [skip ci]

---------

Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
My-Responsitories
2026-01-30 10:31:26 +08:00
committed by GitHub
parent 9442b17d63
commit d6e6e52df2
4 changed files with 183 additions and 169 deletions

View File

@@ -162,15 +162,28 @@ abstract final class Utils {
return randomBase64.substring(0, randomBase64.length - 2);
}
static int _getExt(String uri) {
final i = uri.indexOf('?');
return i == -1 ? uri.length : i;
}
static String getFileName(String uri, {bool fileExt = true}) {
final i0 = uri.lastIndexOf('/') + 1;
final i1 = fileExt ? _getExt(uri) : uri.lastIndexOf('.');
return uri.substring(i0, i1);
int slash = -1;
int dot = -1;
int qMark = uri.length;
loop:
for (int index = uri.length - 1; index >= 0; index--) {
switch (uri.codeUnitAt(index)) {
case 0x2F: // `/`
slash = index;
break loop;
case 0x2E: // `.`
if (dot == -1) dot = index;
break;
case 0x3F: // `?`
qMark = index;
if (dot > qMark) dot = -1;
break;
}
}
RangeError.checkNotNegative(slash, '/');
return uri.substring(slash + 1, (fileExt || dot == -1) ? qMark : dot);
}
/// When calling this from a `catch` block consider annotating the method