arHSM / bottom-cr

Bottom spec implementation in Crystal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bottom-cr

A bottom spec implementation in Crystal

The spec can be found at https://github.com/bottom-software-foundation/spec

Installation

Just download bottom.cr and add it to your project or w/e

Usage

require "path/to/bottom.cr"

puts Bottom.encode("Hello")
# Output: πŸ’–βœ¨βœ¨,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨,πŸ‘‰πŸ‘ˆ
puts Bottom.decode("πŸ’–βœ¨βœ¨,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨,πŸ‘‰πŸ‘ˆ")
# Output: Hello

Documentation

def decode(string : String) : String

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: Hello

Invalid:

puts Bottom.decode("Hello")
# Output: ArgumentError

Returns String

def encode(string : String) : 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

def verify_bottom(string : String)

Validates the given String instance. 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.verify_bottom("πŸ’–βœ¨βœ¨,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–πŸ₯Ί,,,πŸ‘‰πŸ‘ˆπŸ’–πŸ’–βœ¨,πŸ‘‰πŸ‘ˆ")
# Output: nil

Invalid:

puts Bottom.verify_bottom("Hello")
# Output: ArgumentError

Returns nil

Contributors

  • arHSM - creator and maintainer

About

Bottom spec implementation in Crystal

License:MIT License


Languages

Language:Crystal 100.0%