A bottom spec implementation in Crystal
The spec can be found at https://github.com/bottom-software-foundation/spec
Just download bottom.cr
and add it to your project or w/e
require "path/to/bottom.cr"
puts Bottom.encode("Hello")
# Output: πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππ
puts Bottom.decode("πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππ")
# Output: Hello
Validates and decodes the given string. Raises an
ArgumentError
if string is not a valid bottom-encoded string or the string is not valid a valid UTF8 string.Example:
Valid:
puts Bottom.decode("πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππ") # Output: HelloInvalid:
puts Bottom.decode("Hello") # Output: ArgumentErrorReturns
String
Encodes string as per the bottom spec. Raises an
ArgumentError
if the string is not a valid UTF8 string.Example:
puts Bottom.encode("Hello") # Output: πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππReturns
String
Validates the given
String
instance. Raises anArgumentError
if string is not a valid bottom-encoded string or the string is not valid a valid UTF8 string.Example:
Valid:
puts Bottom.verify_bottom("πβ¨β¨,,ππππ,πππππ₯Ί,,,πππππ₯Ί,,,ππππβ¨,ππ") # Output: nilInvalid:
puts Bottom.verify_bottom("Hello") # Output: ArgumentErrorReturns
nil
- arHSM - creator and maintainer