<commit_before>/**
 * Implements the Cold Fusion Function val
 */
package railo.runtime.functions.string;

import railo.runtime.PageContext;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;

public final class Val implements Function {
	
	public static double call(PageContext pc , Object value) throws PageException {
	    //if(value instanceof Boolean || value instanceof Number) return Caster.toDoubleValue(value);
	    
        //double dbl=Caster.toDoubleValue(value,Double.NaN);
        //if(Decision.isValid(dbl)) return dbl;
        
        String str=Caster.toString(value);
        
	    int pos=getPos(str);
	    if(pos<=0) {
		    if(Decision.isBoolean(str)) return Caster.toDoubleValue(str);
		    return 0;
		}
		return Caster.toDoubleValue(str.substring(0,pos));
	}
	
	private static int getPos(String str) { 
        if(str==null) return 0; 
        str=str.trim();
        int pos=0; 
        int len=str.length(); 
        if(len==0) return 0; 
        char curr=str.charAt(pos); <commit_msg>solved ticket https://jira.jboss.org/browse/RAILO-1092<commit_after>/**
 * Implements the Cold Fusion Function val
 */
package railo.runtime.functions.string;

import railo.print;
import railo.runtime.PageContext;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;

public final class Val implements Function {
	
	public static double call(PageContext pc , Object value) throws PageException {
	    String str=Caster.toString(value);
        str=str.trim();
	    int pos=getPos(str);
	    if(pos<=0) {
		    if(Decision.isBoolean(str)) return Caster.toDoubleValue(str);
		    return 0;
		}
		return Caster.toDoubleValue(str.substring(0,pos));
	}
	
	private static int getPos(String str) { 
        if(str==null) return 0; 
        
        int pos=0; 
        int len=str.length(); 
        if(len==0) return 0; 
        char curr=str.charAt(pos); 
{'fraction_non_alphanumeric': 0.11704711024769306, 'fraction_numerical': 0.008742107819329771, 'mean_word_length': 3.2386831275720165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3956096', 'n_tokens_mistral': 687, 'n_tokens_neox': 640, 'n_words': 145}