DEV Community

manuel
manuel

Posted on • Originally published at mnlwldr.com on

OWO - A fuzzy string transformer written in Golang.

#go

Huohhhh. fuwwy stwing twansfowmew ;3

Built @zuzakistan’s (@BBCBweaking) OWO with Golang.

Source: mnlwldr/OWO.

package owo

import (
    "math/rand"
    "strings"
    "time"
)

// Define a prefixes variable as a slice of strings
var prefixes = []string{
    "<3 ",
    "0w0 ",
    "H-hewwo?? ",
    "HIIII! ",
    "Haiiii! ",
    "Huohhhh. ",
    "OWO ",
    "OwO ",
    "UwU ",
}

// Define a suffixes variable as a slice of strings
var suffixes = []string{
    " ( ͡° ᴥ ͡°)",
    " (இωஇ )",
    " (๑•́ ₃ •̀๑)",
    " (• o •)",
    " (●´ω`●)",
    " (◠‿◠✿)",
    " (✿ ♡‿♡)",
    " ( \"\")",
    " (人◕ω◕)",
    " (;ω;)",
    " (`へ´)",
    " ._.",
    " :3",
    " :D",
    " :P",
    " ;-;",
    " ;3",
    " ;_;",
    " >_<",
    " >_>",
    " UwU",
    " XDDD",
    " ^-^",
    " ^_^",
    " x3",
    " x3",
    " xD",
    " ÙωÙ",
    " ʕʘ‿ʘʔ",
    " ʕ•̫͡•ʔ",
    " ㅇㅅㅇ",
    ", fwendo",
    "(^v^)",
}

// Translate the given text. You can set withPrefix and withSuffix
// to true or false, if you want them or not.
// It returns the translated text
func Translate(text string, withPrefix bool, withSuffix bool) string {

    // Define a concat variable as a slice of strings
    var concat []string

    // if withPrefix is set to true add it to the concat slice
    if withPrefix {
        concat = append(concat, prefixes[random(len(prefixes))])
    }

    // substitute characters and add the processed string to the concat slice
    concat = append(concat, substitute(text))

    // if withSuffix is set to true add it to the concat slice
    if withSuffix {
        concat = append(concat, suffixes[random(len(suffixes))])
    }

    // Join the concat slice and return it as a string
    return strings.Join(concat, " ")
}

// It replaces characters in the given text
// It returns the processed string
func substitute(text string) string {
    return strings.NewReplacer(
        "r", "w",
        "l", "w",
        "R", "W",
        "L", "W",
        "no", "nu",
        "has", "haz",
        "have", "haz",
        "you", "uu",
        "the ", "da ",
        "The ", "Da ").Replace(text)
}

// It returns a random number
func random(max int) int {
    return rand.New(rand.NewSource(time.Now().UnixNano())).Intn(max)
}
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay