mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[Icons] Prevent double underscores after replacement (#96904)
* Prevent double underscores after replacement * add test * remove trailing space
This commit is contained in:
parent
ff09801941
commit
6bd0b95728
@ -36,4 +36,8 @@ void main() {
|
|||||||
expect(testIsStable(codepointsC, codepointsA), true);
|
expect(testIsStable(codepointsC, codepointsA), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('no double underscores', () {
|
||||||
|
expect(Icon.generateFlutterId('abc__123'), 'abc_123');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -275,10 +275,10 @@ String _regenerateIconsFile(
|
|||||||
String fontFamily,
|
String fontFamily,
|
||||||
bool enforceSafetyChecks,
|
bool enforceSafetyChecks,
|
||||||
) {
|
) {
|
||||||
final List<_Icon> newIcons = tokenPairMap.entries
|
final List<Icon> newIcons = tokenPairMap.entries
|
||||||
.map((MapEntry<String, String> entry) => _Icon(entry, fontFamily))
|
.map((MapEntry<String, String> entry) => Icon(entry, fontFamily))
|
||||||
.toList();
|
.toList();
|
||||||
newIcons.sort((_Icon a, _Icon b) => a._compareTo(b));
|
newIcons.sort((Icon a, Icon b) => a._compareTo(b));
|
||||||
|
|
||||||
final StringBuffer buf = StringBuffer();
|
final StringBuffer buf = StringBuffer();
|
||||||
bool generating = false;
|
bool generating = false;
|
||||||
@ -296,13 +296,13 @@ String _regenerateIconsFile(
|
|||||||
// Automatically finds and generates all icon declarations.
|
// Automatically finds and generates all icon declarations.
|
||||||
for (final String style in <String>['', '_outlined', '_rounded', '_sharp']) {
|
for (final String style in <String>['', '_outlined', '_rounded', '_sharp']) {
|
||||||
try {
|
try {
|
||||||
final _Icon agnosticIcon = newIcons.firstWhere(
|
final Icon agnosticIcon = newIcons.firstWhere(
|
||||||
(_Icon icon) => icon.id == '${ids[0]}$style',
|
(Icon icon) => icon.id == '${ids[0]}$style',
|
||||||
orElse: () => throw ids[0]);
|
orElse: () => throw ids[0]);
|
||||||
final _Icon iOSIcon = newIcons.firstWhere(
|
final Icon iOSIcon = newIcons.firstWhere(
|
||||||
(_Icon icon) => icon.id == '${ids[1]}$style',
|
(Icon icon) => icon.id == '${ids[1]}$style',
|
||||||
orElse: () => throw ids[1]);
|
orElse: () => throw ids[1]);
|
||||||
platformAdaptiveDeclarations.add(_Icon.platformAdaptiveDeclaration('$flutterId$style', agnosticIcon, iOSIcon),
|
platformAdaptiveDeclarations.add(Icon.platformAdaptiveDeclaration('$flutterId$style', agnosticIcon, iOSIcon),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (style == '') {
|
if (style == '') {
|
||||||
@ -327,7 +327,7 @@ String _regenerateIconsFile(
|
|||||||
// Generate for Icons
|
// Generate for Icons
|
||||||
if (line.contains(_beginGeneratedMark)) {
|
if (line.contains(_beginGeneratedMark)) {
|
||||||
generating = true;
|
generating = true;
|
||||||
final String iconDeclarationsString = newIcons.map((_Icon icon) => icon.fullDeclaration).join();
|
final String iconDeclarationsString = newIcons.map((Icon icon) => icon.fullDeclaration).join();
|
||||||
buf.write(iconDeclarationsString);
|
buf.write(iconDeclarationsString);
|
||||||
} else if (line.contains(_endGeneratedMark)) {
|
} else if (line.contains(_endGeneratedMark)) {
|
||||||
generating = false;
|
generating = false;
|
||||||
@ -388,9 +388,9 @@ void _regenerateCodepointsFile(File oldCodepointsFile, Map<String, String> newTo
|
|||||||
oldCodepointsFile.writeAsStringSync(buf.toString());
|
oldCodepointsFile.writeAsStringSync(buf.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Icon {
|
class Icon {
|
||||||
// Parse tokenPair (e.g. {"6_ft_apart_outlined": "e004"}).
|
// Parse tokenPair (e.g. {"6_ft_apart_outlined": "e004"}).
|
||||||
_Icon(MapEntry<String, String> tokenPair, this.fontFamily) {
|
Icon(MapEntry<String, String> tokenPair, this.fontFamily) {
|
||||||
id = tokenPair.key;
|
id = tokenPair.key;
|
||||||
hexCodepoint = tokenPair.value;
|
hexCodepoint = tokenPair.value;
|
||||||
|
|
||||||
@ -463,7 +463,7 @@ class _Icon {
|
|||||||
$declaration
|
$declaration
|
||||||
''';
|
''';
|
||||||
|
|
||||||
static String platformAdaptiveDeclaration(String fullFlutterId, _Icon agnosticIcon, _Icon iOSIcon) => '''
|
static String platformAdaptiveDeclaration(String fullFlutterId, Icon agnosticIcon, Icon iOSIcon) => '''
|
||||||
|
|
||||||
/// Platform-adaptive icon for ${agnosticIcon.dartDoc} and ${iOSIcon.dartDoc}.;
|
/// Platform-adaptive icon for ${agnosticIcon.dartDoc} and ${iOSIcon.dartDoc}.;
|
||||||
IconData get $fullFlutterId => !_isCupertino() ? Icons.${agnosticIcon.flutterId} : Icons.${iOSIcon.flutterId};
|
IconData get $fullFlutterId => !_isCupertino() ? Icons.${agnosticIcon.flutterId} : Icons.${iOSIcon.flutterId};
|
||||||
@ -473,7 +473,7 @@ class _Icon {
|
|||||||
String toString() => id;
|
String toString() => id;
|
||||||
|
|
||||||
/// Analogous to [String.compareTo]
|
/// Analogous to [String.compareTo]
|
||||||
int _compareTo(_Icon b) {
|
int _compareTo(Icon b) {
|
||||||
if (shortId == b.shortId) {
|
if (shortId == b.shortId) {
|
||||||
// Sort a regular icon before its variants.
|
// Sort a regular icon before its variants.
|
||||||
return id.length - b.id.length;
|
return id.length - b.id.length;
|
||||||
@ -501,7 +501,7 @@ class _Icon {
|
|||||||
String flutterId = id;
|
String flutterId = id;
|
||||||
// Exact identifier rewrites.
|
// Exact identifier rewrites.
|
||||||
for (final MapEntry<String, String> rewritePair in identifierExactRewrites.entries) {
|
for (final MapEntry<String, String> rewritePair in identifierExactRewrites.entries) {
|
||||||
final String shortId = _Icon._generateShortId(id);
|
final String shortId = Icon._generateShortId(id);
|
||||||
if (shortId == rewritePair.key) {
|
if (shortId == rewritePair.key) {
|
||||||
flutterId = id.replaceFirst(
|
flutterId = id.replaceFirst(
|
||||||
rewritePair.key,
|
rewritePair.key,
|
||||||
@ -518,6 +518,10 @@ class _Icon {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent double underscores.
|
||||||
|
flutterId = flutterId.replaceAll('__', '_');
|
||||||
|
|
||||||
return flutterId;
|
return flutterId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -699,16 +699,16 @@ class Icons {
|
|||||||
static const IconData sixty_fps_select_outlined = IconData(0xee1b, fontFamily: 'MaterialIcons');
|
static const IconData sixty_fps_select_outlined = IconData(0xee1b, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons md-36">6_ft_apart</i> — material icon named "6 ft apart".
|
/// <i class="material-icons md-36">6_ft_apart</i> — material icon named "6 ft apart".
|
||||||
static const IconData six__ft_apart = IconData(0xe02a, fontFamily: 'MaterialIcons');
|
static const IconData six_ft_apart = IconData(0xe02a, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-sharp md-36">6_ft_apart</i> — material icon named "6 ft apart" (sharp).
|
/// <i class="material-icons-sharp md-36">6_ft_apart</i> — material icon named "6 ft apart" (sharp).
|
||||||
static const IconData six__ft_apart_sharp = IconData(0xe72a, fontFamily: 'MaterialIcons');
|
static const IconData six_ft_apart_sharp = IconData(0xe72a, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-round md-36">6_ft_apart</i> — material icon named "6 ft apart" (round).
|
/// <i class="material-icons-round md-36">6_ft_apart</i> — material icon named "6 ft apart" (round).
|
||||||
static const IconData six__ft_apart_rounded = IconData(0xf509, fontFamily: 'MaterialIcons');
|
static const IconData six_ft_apart_rounded = IconData(0xf509, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-outlined md-36">6_ft_apart</i> — material icon named "6 ft apart" (outlined).
|
/// <i class="material-icons-outlined md-36">6_ft_apart</i> — material icon named "6 ft apart" (outlined).
|
||||||
static const IconData six__ft_apart_outlined = IconData(0xee1c, fontFamily: 'MaterialIcons');
|
static const IconData six_ft_apart_outlined = IconData(0xee1c, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons md-36">6k</i> — material icon named "6k".
|
/// <i class="material-icons md-36">6k</i> — material icon named "6k".
|
||||||
static const IconData six_k = IconData(0xe02b, fontFamily: 'MaterialIcons');
|
static const IconData six_k = IconData(0xe02b, fontFamily: 'MaterialIcons');
|
||||||
@ -4803,13 +4803,13 @@ class Icons {
|
|||||||
static const IconData class_ = IconData(0xe165, fontFamily: 'MaterialIcons');
|
static const IconData class_ = IconData(0xe165, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-sharp md-36">class</i> — material icon named "class" (sharp).
|
/// <i class="material-icons-sharp md-36">class</i> — material icon named "class" (sharp).
|
||||||
static const IconData class__sharp = IconData(0xe862, fontFamily: 'MaterialIcons');
|
static const IconData class_sharp = IconData(0xe862, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-round md-36">class</i> — material icon named "class" (round).
|
/// <i class="material-icons-round md-36">class</i> — material icon named "class" (round).
|
||||||
static const IconData class__rounded = IconData(0xf641, fontFamily: 'MaterialIcons');
|
static const IconData class_rounded = IconData(0xf641, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons-outlined md-36">class</i> — material icon named "class" (outlined).
|
/// <i class="material-icons-outlined md-36">class</i> — material icon named "class" (outlined).
|
||||||
static const IconData class__outlined = IconData(0xef54, fontFamily: 'MaterialIcons');
|
static const IconData class_outlined = IconData(0xef54, fontFamily: 'MaterialIcons');
|
||||||
|
|
||||||
/// <i class="material-icons md-36">clean_hands</i> — material icon named "clean hands".
|
/// <i class="material-icons md-36">clean_hands</i> — material icon named "clean hands".
|
||||||
static const IconData clean_hands = IconData(0xe166, fontFamily: 'MaterialIcons');
|
static const IconData clean_hands = IconData(0xe166, fontFamily: 'MaterialIcons');
|
||||||
|
Loading…
Reference in New Issue
Block a user