001    /*
002     * StripLeadingNonAlphaNum.java
003     *
004     * Version: $Revision: 3738 $
005     *
006     * Date: $Date: 2009-04-24 04:32:12 +0000 (Fri, 24 Apr 2009) $
007     *
008     * Copyright (c) 2002-2009, The DSpace Foundation.  All rights reserved.
009     *
010     * Redistribution and use in source and binary forms, with or without
011     * modification, are permitted provided that the following conditions are
012     * met:
013     *
014     * - Redistributions of source code must retain the above copyright
015     * notice, this list of conditions and the following disclaimer.
016     *
017     * - Redistributions in binary form must reproduce the above copyright
018     * notice, this list of conditions and the following disclaimer in the
019     * documentation and/or other materials provided with the distribution.
020     *
021     * - Neither the name of the DSpace Foundation nor the names of its
022     * contributors may be used to endorse or promote products derived from
023     * this software without specific prior written permission.
024     *
025     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026     * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
029     * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
030     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
031     * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
032     * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
033     * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
034     * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
035     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
036     * DAMAGE.
037     */
038    
039    package org.dspace.text.filter;
040    
041    public class StripLeadingNonAlphaNum implements TextFilter
042    {
043        public String filter(String str)
044        {
045            int i = 0;
046    
047            while (i < str.length() && !Character.isLetterOrDigit(str.charAt(i)))
048                i++;
049    
050            if (i > 0)
051                return str.substring(i);
052    
053            return str;
054        }
055    
056        public String filter(String str, String lang)
057        {
058            return filter(str);
059        }
060    }