/*
 * Leet Translation helper function library
 *
 * By Ravenous Bugblatter Beast
 * ravenousbugblatterbeast@hotmail.com
 * http://www.ravenousbugblatterbeast.pwp.blueyonder.co.uk
 *
 *
 * This function contains one user-callable function deleet, 
 * which removes leet from a string. e.g. converts |_337 into leet.
 */
 
#if defined _leet_included
  #endinput
#endif
#define _leet_included
 
 
/* L33t alphabet
 
a   b    c   d    e   f       g   h     i    j   k    l    m      n     o   p    q    r   s   t   u     v    w      x    y    z
4   |3   C   |)   3   |>|-|   6   |-|   1   _|   |<   |_   |\/|   |\|   0   |>   Q   |2   5   7   |_|   \/   \/\/   ><   `/   Z
@                                       !             |                                   $
*/
 
/* Support function */
stock deleetclose(str[],start,num) {
  new c = strlen(str) - num;
  new i;
  for (i=start+1;i<c;i++) {
    str[i]=str[i+num];
  }
  str[c]=NULL_CHAR;
}
 
/* Removes |_337 from str[] */
stock deleet(str[]) {
  new i=0;
  new c = strlen(str);
  while(i<c) {
    if (str[i]=='4') {
      str[i]='a';
    } else if (str[i]=='|') {
      if (i<c-1) {
	if (str[i+1] == '3') {
          str[i] ='b';
	  deleetclose(str,i,1);
	} else if (str[i+1] == ')') {
	  str[i] ='d';
	  deleetclose(str,i,1);
	} else if (str[i+1] == '<') {
	  str[i] ='k';
	  deleetclose(str,i,1);
	} else if (str[i+1] == '>') {
	  if (i<c-4) {
	    if ((str[i+1] == '>') && (str[i+2] == '|') && (str[i+3] == '-') && (str[i+4] == '|')) {
	      str[i]='f';
	      deleetclose(str,i,4);
	    }
	    else {
	      str[i]='p';
	      deleetclose(str,i,1);
	    }
	  }
	  else {
	    str[i] ='p';
	    deleetclose(str,i,1);
	  }
	} else if (str[i+1] == '-') {
	  if (i<c-2) {
	    if (str[i+2]=='|') {
	      str[i] = 'h';
	      deleetclose(str,i,2);
	    }
	  }
	} else if (str[i+1] == '_') {
	  if (i<c-2) {
	    if (str[i+2] =='|') {
	      str[i] ='u';
	      deleetclose(str,i,2);
	    }
	    else {
	      str[i]='l';
	      deleetclose(str,i,1);
	    }
	  } else {
	    str[i]='l';
	    deleetclose(str,i,1);
	  }
	} else if (str[i+1]=='\') {
	  if (i<c-2) {
	    if (i<c-3) {
	      if ((str[i+2] == '/') && (str[i+3] == '|')) {
		str[i]='m';
		deleetclose(str,i,3);
	      }
	      else if (str[i+2] == '|') {
		str[i]='n';
		deleetclose(str,i,2);
	      }
	    } else if (str[i+2] == '|') {
	      str[i]='n';
	      deleetclose(str,i,2);
	    }
	  }
	}
	else if (str[i+1] == '2') {
	  str[i]='r';
	  deleetclose(str,i,1);
	} else {
	  str[i] = 'l';
	}
      }
      else {
       str[i] = 'l';
      }
    }
    else if (str[i] == '3') {
      str[i]='e';
    }
    else if (str[i] == '6') {
      str[i]='g';
    }
    else if ((str[i] == '1') || (str[i] =='!')) {
      str[i]='i';
    }
    else if (str[i] == '_') {
      if (i < c-1) {
	if (str[i+1] =='|') {
	  str[i] = 'j';
	  deleetclose(str,i,1);
	}
      }
    }
    else if (str[i] == '0') {
      str[i] ='o';
    }
    else if ((str[i] == '5') || (str[i] == '$')) {
      str[i] ='s';
    }
    else if (str[i] == '7') {
      str[i] = 't';
    }
    else if (str[i] == '\') {
      if (i < c-1) {
	if (i < c-3) {
	  if ((str[i+1] == '/') &&(str[i+3] == '/') &&(str[i+2] == '\')) {
	    str[i] = 'w';
	    deleetclose(str,i,3);
	  }
	  else if (str[i+1] == '/') {
	    str[i] = 'v';
	    deleetclose(str,i,1);
          }
	} else if (str[i+1] == '/') {
	  str[i] = 'v';
	  deleetclose(str,i,1);
	}
      } else if (str[i+1] == '/') {
	str[i] = 'v';
	deleetclose(str,i,1);
      }
    }
    else if (str[i] == '>') {
      if (i<c-1) {
	if (str[i+1] == '<') {
	  str[i]='x';
	  deleetclose(str,i,1);
	}
      }
    }
    else if (str[i] == '`') {
      if (i<c-1) {
	if (str[i+1] == '/') {
	  str[i]='y';
	  deleetclose(str,i,1);
	}
      } 
    }
    else if (str[i] == '@') {
      str[i] ='a';
    }
 
    i++;
    c = strlen(str);
  }
}