Parses a string to an integer object. AbortOnError defines if the function should throw an exception if an error
occurs during the parsing. If it doesn't abort, the given default value is given back as result on error.
185049
protected Integer parseIntString(String string, boolean abortOnError, int def)
        throws TransformationOperationException {
        Integer integer = def;
        if (string == null) {
            logger.debug("Given string is empty so the default value is taken.");
        }
        try {
            integer = Integer.parseInt(string);
        } catch (NumberFormatException e) {
            StringBuilder builder = new StringBuilder();
            builder.append("The string ").append(string).append(" is not a number. ");
            if (abortOnError) {
                builder.append("The step will be skipped.");
            } else {
                builder.append(def).append(" will be taken instead.");
            }

            logger.warn(builder.toString());
            if (abortOnError) {
                throw new TransformationOperationException(builder.toString());
            }
        }
        return integer;
    }
551007
def filter_int(string, default=None, start=None, stop=None):
    """"""
    try:
        i = int(string)
        if start is not None and i < start:
            raise InvalidInputError("value too small")
        if stop is not None and i >= stop:
            raise InvalidInputError("value too large")
        return i
    except ValueError:
        if not string and default is not None:
            # empty string, default was given
            return default
        else:
            raise InvalidInputError
823100
function () {

// Parse a number value.

            var number,
                string = '';

            if (ch === '-') {
                string = '-';
                next('-');
            }
            while (ch >= '0' && ch <= '9') {
                string += ch;
                next();
            }
            if (ch === '.') {
                string += '.';
                while (next() && ch >= '0' && ch <= '9') {
                    string += ch;
                }
            }
            if (ch === 'e' || ch === 'E') {
                string += ch;
                next();
                if (ch === '-' || ch === '+') {
                    string += ch;
                    next();
                }
                while (ch >= '0' && ch <= '9') {
                    string += ch;
                    next();
                }
            }
            number = +string;
            if (isNaN(number)) {
                error("Bad number");
            } else {
                return number;
            }
        }
600503
def _parse_value(self, raw):
        
        try:
            if not raw.startswith("0"):
                val = float(raw)
                if (val % 1) == 0:  # integer
                    val = int(raw)
                    return str(val)

                return self.num_format.format(val)
            else:
                raise ValueError("Cannot parse int!")
        except:
            return str(raw)
895970
private int getIntValue(String str, int defaultValue) {

        try {
            int intValue = Integer.parseInt(str);
            return (intValue > 0) ? intValue : defaultValue;
        } catch (NumberFormatException e) {
            // intentionally left blank
        }
        return defaultValue;
    }
305989
@Override
    public void validateDefault(InputProblemReporter rep, boolean normalize)
        throws XMLStreamException
    {
        String defValue = mDefValue.getValue();
        int len = defValue.length();

        // Then code similar to actual value validation:
        StringBuilder sb = null;
        int count = 0;
        int start = 0;

        main_loop:
        while (start < len) {
            char c = defValue.charAt(start);

            // Ok, any white space to skip?
            while (true) {
                if (!WstxInputData.isSpaceChar(c)) {
                    break;
                }
                if (++start >= len) {
                    break main_loop;
                }
                c = defValue.charAt(start);
            }

            int i = start+1;

            do {
                if (++i >= len) {
                    break;
                }
                c = defValue.charAt(i);
            } while (!WstxInputData.isSpaceChar(c));
            ++count;
            String token = defValue.substring(start, i);
            int illegalIx = WstxInputData.findIllegalNmtokenChar(token, mCfgNsAware, mCfgXml11);
            if (illegalIx >= 0) {
                reportValidationProblem(rep, "Invalid default value '"+defValue
                                        +"'; character #"+illegalIx+" ("
                                        +WstxInputData.getCharDesc(defValue.charAt(illegalIx))
                                        +") not a valid NMTOKENS character");
            }

            if (normalize) {
                if (sb == null) {
                    sb = new StringBuilder(i - start + 32);
                } else {
                    sb.append(' ');
                }
                sb.append(token);
            }
            start = i+1;
        }

        if (count == 0) {
            reportValidationProblem(rep, "Invalid default value '"+defValue
                                    +"'; empty String is not a valid NMTOKENS value");
            return;
        }

        if (normalize) {
            mDefValue.setValue(sb.toString());
        }
    }
582023
def validate_non_negative_int_or_basestring(option, value):
    
    if isinstance(value, integer_types):
        return value
    elif isinstance(value, string_type):
        try:
            val = int(value)
        except ValueError:
            return value
        return validate_non_negative_integer(option, val)
    raise TypeError("Wrong type for %s, value must be an "
                    "non negative integer or a string" % (option,))
304102
public static int parseSeconds(String value, int defaultValue) {
    try {
      long seconds = Long.parseLong(value);
      if (seconds > Integer.MAX_VALUE) {
        return Integer.MAX_VALUE;
      } else if (seconds < 0) {
        return 0;
      } else {
        return (int) seconds;
      }
    } catch (NumberFormatException e) {
      return defaultValue;
    }
  }
1040669
static public Object stringToValue(String s) {
        if (s.equals("")) {
            return s;
        }
        if (s.equalsIgnoreCase("true")) {
            return Boolean.TRUE;
        }
        if (s.equalsIgnoreCase("false")) {
            return Boolean.FALSE;
        }
        if (s.equalsIgnoreCase("null")) {
            return JSONObject.NULL;
        }

        /*
         * If it might be a number, try converting it.
         * We support the non-standard 0x- convention.
         * If a number cannot be produced, then the value will just
         * be a string. Note that the 0x-, plus, and implied string
         * conventions are non-standard. A JSON parser may accept
         * non-JSON forms as long as it accepts all correct JSON forms.
         */

        char b = s.charAt(0);
        if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
            if (b == '0' && s.length() > 2 &&
                        (s.charAt(1) == 'x' || s.charAt(1) == 'X')) {
                try {
                    return new Integer(Integer.parseInt(s.substring(2), 16));
                }
                catch (Exception ignore) {
                }
            }
            try {
                if (s.indexOf('.') > -1 ||
                        s.indexOf('e') > -1 || s.indexOf('E') > -1) {
                    return Double.valueOf(s);
                }
                else {
                    Long myLong = new Long(s);
                    if (myLong.longValue() == myLong.intValue()) {
                        return new Integer(myLong.intValue());
                    }
                    return myLong;
                }
            }
            catch (Exception ignore) {
            }
        }
        return s;
    }
909114
function (e,err)
		{
			if (typeof err == 'string' || typeof err != 'object' || err.stack == undefined)
				return false;

			e.owner.e.log('ERROR: '+err.message,'exception');

			var _stack = err.stack.split("\n");
			_stack.shift();
			for (s in _stack)
				e.owner.e.log(_stack[s],'stack');
		}
1172960
private static int toInt(String str, int defaultVal) {
    try {
      return Integer.parseInt(str.trim());
    } catch (Exception e) {
      return defaultVal;
    }
  }
380955
def setThrowException(self, setting):
        
        if setting:
            self._throwException = True
            self._findFailedResponse = "ABORT"
        else:
            self._throwException = False
            self._findFailedResponse = "SKIP"
896622
public static int parseIntOrDefault(final String value, final int defaultValue)
    {
        if (null == value)
        {
            return defaultValue;
        }

        return Integer.parseInt(value);
    }
1133907
function primitive(str) {
	if (typeof str !== 'string')
		return str
	if (str === 'null')
		return null
	if (str === 'undefined')
		return undefined
	if (str === 'true')
		return true
	if (str === 'false')
		return false
	if (str === 'true')
		return true
	if (str === 'NaN')
		return NaN
	//if (str === 'Infinity')
	//	return Number.POSITIVE_INFINITY
	let ret
	if (str.indexOf('.') >= 0)
		ret = Number.parseFloat(str)
	else
		ret = Number.parseInt(str)
	if (!Number.isNaN(ret))
		return ret
	return str
}
1227835
function throwUnexpected (attr, obj) {
  var e = Unexpected(attr, obj);
  Error.captureStackTrace(e, throwUnexpected);
  throw e;
}
832473
public final void defaultValue() throws RecognitionException {
		int defaultValue_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 79) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:677:6: ( 'default' elementValue )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:677:8: 'default' elementValue
			{
			match(input,74,FOLLOW_74_in_defaultValue2721); if (state.failed) return;
			pushFollow(FOLLOW_elementValue_in_defaultValue2723);
			elementValue();
			state._fsp--;
			if (state.failed) return;
			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 79, defaultValue_StartIndex); }

		}
	}
246989
def catch_error(exception)
      if handler = handler_for_error(exception)
        handler.arity.zero? ? handler.call : handler.call(exception)
        true
      end
    end