{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module Text.Format (
      format
    ) where

import Data.List.Utils (replace)

{- |
Formats input string, using C\#-style.

First param is the input string in the form: \"Please, replace here {0} and here {1}\".

Second param is list of strings to put into {0}, {1} .. {N} positions.

Example: 

> format "Some {0} think that 1 + 1 = {1}." ["people",show 10]

Result is:

> "Some people think that 1 + 1 = 10."
-}
format :: String -> [String] -> String
format a b = doFormat a (0::Int,b)
    where
    doFormat a (_,[]) = a
    doFormat a (n,(b:bs)) = replace (old n) b a `doFormat` (n+1,bs)
    old n = "{" ++ show n ++ "}"