# -*- coding: utf-8 -*-
"""
Created on Sun Jan 12 14:58:04 2014

@author: dconduche
"""

def RechercheMotTexte(mot,texte):#Recherche la présence d'un mot dans un texte
                            #mot : string contenant le motif à rechercher (peut contenir plusieurs mots)
                            #texte : string contenant le texte où l'on cherche "mot".
    n=len(mot)
    for i in range(len(texte)-n+1):
        if texte[i:i+n]==mot:
            return True
    return False

def RechercheMotTexteIndice(mot,texte):#Recherche la présence d'un mot dans un texte, retourne le plus grand indice si le motif est présent, et -1 sinon
                            #mot : string contenant le motif à rechercher (peut contenir plusieurs mots)
                            #texte : string contenant le texte où l'on cherche "mot".
    n=len(mot)
    indice=-1
    for i in range(len(texte)-n+1):
        if texte[i:i+n]==mot:
            indice=i
    return indice

#Tests :
TexteTest='Ce test est un petit test'
print(TexteTest)
M=['Ceci', 't u', 'test', 'blabla'] #Liste de motifs à chercher. Présents ou non, au bout ou non.
for mot in M:
    print('Présence de \''+mot+'\' dans le texte :'+str(RechercheMotTexte(mot,TexteTest)))

for mot in M:
    print('Indice de \''+mot+'\' dans le texte :'+str(RechercheMotTexteIndice(mot,TexteTest)))
