mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-03 11:39:11 +02:00
improved isLatin function by considering whitespace too
This commit is contained in:
parent
8af610fd46
commit
94c21342d1
@ -126,14 +126,22 @@ Future<void> main(List<String> arguments) async {
|
||||
}
|
||||
|
||||
if( argResults[requestArg] != null) {
|
||||
stdout.write("Got argument request ${argResults[requestArg]}");
|
||||
//stdout.write("Got argument request: ${argResults[requestArg]}");
|
||||
stdout.write('Sending request and waiting for events...');
|
||||
|
||||
sendRequest(defaultServerUrl, argResults[requestArg]);
|
||||
Future.delayed(const Duration(milliseconds: 6000), () {
|
||||
List<Event> receivedEvents = getRecievedEvents();
|
||||
stdout.write("received ${receivedEvents.length - numFileEvents} events from $defaultServerUrl\n");
|
||||
|
||||
// remove bots
|
||||
receivedEvents.removeWhere((e) => gBots.contains(e.eventData.pubkey));
|
||||
|
||||
// create tree
|
||||
Tree node = getTree(getRecievedEvents());
|
||||
clearEvents();
|
||||
clearEvents(); // cause we have consumed them above
|
||||
|
||||
// call main menu
|
||||
mainMenuUi(node, []);
|
||||
});
|
||||
return;
|
||||
|
@ -71,23 +71,28 @@ bool isNumeric(String s) {
|
||||
return double.tryParse(s) != null;
|
||||
}
|
||||
|
||||
bool isWhitespace(String s) {
|
||||
if( s.length != 1) {
|
||||
return false;
|
||||
}
|
||||
return s[0] == ' ' || s[0] == '\n' || s[0] == '\r' || s[0] == '\t';
|
||||
}
|
||||
|
||||
extension StringX on String {
|
||||
isLatinAlphabet({caseSensitive = false}) {
|
||||
if( length < 6) { // since smaller words can be smileys can should not be translated
|
||||
return true;
|
||||
}
|
||||
|
||||
int countLatinletters = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
final target = caseSensitive ? this[i] : this[i].toLowerCase();
|
||||
if ( (target.codeUnitAt(0) > 96 && target.codeUnitAt(0) < 123) || ( isNumeric(target) )) {
|
||||
if ( (target.codeUnitAt(0) > 96 && target.codeUnitAt(0) < 123) || ( isNumeric(target) ) || isWhitespace(target)) {
|
||||
countLatinletters++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( gDebug > 0) print("in isLatinAlphabet: latin letters: $countLatinletters and total = $length ");
|
||||
|
||||
if( countLatinletters < ( 40.0/100 ) * length ) {
|
||||
if( gDebug > 0) print("in isLatinAlphabet: latin letters: $countLatinletters and total = $length ");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -80,6 +80,8 @@ class Relays {
|
||||
return;
|
||||
}
|
||||
|
||||
if( gDebug > 0) print ("\nIn relay.sendRequest for relay $relay and $request = $request");
|
||||
|
||||
IOWebSocketChannel? fws;
|
||||
if(relays.containsKey(relay)) {
|
||||
fws = relays[relay];
|
||||
|
Loading…
x
Reference in New Issue
Block a user