From bfde70a341d95f080f9729049101c345f1c5f51e Mon Sep 17 00:00:00 2001 From: abnormalbbk Date: Mon, 22 Aug 2022 23:06:00 +0545 Subject: [PATCH 1/3] :sparkles: Added a ignore list for NepaliUnicode --- lib/src/nepali_unicode.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/src/nepali_unicode.dart b/lib/src/nepali_unicode.dart index 23c08b4..b420065 100644 --- a/lib/src/nepali_unicode.dart +++ b/lib/src/nepali_unicode.dart @@ -5,27 +5,35 @@ /// Converts English literal (Roman Literals) into Nepali Unicode. class NepaliUnicode { static String _text = ''; + static List _ignoreList = []; /// Converts specifies [text] into nepali literals. /// /// if live is true, texts will convert in live manner. /// i.e. as you go on typing /// Default for live is false. - static String convert(String text, {bool live = false}) { + /// if ignoreList is provided, text in list will not be translated + static String convert(String text, {bool live = false, List ignoreList = const []}) { + _ignoreList = ignoreList; if (live) { - return _unicode(text); + return _convert(text); } _text = ''; for (var index = 0; index < text.length; index++) { + final char = text[index]; if (index == 0) { - _text = _unicode(text[0]); + _text = _convert(char); } else { - _text = _unicode(_text + text[index]); + _text = _unicode(_text + char); } } return _text; } + static String _convert(String data) { + return _ignoreList.contains(data) ? data : _unicode(data); + } + static String _unicode(String data) { _text = data; _replace('a', '\u0905'); @@ -195,10 +203,12 @@ class NepaliUnicode { } static void _replace(x, y) { + if (_ignoreList.contains(x)) return; _text = _text.replaceAll(x, String.fromCharCodes(Runes(y))); } static void _replaceRunes(x, y) { + if (_ignoreList.contains(x)) return; _text = _text.replaceAll( String.fromCharCodes(Runes(x)), String.fromCharCodes(Runes(y)), From cf2ccd1ebe84d750f4ce8eed0491b3d70251dcc4 Mon Sep 17 00:00:00 2001 From: abnormalbbk Date: Mon, 22 Aug 2022 23:07:01 +0545 Subject: [PATCH 2/3] :memo: Added nepali unicode with number and ignore list in example.dart --- example/main.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/example/main.dart b/example/main.dart index 87f5e23..bceba7c 100644 --- a/example/main.dart +++ b/example/main.dart @@ -70,10 +70,14 @@ void main(List arguments) { print('12345 -> ${numberFormatWithEmptyDelimiter.format(12345)}'); heading('Nepali Unicode'); - print(NepaliUnicode.convert( - "sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii")); - print(NepaliUnicode.convert( - 'saarwabhauma bhai failiekaa, mecii-mahaakaalii\n')); + print(NepaliUnicode.convert("sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii")); + print(NepaliUnicode.convert('saarwabhauma bhai failiekaa, mecii-mahaakaalii\n')); + + heading('Nepali Unicode with number'); + print(NepaliUnicode.convert('10000.10')); + + heading('Nepali Unicode with number and ignore list'); + print(NepaliUnicode.convert('10,000.10', ignoreList: ['.'])); } void heading(String text) { From c2aedae714571058ee9c2e3785b4b580d96d2f57 Mon Sep 17 00:00:00 2001 From: abnormalbbk Date: Mon, 22 Aug 2022 23:14:35 +0545 Subject: [PATCH 3/3] :art: Re-formatted file as per dart 80 characters line limit --- example/main.dart | 6 ++++-- lib/src/nepali_unicode.dart | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/example/main.dart b/example/main.dart index bceba7c..f528bd8 100644 --- a/example/main.dart +++ b/example/main.dart @@ -70,8 +70,10 @@ void main(List arguments) { print('12345 -> ${numberFormatWithEmptyDelimiter.format(12345)}'); heading('Nepali Unicode'); - print(NepaliUnicode.convert("sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii")); - print(NepaliUnicode.convert('saarwabhauma bhai failiekaa, mecii-mahaakaalii\n')); + print(NepaliUnicode.convert( + "sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii")); + print(NepaliUnicode.convert( + 'saarwabhauma bhai failiekaa, mecii-mahaakaalii\n')); heading('Nepali Unicode with number'); print(NepaliUnicode.convert('10000.10')); diff --git a/lib/src/nepali_unicode.dart b/lib/src/nepali_unicode.dart index b420065..76f6bee 100644 --- a/lib/src/nepali_unicode.dart +++ b/lib/src/nepali_unicode.dart @@ -13,7 +13,11 @@ class NepaliUnicode { /// i.e. as you go on typing /// Default for live is false. /// if ignoreList is provided, text in list will not be translated - static String convert(String text, {bool live = false, List ignoreList = const []}) { + static String convert( + String text, { + bool live = false, + List ignoreList = const [], + }) { _ignoreList = ignoreList; if (live) { return _convert(text);