# HG changeset patch # User Daichi TOMA # Date 1364286620 -32400 # Node ID 392c3f30c0763faee511d159d716967ca68c2ea9 # Parent 98e1a35e4ab0bdb4c86efb9047086d22fc43c811 change to String from ByteString diff -r 98e1a35e4ab0 -r 392c3f30c076 Jungle.hs --- 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))