001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019/**
020 * Implements the CFML Function findoneof
021 */
022package lucee.runtime.functions.string;
023
024import lucee.runtime.PageContext;
025import lucee.runtime.ext.function.Function;
026
027public final class FindOneOf implements Function {
028
029        private static final long serialVersionUID = -7521748254181624968L;
030        public static double call(PageContext pc , String set, String str) {
031                return call(pc,set,str,1);
032        }
033        public static double call(PageContext pc , String strSet, String strData, double number) {
034                // strData
035                char[] data=strData.toCharArray();
036                // set
037                char[] set=strSet.toCharArray();
038                // start
039                int start=(int)number-1;
040                if(start<0)start=0;
041                
042                if( start>=data.length || set.length==0) return 0;
043                //else {
044                        for(int i=start;i<data.length;i++) {
045                                for(int y=0;y<set.length;y++) {
046                                        if(data[i]==set[y])return i+1;
047                                }
048                        }
049                //}
050                return 0;
051        }
052
053}