Skip to content

Commit c5502ba

Browse files
committed
null safety migration
1 parent 4a1c219 commit c5502ba

8 files changed

Lines changed: 33 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.0-nullsafety.0
2+
3+
- Null safety pre-release
4+
15
## 0.2.0
26

37
- Exported more of the internal classes

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ Unicode conversion library in Dart for traditional Mongolian script
77
A simple usage example:
88

99
```dart
10-
MongolCode converter = MongolCode.instance;
10+
final converter = MongolCode.instance;
1111
1212
// Unicode to Menksoft code
13-
String unicodeInput = 'ᠮᠣᠩᠭᠣᠯ';
14-
String menksoftResult = converter.unicodeToMenksoft(unicodeInput);
13+
const unicodeInput = 'ᠮᠣᠩᠭᠣᠯ';
14+
final menksoftResult = converter.unicodeToMenksoft(unicodeInput);
1515
print(menksoftResult);
1616
1717
// Menksoft code to Unicode
18-
String menksoftInput = "\uE2C1\uE27F\uE317\uE27E\uE2E8"; // bichig
19-
String unicodeResult = converter.menksoftToUnicode(menksoftInput);
18+
const menksoftInput = '\uE2C1\uE27F\uE317\uE27E\uE2E8'; // bichig
19+
final unicodeResult = converter.menksoftToUnicode(menksoftInput);
2020
print(unicodeResult);
2121
```
2222

example/mongol_code_example.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import 'package:mongol_code/mongol_code.dart';
22

33
void main() {
4-
5-
MongolCode converter = MongolCode.instance;
4+
final converter = MongolCode.instance;
65

76
// Unicode to Menksoft code
8-
String unicodeInput = 'ᠮᠣᠩᠭᠣᠯ';
9-
String menksoftResult = converter.unicodeToMenksoft(unicodeInput);
7+
const unicodeInput = 'ᠮᠣᠩᠭᠣᠯ';
8+
final menksoftResult = converter.unicodeToMenksoft(unicodeInput);
109
print(menksoftResult);
1110

1211
// Menksoft code to Unicode
13-
String menksoftInput = "\uE2C1\uE27F\uE317\uE27E\uE2E8"; // bichig
14-
String unicodeResult = converter.menksoftToUnicode(menksoftInput);
12+
const menksoftInput = '\uE2C1\uE27F\uE317\uE27E\uE2E8'; // bichig
13+
final unicodeResult = converter.menksoftToUnicode(menksoftInput);
1514
print(unicodeResult);
1615
}

lib/src/menksoft_word.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'unicode.dart';
77
class MenksoftWord {
88
static const int SPACE = 0x0020;
99

10-
String _inputWord;
11-
Location _location;
10+
late String _inputWord;
11+
late Location _location;
1212

1313
MenksoftWord(String menksoftWord) {
1414
_inputWord = menksoftWord;
@@ -35,7 +35,7 @@ class MenksoftWord {
3535
String convertToUnicode() {
3636
final outputString = StringBuffer();
3737

38-
if (_inputWord == null || _inputWord.isEmpty) {
38+
if (_inputWord.isEmpty) {
3939
return '';
4040
}
4141

lib/src/mongol_code.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MongolCode {
9393
}
9494

9595
String unicodeToMenksoftSameIndex(String inputString) {
96-
if (inputString == null || inputString.isEmpty) return '';
96+
if (inputString.isEmpty) return '';
9797

9898
final outputString = StringBuffer();
9999
final mongolWord = StringBuffer();
@@ -142,7 +142,7 @@ class MongolCode {
142142
}
143143

144144
String menksoftToUnicode(String inputString) {
145-
if (inputString == null || inputString.isEmpty) return '';
145+
if (inputString.isEmpty) return '';
146146

147147
final outputString = StringBuffer();
148148
final menksoftWord = StringBuffer();
@@ -187,11 +187,6 @@ class MongolCode {
187187
}
188188

189189
static Location getLocation(String textBefore, String textAfter) {
190-
// TODO should we be using this in convertWordToMenksoftCode?
191-
192-
textBefore ??= '';
193-
textAfter ??= '';
194-
195190
var beforeIsMongolian = false;
196191
var afterIsMongolian = false;
197192

@@ -356,7 +351,7 @@ class MongolCode {
356351
// Starts at the end of the word and works up
357352
// if mixed genders only reports the first one from the bottom
358353
// returns null if word does not end in a valid Mongolian character
359-
static Gender getWordGender(String word) {
354+
static Gender? getWordGender(String word) {
360355
return MongolWord.getGender(word);
361356
}
362357
}

lib/src/mongol_word.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import 'shape.dart';
66
import 'unicode.dart';
77

88
class MongolWord {
9-
Gender _gender;
10-
Location _location;
11-
int _length;
12-
bool _isSuffix;
13-
String _inputWord;
14-
int _fvs;
15-
Shape _glyphShapeBelow;
9+
Gender? _gender;
10+
late Location _location;
11+
late int _length;
12+
late bool _isSuffix;
13+
late String _inputWord;
14+
late int _fvs;
15+
late Shape _glyphShapeBelow;
1616

1717
MongolWord(String mongolWord) {
1818
_inputWord = mongolWord;
@@ -1915,9 +1915,9 @@ class MongolWord {
19151915
// Starts at the end of the word and works up
19161916
// if mixed genders only reports the first one from the bottom
19171917
// returns null if word does not end in a valid Mongolian character
1918-
static Gender getGender(String word) {
1918+
static Gender? getGender(String word) {
19191919
// check that word is valid mongolian
1920-
if (word == null || word.isEmpty) return null;
1920+
if (word.isEmpty) return null;
19211921
final length = word.length;
19221922
final lastChar = word.codeUnitAt(length - 1);
19231923
if (!MongolCode.isMongolian(lastChar)) return null;

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: mongol_code
22
description: Unicode conversion package for traditional Mongolian scripts
3-
version: 0.2.0
3+
version: 0.3.0-nullsafety.0
44
homepage: https://github.com/suragch/mongol_code
55

66
environment:
7-
sdk: '>=2.7.0 <3.0.0'
7+
sdk: '>=2.12.0-29.10.beta <3.0.0'
88

99
dev_dependencies:
10-
pedantic: ^1.8.0
11-
test: ^1.6.0
10+
pedantic: ^1.10.0-nullsafety.3
11+
test: ^1.16.0-nullsafety.11

test/mongol_code_test.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ void main() {
2929
expect(expected, result);
3030
});
3131

32-
test('nullString', () async {
33-
final unicode = null;
34-
final result = convertUnicodeToMenksoft(unicode);
35-
final expected = '';
36-
expect(expected, result);
37-
});
38-
3932
test('english character', () async {
4033
final unicode = 'a';
4134
final result = convertUnicodeToMenksoft(unicode);
@@ -5304,13 +5297,6 @@ void main() {
53045297
expect(expected, result);
53055298
});
53065299

5307-
test('nullString', () async {
5308-
final unicode = null;
5309-
final result = convertMenksoftToUnicode(unicode);
5310-
final expected = '';
5311-
expect(expected, result);
5312-
});
5313-
53145300
test('englishKeyboardChars', () async {
53155301
final unicode =
53165302
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#\$%^&*()-=_+`~;:\'" ,./<>?';

0 commit comments

Comments
 (0)