1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| function trim(texte)
{
var temp = texte.replace(/(^\s*)/g,"");// Remove blank before the string
return (temp.replace(/(\s*$)/g," "));// Add a blank after the string
}
function searchpad(searchtext)
{
var tableau = searchtext.split('"');//Splits on double quote
var resultat = '';
for(var i = 0; i < tableau.length; i++)
{
if(i%2 == 0)//For strings outside double quote
{
tableau[i] = trim(tableau[i])//Remove blank before and a 1 blank after the string
if(tableau[i] != " ")//if there is something in it
{
tableau[i] = tableau[i].replace(/\s+/gi, '* ');//Change all kind of blanc (\f,\n,\t," "...) with "* "
tableau[i] = tableau[i].replace('**', '*');// Replace "**" with "*" in case that the visitor had put a * after the word
}
}
else//For strings inside double quote => Do nothing
{
if(tableau[i] != "")
{
tableau[i] = "\""+tableau[i]+"\" ";//Except putting back the removed double quotes
}
}
}
for (var i = 0; i < tableau.length; i++) //Put back the array to string
{
resultat = resultat + tableau[i];
}
return(resultat);
} |