Mercurial > hg > Members > toma > Jungle-haskell
changeset 2:392c3f30c076
change to String from ByteString
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Mar 2013 17:30:20 +0900 |
parents | 98e1a35e4ab0 |
children | 090bdde20e9f |
files | Jungle.hs |
diffstat | 1 files changed, 5 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Jungle.hs Tue Mar 26 16:24:20 2013 +0900 +++ b/Jungle.hs Tue Mar 26 17:30:20 2013 +0900 @@ -19,10 +19,9 @@ ) where import qualified Data.Map as Map -import qualified Data.ByteString as B data Children = Children (Map.Map Int Node) deriving (Show) -data Attributes = Attributes (Map.Map String B.ByteString) deriving (Show) +data Attributes = Attributes (Map.Map String String) deriving (Show) data Node = Empty | Node @@ -63,8 +62,8 @@ at :: Children -> Int -> Node at (Children map) pos = Map.findWithDefault Empty pos map -get :: Attributes -> String -> B.ByteString -get (Attributes map) key = Map.findWithDefault B.empty key map +get :: Attributes -> String -> String +get (Attributes map) key = Map.findWithDefault "" key map addNewChildAt :: Tree -> Path -> Int -> Node -> Tree addNewChildAt tree path pos node = Tree $ addNewChildAt' (getRootNode tree) path pos node @@ -75,9 +74,6 @@ where child = at (getChildren parent) --- RootNodeの子が消せない --- addNewChildAtが下に付け加えることしかできないから --- RootNodeのこの場合例外処理すればいけるけどスマートな書き方ないか考える deleteChildAt :: Tree -> Path -> Int -> Tree deleteChildAt tree path pos = editTree tree path (deleteChild target pos) where @@ -98,7 +94,7 @@ deleteChild Empty _ = Empty deleteChild (Node (Children map) attributes) pos = Node (Children (Map.delete pos map)) attributes -putAttribute :: Tree -> Path -> String -> B.ByteString -> Tree +putAttribute :: Tree -> Path -> String -> String -> Tree putAttribute tree path key value = editTree tree path (putAttribute' target key value) where root = getRootNode tree @@ -110,7 +106,7 @@ root = getRootNode tree target = getNode root path -putAttribute' :: Node -> String -> B.ByteString -> Node +putAttribute' :: Node -> String -> String -> Node putAttribute' Empty key value = putAttribute' (Node (Children Map.empty) (Attributes Map.empty)) key value putAttribute' (Node children (Attributes map)) key value = Node children (Attributes (Map.insert key value map))