Skip to content

Instantly share code, notes, and snippets.

@PlugFox
Last active December 5, 2021 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlugFox/9c7bbfabcea80d41d380b4ee8ae4c75d to your computer and use it in GitHub Desktop.
Save PlugFox/9c7bbfabcea80d41d380b4ee8ae4c75d to your computer and use it in GitHub Desktop.
Filter unicode symbols by code
/*
* Filter unicode symbols by code
* https://gist.github.com/PlugFox/9c7bbfabcea80d41d380b4ee8ae4c75d
* https://dartpad.dev/9c7bbfabcea80d41d380b4ee8ae4c75d?id=&null_safety=true
*/
import 'dart:math' as math;
const String source = r'#51\J-!dv@dT_o6w^iж,7nдomzGpаWq0ЁKlGsH"~!UZHdпф5i3`N(';
void main() => print(
String.fromCharCodes(
source.codeUnits.where((i) =>
UTF8CodeUnitsX.isDigit(i) ||
UTF8CodeUnitsX.isLatin(i) ||
UTF8CodeUnitsX.isCyrillic(i)),
),
);
extension UTF8CodeUnitsX on List<int> {
/// 0..9: 48..57
static bool isDigit(i) => i > 47 && i < 58;
/// A..Z: 65..90
/// a..z: 97..122
static bool isLatin(i) => (i > 64 && i < 91) || (i > 96 && i < 123);
/// Ё: 1025
/// А..Я: 1040..1071
/// а..я: 1072..1103
/// ё: 1105
static bool isCyrillic(i) => (i > 1039 && i < 1104) || i == 1025 || i == 1105;
Iterable<int> get onlyDigits => where(isDigit);
Iterable<int> get onlyLatin => where(isLatin);
Iterable<int> get onlyCyrillic => where(isCyrillic);
/// Maximum code
int get max => reduce(math.max);
/// Minimum code
int get min => reduce(math.min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment