@@ -4,9 +4,28 @@ import Tokenizer
4
4
import Evaluator
5
5
import Conversion
6
6
import Control.Monad.Error
7
+ import Data.Char
7
8
8
- functions = [(" strlen" , phpStrLen)]
9
+ functions :: [(String , PHPFunctionType )]
10
+ functions = [ (" strlen" , phpStrLen)
11
+ , (" strtoupper" , phpStrToUpper)
12
+ , (" strtolower" , phpStrToLower)]
13
+
14
+ -- Conversion of a PHPString for a Haskell [Char]
15
+ toHaskellStr :: PHPValue -> String
16
+ toHaskellStr x = stringFromPHPValue $ castToString x
17
+
18
+ -- Throws an arity error
19
+ arityErrorFor f = throwError $ Default $ " Wrong number of arguments to " ++ f
9
20
10
21
phpStrLen :: PHPFunctionType
11
- phpStrLen (s: [] ) = return $ PHPInt $ toInteger $ length $ stringFromPHPValue $ castToString s
12
- phpStrLen _ = throwError $ Default " Wrong number of arguments to strlen"
22
+ phpStrLen (s: [] ) = return $ PHPInt $ toInteger $ length $ toHaskellStr s
23
+ phpStrLen _ = arityErrorFor " strlen"
24
+
25
+ phpStrToUpper :: PHPFunctionType
26
+ phpStrToUpper (s: [] ) = return $ PHPString $ map toUpper $ toHaskellStr s
27
+ phpStrToUpper _ = arityErrorFor " strtoupper"
28
+
29
+ phpStrToLower :: PHPFunctionType
30
+ phpStrToLower (s: [] ) = return $ PHPString $ map toLower $ toHaskellStr s
31
+ phpStrToLower _ = arityErrorFor " strtolower"
0 commit comments