Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Created March 18, 2012 17:42
Show Gist options
  • Save cosmo0920/2078409 to your computer and use it in GitHub Desktop.
Save cosmo0920/2078409 to your computer and use it in GitHub Desktop.
モナドが絡んで訳のわからないことに…
import Text.Regex.Posix
main = do name <- getLine
print (checkURL name)
print (countURLLength name)
print (twitLength name)
checkLengthAndTwit name
-- URLの正規表現を定める
urlRegex :: [Char]
urlRegex = "(https?|ftp)(://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)"
-- t.coのURL長
tcoLength :: Int
tcoLength = length "http://t.co/xxxxxxx"
-- その文字列、URLですか?
checkURL url = ( url =~ urlRegex ) :: String
-- URLの文字数をカウント
countURLLength :: [a] -> Int
countURLLength url = length url
twitLength :: [a] -> Int
twitLength str = (length str) - (countURLLength str) + tcoLength
twitLength' str = if 0 < (countURLLength str) then
return () >> return ((length str) - (countURLLength str) + tcoLength)
else return() >> return (length str)
-- 文字数のチェック
-- TODO:URLの文字数カウント
-- checkLengthAndTwit :: [Char] -> IO ()
checkLengthAndTwit msg
| 0 == twitLength msg = putStrLn "at least 1 character!"
| 140 < twitLength msg = putStrLn "over 140 characters!!"
| otherwise = print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment