Commit a2529e4f authored by Nicolas Lenz's avatar Nicolas Lenz

Merge branch 'master' into subsuper

parents 4b3cc6c1 08348688
# ---> Haskell
mock.cabal
dist
dist-*
cabal-dev
......@@ -19,4 +20,3 @@ cabal.sandbox.config
.stack-work/
cabal.project.local
.HTF/
......@@ -2,6 +2,8 @@
![wAR miR jEtzT Zu anSTRENgEnd dA JedeN ZWEiten BUChSTaBeN GRoSS zU scHREiBen](mock.png)
There is a **Telegram bot** for Mock available as [@truemockbot](https://t.me/truemockbot), you can find its source code in the [repository](https://git.eisfunke.com/software/mock-telegram-bot).
## Installation
```
......
......@@ -3,6 +3,7 @@
module Main where
import Mock (styles)
import Mock.Help (styleHelp)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Char
......@@ -30,7 +31,20 @@ handle style = fromMaybe (const help) (lookup style styles) . T.dropWhileEnd isS
-- |Help string.
help :: T.Text
help = T.unlines [
"Mock 3.0.0 - a program to transform text.",
" ╔════════════════════╗",
" ║ Mock 3.3.0 ║",
" ╚════════════════════╝",
"",
"A Great PrOgrAM tO TRANsFoRM TEXt, wRiTten iN HaSKeLL.",
"By Nicolas Lenz. Free and open source under the WTFPL.",
"Webpage (source code, issues, pull requests): https://git.eisfunke.com/software/mock",
"",
"Usage: mock [STYLE] [TEXT]",
"Styles: " `T.append` (T.intercalate ", " $ map fst styles)]
"Help: mock --help",
"",
"Styles: ",
T.intercalate "\n" styleHelps] where
styleHelps = map
(\(name, _) -> T.concat [" - ", name, ": ", T.replicate (maxNameLength - T.length name) " " , styleHelp name])
styles
maxNameLength = maximum . map (T.length . fst) $ styles
cabal-version: 2.2
-- This file has been generated from package.yaml by hpack version 0.31.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: c163d71c387a66e9f2b69128f77418f0edb7d266751fbe7ec2aa40443511d5d0
name: mock
version: 3.2.1
synopsis: GrEAt HAskeLL PrOGRaM to trANsForm tEXT
description: Please see the README at <https://git.eisfunke.com/software/mock#readme>
category: String
author: Nicolas Lenz
maintainer: nicolas@eisfunke.com
copyright: 2018 Nicolas Lenz
license: WTFPL
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
source-repository head
type: git
location: https://git.eisfunke.com/software/mock
library
exposed-modules:
Mock
other-modules:
Paths_mock
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, hashable
, random
, text
default-language: Haskell2010
executable mock
main-is: Main.hs
other-modules:
Paths_mock
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, hashable
, mock
, random
, text
default-language: Haskell2010
name: mock
version: 3.2.1
version: 3.5.0
license: WTFPL
git: "https://git.eisfunke.com/software/mock"
author: "Nicolas Lenz"
......@@ -14,7 +14,7 @@ category: String
description: Please see the README at <https://git.eisfunke.com/software/mock#readme>
dependencies:
- base >= 4.7 && < 5
- base
- random
- hashable
- text
......
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings, LambdaCase #-}
module Mock (styles, mockAlternate, mockRandom, letterspace, toDouble) where
......@@ -15,18 +15,22 @@ styles :: [(Text, Text -> Text)]
styles = [
("random", mockRandom),
("alternate", mockAlternate),
("alternate2", mockAlternate . T.toLower),
("strike", strikethrough),
("double", T.map toDouble),
("dedouble", T.map fromDouble),
("smallcaps", T.map toSmallCap),
("lower", T.toLower),
("upper", T.toUpper),
("cyrillic", T.map toCyrillic),
("subsuper", T.map toSubSuper),
("cc", mockCC),
("b", mockB),
("space", letterspace 1),
("space2", letterspace 2),
("space3", letterspace 3),
("lines", T.intersperse '\n'),
("upper", T.toUpper),
("lower", T.toLower),
("double", T.map toDouble),
("cc", mockCC),
("b", mockB),
("square", mockSquare),
("strike", strikethrough),
("subsuper", T.map toSubSuper)]
("square", mockSquare)]
-- |Transforms a String into uppercase where the corresponding list is True. For False the String isn't changed.
toUpperBy :: [Bool] -> T.Text -> T.Text
......@@ -70,6 +74,76 @@ toSubSuper c = case lookup c table of
| otherwise -> c
where table = [('A', 7468), ('B', 7470), ('D', 7472), ('E', 7473), ('O', 7484), ('P', 7486), ('R', 7487), ('T', 7488), ('U', 7489), ('V', 11389), ('W', 7490)]
-- |Transforms double-struck characters back into their normal variant.
fromDouble :: Char -> Char
fromDouble c = case ord c of
8450 -> 'C'
8461 -> 'H'
8469 -> 'N'
8473 -> 'P'
8474 -> 'Q'
8477 -> 'R'
8484 -> 'Z'
code
| 120792 <= code && code <= 120801 -> chr $ code - 120792 + 48
| 120120 <= code && code <= 120145 -> chr $ code - 120120 + 65
| 120146 <= code && code <= 120171 -> chr $ code - 120146 + 97
code -> chr code
-- |Transforms lowercase characters into their unicode small capital variant
toSmallCap :: Char -> Char
toSmallCap = \case
'a' -> chr 7424
'b' -> chr 665
'c' -> chr 7428
'd' -> chr 7429
'e' -> chr 7431
'f' -> chr 42800
'g' -> chr 610
'h' -> chr 668
'i' -> chr 618
'j' -> chr 7434
'k' -> chr 7435
'l' -> chr 671
'm' -> chr 7437
'n' -> chr 628
'o' -> chr 7439
'p' -> chr 7448
'q' -> chr 491
'r' -> chr 640
's' -> chr 42801
't' -> chr 7451
'u' -> chr 7452
'v' -> chr 7456
'w' -> chr 7457
'y' -> chr 655
'z' -> chr 7458
c -> c
toCyrillic :: Char -> Char
toCyrillic = \case
'A' -> 'Д'
'B' -> 'Б'
'E' -> 'З'
'N' -> 'И'
'O' -> 'Ө'
'R' -> 'Я'
'U' -> 'Ц'
'W' -> 'Щ'
'X' -> 'Ж'
'a' -> 'д'
'b' -> 'в'
'e' -> 'ё'
'h' -> 'Ђ'
'i' -> 'ɪ'
'k' -> 'к'
'o' -> 'ө'
'r' -> 'я'
't' -> 'т'
'u' -> 'ц'
'y' -> 'џ'
c -> c
-- |Replaces all occurences of lowercase "ck" and "k" in a string with "cc"s.
mockCC :: T.Text -> T.Text
mockCC = T.replace "k" "cc" . T.replace "ck" "cc"
......
{-# LANGUAGE OverloadedStrings #-}
module Mock.Help (styleHelp) where
import qualified Data.Text as T
import Data.Text (Text)
styleHelp :: Text -> Text
styleHelp styleName = case styleName of
"random" -> "Flips lowercase characters pseudo-randomly into uppercase letters."
"alternate" -> "Flips every second letter into an uppercase one, starting with the second character."
"alternate2" -> "Like alternate, but ignores case in the input. Equivalent to lower|alternate."
"space" -> "Inserts a s p a c e between every two characters."
"space2" -> "Inserts two s p a c e s between every two characters."
"space3" -> "Inserts three s p a c e s between every two characters."
"lines" -> "Puts each character on a single line."
"upper" -> "Turns all characters into UPPERCASE ones."
"lower" -> "Turns all characters into lowercase ones."
"cyrillic" -> "Turns the text into a stereotypical fake russian looking variant."
"double" -> "Turns characters (latin letters and numbers) into their double-struck variants (𝕖𝕩𝕒𝕞𝕡𝕝𝕖). Also known as blackboard bold."
"dedouble" -> "Turns double-struck characters (like from the \"double\" style) back into normal ones."
"smallcaps" -> "Turns lowercase letters into small capitals."
"cc" -> "Replaces all occurences of lowercase \"c\", \"ck\" and \"k\" with \"cc\"."
"b" -> "Replaces all occurences of Bs (lower- and uppercase) with B-button emojis (🅱)."
"square" -> "Shows the input spaced in the first line and the tail of the input lined afterwards."
"strike" -> "Turns the input into strikethrough using Unicode combinators (e̶x̶a̶m̶p̶l̶e̶)."
_ -> "No documentation available."
resolver: lts-12.24
resolver: lts-13.25
packages:
- .
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment