Add missing increment to custom code-page decoder.
Fixes #47.
diff --git a/lib/src/codepage.dart b/lib/src/codepage.dart
index 2cc5fbd..296a116 100644
--- a/lib/src/codepage.dart
+++ b/lib/src/codepage.dart
@@ -256,7 +256,7 @@
throw ArgumentError.value(
characters, "characters", "Must contain 256 characters");
}
- result[i] = char;
+ result[i++] = char;
allChars |= char;
}
if (i < 256) {
diff --git a/test/codepage_test.dart b/test/codepage_test.dart
index 2105f27..e93ef30 100644
--- a/test/codepage_test.dart
+++ b/test/codepage_test.dart
@@ -60,4 +60,15 @@
var decoded = latin3.decode(encoded, allowInvalid: true);
expect(decoded, latin2text);
});
+
+ test("Custom code page", () {
+ var cp = CodePage("custom", "ABCDEF" + "\uFFFD" * 250);
+ var result = cp.encode("BADCAFE");
+ expect(result, [1, 0, 3, 2, 0, 5, 4]);
+ expect(() => cp.encode("GAD"), throwsFormatException);
+ expect(cp.encode("GAD", invalidCharacter: 0x3F), [0x3F, 0, 3]);
+ expect(cp.decode([1, 0, 3, 2, 0, 5, 4]), "BADCAFE");
+ expect(() => cp.decode([6, 1, 255]), throwsFormatException);
+ expect(cp.decode([6, 1, 255], allowInvalid: true), "\u{FFFD}B\u{FFFD}");
+ });
}