lib: Implemented HeaderMapIterator on Curl
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 18 Oct 2013 19:04:35 +0000 (15:04 -0400)
committerJean Privat <jean@pryen.org>
Thu, 24 Oct 2013 15:59:55 +0000 (11:59 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/curl/curl.nit

index 788c553..6b6b34c 100644 (file)
@@ -439,6 +439,8 @@ class HeaderMap
                end
        end
 
+       fun iterator: MapIterator[String, String] do return new HeaderMapIterator(self)
+
        # Convert Self to a single string used to post http fields
        fun to_url_encoded(curl: CCurl): String
        do
@@ -471,3 +473,15 @@ class HeaderMap
        fun length: Int do return arr.length
        fun is_empty: Bool do return arr.is_empty
 end
+
+class HeaderMapIterator
+       super MapIterator[String, String]
+
+       private var iterator: Iterator[Couple[String, String]]
+       init(map: HeaderMap) do self.iterator = map.arr.iterator
+
+       redef fun is_ok do return self.iterator.is_ok
+       redef fun next do self.iterator.next
+       redef fun item do return self.iterator.item.second
+       redef fun key do return self.iterator.item.first
+end