Implementing switch expressions in flutter_tools/ (#145632)

This pull request is step 12 in the journey to make this entire repository more readable.

(previous PRs: #139048, #139882, #141591, #142279, #142634, #142793, #143293, #143496, #143634, #143812, #144580)

We're getting close to the end! 😄
This commit is contained in:
Nate
2024-03-29 16:31:19 -06:00
committed by GitHub
parent 7f6685658c
commit a17d4b34f0
20 changed files with 222 additions and 409 deletions

View File

@@ -122,25 +122,15 @@ class LogLine {
}
static String clarify(String line) {
return line.runes.map<String>((int rune) {
if (rune >= 0x20 && rune <= 0x7F) {
return String.fromCharCode(rune);
}
switch (rune) {
case 0x00:
return '<NUL>';
case 0x07:
return '<BEL>';
case 0x08:
return '<TAB>';
case 0x09:
return '<BS>';
case 0x0A:
return '<LF>';
case 0x0D:
return '<CR>';
}
return '<${rune.toRadixString(16).padLeft(rune <= 0xFF ? 2 : rune <= 0xFFFF ? 4 : 5, '0')}>';
return line.runes.map<String>((int rune) => switch (rune) {
>= 0x20 && <= 0x7F => String.fromCharCode(rune),
0x00 => '<NUL>',
0x07 => '<BEL>',
0x08 => '<TAB>',
0x09 => '<BS>',
0x0A => '<LF>',
0x0D => '<CR>',
_ => '<${rune.toRadixString(16).padLeft(rune <= 0xFF ? 2 : rune <= 0xFFFF ? 4 : 5, '0')}>',
}).join();
}
}

View File

@@ -20,23 +20,15 @@ enum HttpMethod {
}
HttpMethod _fromMethodString(String value) {
final String name = value.toLowerCase();
switch (name) {
case 'get':
return HttpMethod.get;
case 'put':
return HttpMethod.put;
case 'delete':
return HttpMethod.delete;
case 'post':
return HttpMethod.post;
case 'patch':
return HttpMethod.patch;
case 'head':
return HttpMethod.head;
default:
throw StateError('Unrecognized HTTP method $value');
}
return switch (value.toLowerCase()) {
'get' => HttpMethod.get,
'put' => HttpMethod.put,
'delete' => HttpMethod.delete,
'post' => HttpMethod.post,
'patch' => HttpMethod.patch,
'head' => HttpMethod.head,
_ => throw StateError('Unrecognized HTTP method $value'),
};
}
String _toMethodString(HttpMethod method) {