mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: save all pending work
ref:
This commit is contained in:
32
lib/utils/avatar_label_helper.dart
Normal file
32
lib/utils/avatar_label_helper.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
class AvatarLabelHelper {
|
||||
static String buildLabel(String name) {
|
||||
final trimmed = name.trim();
|
||||
if (trimmed.isEmpty) return '?';
|
||||
|
||||
if (trimmed.startsWith('#')) {
|
||||
final hashBody = trimmed.substring(1).replaceAll(RegExp(r'[\s_-]+'), '');
|
||||
if (hashBody.isEmpty) {
|
||||
return '#';
|
||||
}
|
||||
return '#${_take(hashBody, 2)}'.toUpperCase();
|
||||
}
|
||||
|
||||
final parts = trimmed
|
||||
.split(RegExp(r'[\s_-]+'))
|
||||
.where((part) => part.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (parts.length >= 2) {
|
||||
final first = _take(parts[0], 1);
|
||||
final second = _take(parts[1], 1);
|
||||
return '$first$second'.toUpperCase();
|
||||
}
|
||||
|
||||
return _take(trimmed, 2).toUpperCase();
|
||||
}
|
||||
|
||||
static String _take(String value, int count) {
|
||||
if (value.length <= count) return value;
|
||||
return value.substring(0, count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user