Jump to content

Bottom Text Encoding UDF


rcmaehl
 Share

Recommended Posts

This example script converts UTF-8 text to Bottom Text Encoding, and eventually vice versa, as defined by the Bottom Software Foundation. The entire language is based on the "I don't speak bottom" meme, but was good practice for me messing with UTF-8 text.

Code:

#include-once
#include <StringConstants.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: _EncodeBottom
; Description ...: Converts UTF-8 String to Bottom Text Encoding
; Syntax ........: _EncodeBottom($sString)
; Parameters ....: $sString             - A valid UTF-8 String
; Return values .: A Bottom Text Encoded String
; Author ........: Robert Maehl (rcmaehl)
; Modified ......: 03/03/2021
; Remarks .......:
; Related .......:
; Link ..........: https://github.com/bottom-software-foundation/spec
; Example .......: No
; ===============================================================================================================================
Func _EncodeBottom($sString)

    Local $i = 0
    Local $sOut = ""
    Local $vString
    Local $aBytes[0]

    Local $aSplitString = StringSplit($sString, "", $STR_NOCOUNT)

    For $iChrInString = 0 To UBound($aSplitString) - 1

        ReDim $aBytes[0]

        $vString = StringToBinary($aSplitString[$iChrInString], $SB_UTF8)
        $vString = StringReplace($vString, "0x", "")

        ReDim $aBytes[Ceiling(StringLen($vString) / 2)]

        For $iElement = 0 To UBound($aBytes) - 1
            $aBytes[$iElement] = Dec(StringLeft($vString, 2))
            $vString = StringTrimLeft($vString, 2)
        Next

        For $iByteInChr = 0 To UBound($aBytes) - 1

            Do
                Select

                    Case $aBytes[$iByteInChr] >= 200
                        $aBytes[$iByteInChr] -= 200
                        $sOut &= ChrW(129730)

                    Case $aBytes[$iByteInChr] >= 50
                        $aBytes[$iByteInChr] -= 50
                        $sOut &= "💖"

                    Case $aBytes[$iByteInChr] >= 10
                        $aBytes[$iByteInChr] -= 10
                        $sOut &= "✨"

                    Case $aBytes[$iByteInChr] >= 5
                        $aBytes[$iByteInChr] -= 5
                        $sOut &= "🥺"

                    Case $aBytes[$iByteInChr] >= 1
                        $aBytes[$iByteInChr] -= 1
                        $sOut &= ","

                EndSelect
            Until $aBytes[$iByteInChr] = 0

            $sOut &= "👉👈"

        Next
    Next

    Return $sOut

EndFunc

Changelog:

Spoiler

3/03/21

  • Initial Commit

 

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...