### jack_misc - misc stuff for
### jack - extract audio from a CD and MP3ify it using 3rd party software
### Copyright (C) 1999,2000  Arne Zellentin <arne@unix-ag.org>

### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.

### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.

### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import string, types

def multi_replace(s, rules):
    "like string.replace but take list (('from0', 'to0'), ('from1', 'to1'))..."
    # currently all from must be like %x (a percent sign follow by single char.
    res = ""
    maybe = 0
    for i in s:
        if maybe:
            maybe = 0
            found = 0
            for j in rules:
                if ("%" + i) == j[0]:
                    res = res[:-1] + j[1]
                    found = 1
            if found:
                continue
        maybe = 0
        if i == "%":
            maybe = 1
        res = res + i
    return res
