-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid cumbersome formatter workaround #6573
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:mockito/mockito.dart'; | ||
|
@@ -69,25 +68,15 @@ MockHttpClient createMockImageHttpClient(SecurityContext? _) { | |
return client; | ||
} | ||
|
||
// This string represents the hexidecial bytes of a transparent image. A | ||
// string is used to make the visual representation of the data compact. A | ||
// List<int> of the same data requires over 60 lines in a source file with | ||
// each element in the array on a single line. | ||
const String _imageBytesAsString = ''' | ||
// A list of integers that can be consumed as image data in a stream. | ||
final List<int> _transparentImage = <int>[ | ||
// Image bytes. | ||
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, | ||
0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, | ||
0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, | ||
0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D, | ||
0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, | ||
'''; | ||
|
||
// Convert the string representing the hexidecimal bytes in the image into | ||
// a list of integers that can be consumed as image data in a stream. | ||
final List<int> _transparentImage = const LineSplitter() | ||
.convert(_imageBytesAsString.replaceAllMapped( | ||
RegExp(r' *0x([A-F0-9]{2}),? *\n? *'), (Match m) => '${m[1]}\n')) | ||
.map<int>((String b) => int.parse(b, radix: 16)) | ||
.toList(); | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another, still simpler than the original, workaround would be: final String _imageBytesString =
'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49'
'\x48\x44\x52\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06'
'\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00\x0A\x49\x44'
'\x41\x54\x78\x9C\x63\x00\x01\x00\x00\x05\x00\x01\x0D'
'\x0A\x2D\xB4\x00\x00\x00\x00\x49\x45\x4E\x44\xAE';
final List<int> _transparentImage = [..._imageBytesString.codeUnits]; Having a full, formatted string, and parsing it using RegExp, just to get to some bytes, feels a little like overkill. |
||
|
||
List<int> getTestImageData() { | ||
return _transparentImage; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some possible improvements, for any similar code:
const LineSplitter().convert(...)
, one can just useLineSplitter.split(...)
.allMatches
, than to try to remove what's not numbers: