Skip to content

Commit

Permalink
support windows-1253 and 1254, resolves #5
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Mar 17, 2021
1 parent e0eeb28 commit 2f989c0
Show file tree
Hide file tree
Showing 6 changed files with 523 additions and 0 deletions.
12 changes: 12 additions & 0 deletions example/enough_convert_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void main() {
windows1250();
windows1251();
windows1252();
windows1253();
windows1254();
gbk();
}

Expand Down Expand Up @@ -102,6 +104,16 @@ void windows1252() {
'Il faut être bête quand même.');
}

void windows1253() {
roundtrip(
const Windows1253Codec(allowInvalid: false), 'Χαίρομαι που σας γνωρίζω!');
}

void windows1254() {
roundtrip(const Windows1254Codec(allowInvalid: false),
'Tanıştığımıza memnun oldum!');
}

void gbk() {
roundtrip(const GbkCodec(allowInvalid: false), '白日依山尽,黄河入海流');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/enough_convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export 'windows/windows.dart';
export 'windows/windows1250.dart';
export 'windows/windows1251.dart';
export 'windows/windows1252.dart';
export 'windows/windows1253.dart';
export 'windows/windows1254.dart';
export 'gbk/gbk.dart';
162 changes: 162 additions & 0 deletions lib/windows/windows1253.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import 'dart:convert' as cnvrt;

import 'package:enough_convert/windows/windows.dart';

const String _cp1253Symbols =
'€?‚ƒ„…†‡?‰?‹?????‘’“”•–—?™?›????\u{00A0}΅Ά£¤¥¦§¨©?«¬\u{00AD}®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ?ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ?';
const Map<int, int> _cp1253Map = {
8364: 128,
8218: 130,
402: 131,
8222: 132,
8230: 133,
8224: 134,
8225: 135,
8240: 137,
8249: 139,
8216: 145,
8217: 146,
8220: 147,
8221: 148,
8226: 149,
8211: 150,
8212: 151,
8482: 153,
8250: 155,
160: 160,
901: 161,
902: 162,
163: 163,
164: 164,
165: 165,
166: 166,
167: 167,
168: 168,
169: 169,
171: 171,
172: 172,
173: 173,
174: 174,
8213: 175,
176: 176,
177: 177,
178: 178,
179: 179,
900: 180,
181: 181,
182: 182,
183: 183,
904: 184,
905: 185,
906: 186,
187: 187,
908: 188,
189: 189,
910: 190,
911: 191,
912: 192,
913: 193,
914: 194,
915: 195,
916: 196,
917: 197,
918: 198,
919: 199,
920: 200,
921: 201,
922: 202,
923: 203,
924: 204,
925: 205,
926: 206,
927: 207,
928: 208,
929: 209,
931: 211,
932: 212,
933: 213,
934: 214,
935: 215,
936: 216,
937: 217,
938: 218,
939: 219,
940: 220,
941: 221,
942: 222,
943: 223,
944: 224,
945: 225,
946: 226,
947: 227,
948: 228,
949: 229,
950: 230,
951: 231,
952: 232,
953: 233,
954: 234,
955: 235,
956: 236,
957: 237,
958: 238,
959: 239,
960: 240,
961: 241,
962: 242,
963: 243,
964: 244,
965: 245,
966: 246,
967: 247,
968: 248,
969: 249,
970: 250,
971: 251,
972: 252,
973: 253,
974: 254,
};

/// Provides a windows 1253 / cp1253 codec for easy encoding and decoding.
class Windows1253Codec extends cnvrt.Encoding {
final bool allowInvalid;

/// Creates a new codec
const Windows1253Codec({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be encoded to ? and decoded to �
this.allowInvalid = false,
});

@override
Windows1253Decoder get decoder => allowInvalid
? const Windows1253Decoder(allowInvalid: true)
: const Windows1253Decoder(allowInvalid: false);

@override
Windows1253Encoder get encoder => allowInvalid
? const Windows1253Encoder(allowInvalid: true)
: const Windows1253Encoder(allowInvalid: false);

@override
String get name => 'windows-1253';
}

/// Decodes windows 1253 / cp1253 data.
class Windows1253Decoder extends WindowsDecoder {
const Windows1253Decoder({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be decoded to �
bool allowInvalid = false,
}) : super(_cp1253Symbols, allowInvalid: allowInvalid);
}

/// Encodes texts into windows 1253 data
class Windows1253Encoder extends WindowsEncoder {
const Windows1253Encoder({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be encoded to ?
bool allowInvalid = false,
}) : super(_cp1253Map, allowInvalid: allowInvalid);
}
172 changes: 172 additions & 0 deletions lib/windows/windows1254.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import 'dart:convert' as cnvrt;

import 'package:enough_convert/windows/windows.dart';

const String _cp1254Symbols =
'€?‚ƒ„…†‡ˆ‰Š‹Œ????‘’“”•–—˜™š›œ??Ÿ\u{00A0}¡¢£¤¥¦§¨©ª«¬\u{00AD}®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏĞÑÒÓÔÕÖ×ØÙÚÛÜİŞßàáâãäåæçèéêëìíîïğñòóôõö÷øùúûüışÿ';
const Map<int, int> _cp1254Map = {
8364: 128,
8218: 130,
402: 131,
8222: 132,
8230: 133,
8224: 134,
8225: 135,
710: 136,
8240: 137,
352: 138,
8249: 139,
338: 140,
8216: 145,
8217: 146,
8220: 147,
8221: 148,
8226: 149,
8211: 150,
8212: 151,
732: 152,
8482: 153,
353: 154,
8250: 155,
339: 156,
376: 159,
160: 160,
161: 161,
162: 162,
163: 163,
164: 164,
165: 165,
166: 166,
167: 167,
168: 168,
169: 169,
170: 170,
171: 171,
172: 172,
173: 173,
174: 174,
175: 175,
176: 176,
177: 177,
178: 178,
179: 179,
180: 180,
181: 181,
182: 182,
183: 183,
184: 184,
185: 185,
186: 186,
187: 187,
188: 188,
189: 189,
190: 190,
191: 191,
192: 192,
193: 193,
194: 194,
195: 195,
196: 196,
197: 197,
198: 198,
199: 199,
200: 200,
201: 201,
202: 202,
203: 203,
204: 204,
205: 205,
206: 206,
207: 207,
286: 208,
209: 209,
210: 210,
211: 211,
212: 212,
213: 213,
214: 214,
215: 215,
216: 216,
217: 217,
218: 218,
219: 219,
220: 220,
304: 221,
350: 222,
223: 223,
224: 224,
225: 225,
226: 226,
227: 227,
228: 228,
229: 229,
230: 230,
231: 231,
232: 232,
233: 233,
234: 234,
235: 235,
236: 236,
237: 237,
238: 238,
239: 239,
287: 240,
241: 241,
242: 242,
243: 243,
244: 244,
245: 245,
246: 246,
247: 247,
248: 248,
249: 249,
250: 250,
251: 251,
252: 252,
305: 253,
351: 254,
255: 255,
};

/// Provides a windows 1254 / cp1254 codec for easy encoding and decoding.
class Windows1254Codec extends cnvrt.Encoding {
final bool allowInvalid;

/// Creates a new codec
const Windows1254Codec({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be encoded to ? and decoded to �
this.allowInvalid = false,
});

@override
Windows1254Decoder get decoder => allowInvalid
? const Windows1254Decoder(allowInvalid: true)
: const Windows1254Decoder(allowInvalid: false);

@override
Windows1254Encoder get encoder => allowInvalid
? const Windows1254Encoder(allowInvalid: true)
: const Windows1254Encoder(allowInvalid: false);

@override
String get name => 'windows-1254';
}

/// Decodes windows 1254 / cp1254 data.
class Windows1254Decoder extends WindowsDecoder {
const Windows1254Decoder({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be decoded to �
bool allowInvalid = false,
}) : super(_cp1254Symbols, allowInvalid: allowInvalid);
}

/// Encodes texts into windows 1254 data
class Windows1254Encoder extends WindowsEncoder {
const Windows1254Encoder({
/// set [allowInvalid] to `true` for ignoring invalid data.
/// When invalid data is allowed it will be encoded to ?
bool allowInvalid = false,
}) : super(_cp1254Map, allowInvalid: allowInvalid);
}
Loading

0 comments on commit 2f989c0

Please sign in to comment.