-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
670 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:convert/convert.dart'; | ||
|
||
class HEXEncoding extends Encoding { | ||
@override | ||
Converter<List<int>, String> get decoder => _HEXDecoder(); | ||
@override | ||
Converter<String, List<int>> get encoder => _HEXEnoder(); | ||
|
||
@override | ||
String get name => 'hex'; | ||
} | ||
|
||
class _HEXDecoder extends Converter<List<int>, String> { | ||
@override | ||
String convert(List<int> input) => hex.encode(input); | ||
} | ||
|
||
class _HEXEnoder extends Converter<String, List<int>> { | ||
@override | ||
List<int> convert(String input) => hex.decode(input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,78 @@ | ||
import 'dart:convert'; | ||
import 'dart:core'; | ||
|
||
import 'package:utf/utf.dart'; | ||
import 'package:utf/utf.dart' as utf; | ||
|
||
abstract class UTF16 extends Encoding { | ||
List<int> get bom; | ||
|
||
static const le = [0xff, 0xfe]; | ||
static const be = [0xfe, 0xff]; | ||
|
||
@override | ||
Converter<List<int>, String> get decoder; | ||
|
||
@override | ||
Converter<String, List<int>> get encoder; | ||
|
||
@override | ||
String get name; // => 'utf16'; | ||
} | ||
|
||
class UTF16LE extends UTF16 { | ||
@override | ||
List<int> get bom => UTF16.le; | ||
|
||
@override | ||
Converter<List<int>, String> get decoder => _UTF16LEDecoder(); | ||
|
||
@override | ||
Converter<String, List<int>> get encoder => _UTF16LEEnoder(); | ||
|
||
@override | ||
String get name => 'utf16le'; | ||
} | ||
|
||
class _UTF16LEDecoder extends Converter<List<int>, String> { | ||
@override | ||
String convert(List<int> input) { | ||
final decoder = utf.Utf16leBytesToCodeUnitsDecoder(input); | ||
return String.fromCharCodes(decoder.decodeRest()); | ||
} | ||
} | ||
|
||
class _UTF16LEEnoder extends Converter<String, List<int>> { | ||
@override | ||
List<int> convert(String input) { | ||
return utf.encodeUtf16le(input, true); | ||
} | ||
} | ||
|
||
class UTF16BE extends UTF16 { | ||
@override | ||
List<int> get bom => UTF16.be; | ||
|
||
class UTF16 extends Encoding { | ||
@override | ||
Converter<List<int>, String> get decoder => _UTF16Decoder(); | ||
Converter<List<int>, String> get decoder => _UTF16BEDecoder(); | ||
|
||
@override | ||
Converter<String, List<int>> get encoder => _UTF16Enoder(); | ||
Converter<String, List<int>> get encoder => _UTF16BEEnoder(); | ||
|
||
@override | ||
String get name => 'utf16'; | ||
String get name => 'utf16be'; | ||
} | ||
|
||
class _UTF16Decoder extends Converter<List<int>, String> { | ||
class _UTF16BEDecoder extends Converter<List<int>, String> { | ||
@override | ||
String convert(List<int> input) { | ||
return decodeUtf16(input); | ||
final decoder = utf.Utf16beBytesToCodeUnitsDecoder(input); | ||
return String.fromCharCodes(decoder.decodeRest()); | ||
} | ||
} | ||
|
||
class _UTF16Enoder extends Converter<String, List<int>> { | ||
class _UTF16BEEnoder extends Converter<String, List<int>> { | ||
@override | ||
List<int> convert(String input) { | ||
return input.runes.toList(); | ||
return utf.encodeUtf16be(input, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.