Please add a tests of your functions for empty strings. This function will certainly fail then ;-)