You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
class Cyr2Lat {
static Map < String , String > _charMap = {
' А ' : ' A ' ,
' В ' : ' B ' ,
' Е ' : ' E ' ,
' Ё ' : ' E ' ,
' З ' : ' 3 ' ,
' К ' : ' K ' ,
' М ' : ' M ' ,
' Н ' : ' H ' ,
' О ' : ' O ' ,
' Р ' : ' P ' ,
' С ' : ' C ' ,
' Т ' : ' T ' ,
' Х ' : ' X ' ,
' Ь ' : ' b ' ,
' а ' : ' a ' ,
' е ' : ' e ' ,
' ё ' : ' e ' ,
' о ' : ' o ' ,
' р ' : ' p ' ,
' с ' : ' c ' ,
' у ' : ' y ' ,
' х ' : ' x ' ,
} ;
static final RegExp _prefixRegExp = RegExp ( r'\@\[[\S\s]+\] ' ) ;
static void setCharMap ( Map < String , String > charMap ) {
_charMap = Map . from ( charMap ) ;
}
static String encode ( String text ) {
if ( text . isEmpty ) return text ;
final buffer = StringBuffer ( ) ;
final senderName = extractSenderName ( text ) ;
final msgText = removeSenderName ( text ) ;
for ( final rune in msgText . runes ) {
final char = String . fromCharCode ( rune ) ;
buffer . write ( _charMap [ char ] ? ? char ) ;
}
return senderName + buffer . toString ( ) ;
}
static String removeSenderName ( String text ) {
final match = _prefixRegExp . matchAsPrefix ( text ) ;
if ( match ! = null ) {
return text . substring ( match . end ) ;
}
return text ;
}
static String extractSenderName ( String text ) {
final match = _prefixRegExp . matchAsPrefix ( text ) ;
if ( match ! = null ) {
return match . group ( 0 ) ? ? ' ' ;
}
return ' ' ;
}
}