This deprecates string.to_bool and string.to_int*.
var lit = indices[0] as IntegerLiteral;
var memberaccess = expr.container as MemberAccess;
if (lit != null && memberaccess != null) {
- int dim = lit.value.to_int ();
+ int dim = int.parse (lit.value);
set_cvalue (expr, get_array_length_cexpression (memberaccess.inner, dim + 1));
} else {
Report.error (expr.source_reference, "only integer literals supported as index");
return 0;
}
- return value.to_int ();
+ return int.parse (value);
}
/**
return 0;
}
- return value.to_double ();
+ return double.parse (value);
}
/**
* @return boolean value
*/
public bool get_bool (string name) {
- return (args.get (name) == "true");
+ return bool.parse (args.get (name));
}
}
Report.error (source_reference, "Element access with non-literal index is not supported for tuples");
return false;
}
- int i = index.value.to_int ();
+ int i = int.parse (index.value);
if (container.value_type.get_type_arguments ().size == 0) {
error = true;
Report.error (source_reference, "Element access is not supported for untyped tuples");
if (id == "indent") {
expect (TokenType.ASSIGN);
expect (TokenType.INTEGER_LITERAL);
- scanner.indent_spaces = get_last_string().to_int();
+ scanner.indent_spaces = int.parse (get_last_string());
expect (TokenType.CLOSE_BRACKET);
expect (TokenType.EOL);
} else {
}
var length_literal = (IntegerLiteral) parse_literal ();
- array_length = length_literal.value.to_int ();
+ array_length = int.parse (length_literal.value);
}
expect (TokenType.CLOSE_BRACKET);
public int get_integer (ArgumentType arg) {
var lit = get_expression (arg) as IntegerLiteral;
if (lit != null) {
- return lit.value.to_int ();
+ return int.parse (lit.value);
}
return 0;
string closure = reader.get_attribute ("closure");
string destroy = reader.get_attribute ("destroy");
if (closure != null && &closure_idx != null) {
- closure_idx = closure.to_int ();
+ closure_idx = int.parse (closure);
}
if (destroy != null && &destroy_idx != null) {
- destroy_idx = destroy.to_int ();
+ destroy_idx = int.parse (destroy);
}
next ();
if (!(type_name == "GLib.Array" || type_name == "GLib.PtrArray")) {
if (reader.get_attribute ("length") != null
&& &array_length_index != null) {
- array_length_index = reader.get_attribute ("length").to_int ();
+ array_length_index = int.parse (reader.get_attribute ("length"));
}
next ();
var element_type = parse_type ();
value = value.substring (0, value.length - 1);
}
- int64 n = value.to_int64 ();
+ int64 n = int64.parse (value);
if (!u && n > 0x7fffffff) {
// value doesn't fit into signed 32-bit
l = 2;
if (target_st.is_integer_type ()) {
var int_attr = target_st.get_attribute ("IntegerType");
if (int_attr != null && int_attr.has_argument ("min") && int_attr.has_argument ("max")) {
- int val = literal_value.to_int ();
+ int val = int.parse (literal_value);
return (val >= int_attr.get_integer ("min") && val <= int_attr.get_integer ("max"));
} else {
// assume to be compatible if the target type doesn't specify limits
}
} else if (target_type.data_type is Enum && literal_type_name == "int") {
// allow implicit conversion from 0 to enum and flags types
- if (literal_value.to_int () == 0) {
+ if (int.parse (literal_value) == 0) {
return true;
}
}
}
var length_literal = (IntegerLiteral) parse_literal ();
- array_length = length_literal.value.to_int ();
+ array_length = int.parse (length_literal.value);
}
expect (TokenType.CLOSE_BRACKET);
return "false";
}
}
+
+ public static bool parse (string str) {
+ if (str == "true") {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ public static bool try_parse (string str, out bool result = null) {
+ if (str == "true") {
+ result = true;
+ return true;
+ } else if (str == "false") {
+ result = false;
+ return true;
+ } else {
+ result = false;
+ return false;
+ }
+ }
}
[SimpleType]
public static int from_big_endian (int val);
[CCode (cname = "GINT_FROM_LE")]
public static int from_little_endian (int val);
+
+ [CCode (cname = "atoi", cheader_filename = "stdlib.h")]
+ public static int parse (string str);
}
[SimpleType]
public static long from_big_endian (long val);
[CCode (cname = "GLONG_FROM_LE")]
public static long from_little_endian (long val);
+
+ [CCode (cname = "atol", cheader_filename = "stdlib.h")]
+ public static long parse (string str);
}
[SimpleType]
[CCode (cname = "GUINT64_SWAP_LE_BE")]
public uint64 swap_little_endian_big_endian ();
+
+ [CCode (cname = "g_ascii_strtoll")]
+ static int64 ascii_strtoll (string nptr, out char* endptr, uint _base);
+
+ public static int64 parse (string str) {
+ return ascii_strtoll (str, null, 0);
+ }
+ public static bool try_parse (string str, out int64 result = null) {
+ char* endptr;
+ result = ascii_strtoll (str, out endptr, 0);
+ if (endptr == (char*) str + str.length) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
[SimpleType]
public static uint64 from_big_endian (uint64 val);
[CCode (cname = "GUINT64_FROM_LE")]
public static uint64 from_little_endian (uint64 val);
+
+ [CCode (cname = "g_ascii_strtoull")]
+ static uint64 ascii_strtoull (string nptr, out char* endptr, uint _base);
+
+ public static uint64 parse (string str) {
+ return ascii_strtoull (str, null, 0);
+ }
+ public static bool try_parse (string str, out uint64 result = null) {
+ char* endptr;
+ result = ascii_strtoull (str, out endptr, 0);
+ if (endptr == (char*) str + str.length) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
[SimpleType]
public string to_string () {
return this.to_str(new char[DTOSTR_BUF_SIZE]);
}
+
+ [CCode (cname = "g_ascii_strtod")]
+ static double ascii_strtod (string nptr, out char* endptr);
+
+ public static double parse (string str) {
+ return ascii_strtod (str, null);
+ }
+ public static bool try_parse (string str, out double result = null) {
+ char* endptr;
+ result = ascii_strtod (str, out endptr);
+ if (endptr == (char*) str + str.length) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
[GIR (name = "glong")]
[CCode (cname = "g_str_hash")]
public uint hash ();
+ [Deprecated (replacement = "int.parse")]
[CCode (cname = "atoi")]
public int to_int ();
+ [Deprecated (replacement = "long.parse")]
[CCode (cname = "strtol")]
public long to_long (out unowned string endptr = null, int _base = 0);
+ [Deprecated (replacement = "double.parse")]
[CCode (cname = "g_ascii_strtod")]
public double to_double (out unowned string endptr = null);
+ [Deprecated (replacement = "uint64.parse")]
[CCode (cname = "strtoul")]
public ulong to_ulong (out unowned string endptr = null, int _base = 0);
+ [Deprecated (replacement = "int64.parse")]
[CCode (cname = "g_ascii_strtoll")]
public int64 to_int64 (out unowned string endptr = null, int _base = 0);
+ [Deprecated (replacement = "uint64.parse")]
[CCode (cname = "g_ascii_strtoull")]
public uint64 to_uint64 (out unowned string endptr = null, int _base = 0);
+ [Deprecated (replacement = "bool.parse")]
public bool to_bool () {
if (this == "true") {
return true;
} else if (nv[0] == "type_arguments") {
parse_type_arguments_from_string (return_type, eval (nv[1]));
} else if (nv[0] == "instance_pos") {
- cb.cinstance_parameter_position = eval (nv[1]).to_double ();
+ cb.cinstance_parameter_position = double.parse (eval (nv[1]));
} else if (nv[0] == "type_parameters") {
foreach (string type_param_name in eval (nv[1]).split (",")) {
cb.add_type_parameter (new TypeParameter (type_param_name, current_source_reference));
} else if (nv[0] == "base_type") {
st.base_type = parse_type_string (eval (nv[1]));
} else if (nv[0] == "rank") {
- st.set_rank (eval (nv[1]).to_int ());
+ st.set_rank (int.parse (eval (nv[1])));
} else if (nv[0] == "simple_type") {
if (eval (nv[1]) == "1") {
st.set_simple_type (true);
}
} else if (nv[0] == "array_length_pos") {
set_array_length_pos = true;
- array_length_pos = eval (nv[1]).to_double ();
+ array_length_pos = double.parse (eval (nv[1]));
} else if (nv[0] == "delegate_target_pos") {
set_delegate_target_pos = true;
- delegate_target_pos = eval (nv[1]).to_double ();
+ delegate_target_pos = double.parse (eval (nv[1]));
} else if (nv[0] == "type_name") {
p.variable_type = param_type = parse_type_from_string (eval (nv[1]), false);
} else if (nv[0] == "ctype") {
} else if (val == "") {
p.initializer = new StringLiteral ("\"\"", param_type.source_reference);
} else {
- unowned string endptr;
- char* val_end = (char*) val + val.length;
-
- val.to_long (out endptr);
- if ((long)endptr == (long)val_end) {
+ if (int64.try_parse (val)) {
p.initializer = new IntegerLiteral (val, param_type.source_reference);
} else {
- val.to_double (out endptr);
- if ((long)endptr == (long)val_end) {
+ if (double.try_parse (val)) {
p.initializer = new RealLiteral (val, param_type.source_reference);
} else {
if (val.has_prefix ("\"") && val.has_suffix ("\"")) {