-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 1146b03
Showing
9 changed files
with
168 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
|
||
# Omit commiting pubspec.lock for library packages: | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ |
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,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial version, created by Stagehand |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Oliver Ni | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,17 @@ | ||
# Bottom | ||
|
||
This is a Dart implementation of [bottom](https://github.com/kaylynn234/bottom). | ||
|
||
Bottom encodes UTF-8 text into a sequence comprised of bottom emoji (`π«β¨π₯Ίβ€οΈ`, with `,` sprinkled in for good measure) followed by `ππ`. It can encode any valid UTF-8 β being a bottom transcends language, after all β and decode back into UTF-8. | ||
|
||
## Usage | ||
|
||
Here's a simple example: | ||
|
||
```dart | ||
import 'package:bottom/bottom.dart'; | ||
void main(List<String> args) { | ||
print(bottom.encode(args.join(' '))); | ||
} | ||
``` |
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,14 @@ | ||
# Defines a default set of lint rules enforced for | ||
# projects at Google. For details and rationale, | ||
# see https://github.com/dart-lang/pedantic#enabled-lints. | ||
include: package:pedantic/analysis_options.yaml | ||
|
||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. | ||
# Uncomment to specify additional rules. | ||
# linter: | ||
# rules: | ||
# - camel_case_types | ||
|
||
analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** |
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,5 @@ | ||
import 'package:bottom/bottom.dart'; | ||
|
||
void main(List<String> args) { | ||
print(bottom.encode(args.join(' '))); | ||
} |
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,60 @@ | ||
library bottom; | ||
|
||
import 'dart:convert'; | ||
|
||
Map<String, int> _charValues = { | ||
'π«': 200, | ||
'π': 50, | ||
'β¨': 10, | ||
'π₯Ί': 5, | ||
',': 1, | ||
}; | ||
|
||
const _zero = 'β€οΈ'; | ||
const _sectionSeparator = 'ππ'; | ||
final _terminator = RegExp('$_sectionSeparator?\$'); | ||
|
||
class BottomEncoder extends Converter<String, String> { | ||
String _encodeByte(int value) { | ||
if (value == 0) return ''; | ||
final largest = | ||
_charValues.entries.firstWhere((entry) => value >= entry.value); | ||
return largest.key + _encodeByte(value - largest.value); | ||
} | ||
|
||
String encodeByte(int value) { | ||
return value == 0 ? _zero : _encodeByte(value); | ||
} | ||
|
||
@override | ||
String convert(String input) { | ||
return utf8 | ||
.encode(input) | ||
.map((value) => encodeByte(value) + _sectionSeparator) | ||
.join(); | ||
} | ||
} | ||
|
||
class BottomDecoder extends Converter<String, String> { | ||
@override | ||
String convert(String input) { | ||
return utf8.decode(input | ||
.trim() | ||
.replaceAll(_terminator, '') | ||
.split(_sectionSeparator) | ||
.map((chars) => chars | ||
.split('') | ||
.map((x) => _charValues[x]) | ||
.reduce((a, b) => a + b))); | ||
} | ||
} | ||
|
||
class BottomCodec extends Codec<String, String> { | ||
@override | ||
BottomEncoder get encoder => BottomEncoder(); | ||
|
||
@override | ||
BottomDecoder get decoder => BottomDecoder(); | ||
} | ||
|
||
final bottom = BottomCodec(); |
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,11 @@ | ||
name: bottom | ||
description: A starting point for Dart libraries or applications. | ||
version: 1.0.0 | ||
homepage: https://github.com/oliver-ni/bottom-dart | ||
|
||
environment: | ||
sdk: ">=2.8.1 <3.0.0" | ||
|
||
dev_dependencies: | ||
pedantic: ^1.9.0 | ||
test: ^1.14.4 |
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,24 @@ | ||
import 'package:bottom/bottom.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
Map<String, String> pairs = { | ||
'Test': 'πβ¨β¨β¨,,,,ππππ,ππππβ¨π₯Ίππππβ¨π₯Ί,ππ', | ||
'Hello World': | ||
'πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππβ¨β¨β¨,,πππβ¨β¨β¨π₯Ί,,ππππβ¨,ππππβ¨,,,,πππππ₯Ί,,,ππππππ', | ||
'γγγ°γ': | ||
'π«β¨β¨π₯Ί,,ππππβ¨β¨π₯Ί,,,,ππππβ¨β¨β¨β¨πππ«β¨β¨π₯Ί,,ππππβ¨β¨β¨ππππβ¨β¨β¨β¨π₯Ί,,πππ«β¨β¨π₯Ί,,ππππβ¨β¨π₯Ί,,,,πππππβ¨β¨π₯Ί,πππ«β¨β¨π₯Ί,,ππππβ¨β¨β¨ππππβ¨β¨β¨β¨ππ', | ||
'π₯Ί': 'π«β¨β¨β¨β¨ππππππ₯Ί,,,,πππππβ¨π₯Ίπππππβ¨β¨β¨π₯Ί,ππ', | ||
'\x00': 'β€οΈππ', | ||
}; | ||
|
||
void main() { | ||
group('Bottom tests', () { | ||
test('Encodes properly', () { | ||
pairs.forEach((text, result) => expect(bottom.encode(text), result)); | ||
}); | ||
|
||
test('Decodes properly', () { | ||
pairs.forEach((text, result) => expect(bottom.decode(result), text)); | ||
}); | ||
}); | ||
} |