Rename is_valid_integer() to is_valid_int()

Method from `String`
This commit is contained in:
Lightning_A 2021-06-16 10:24:34 -06:00
parent 48fe9c9794
commit b6af2a29eb
10 changed files with 49 additions and 49 deletions

View file

@ -294,7 +294,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
// Port // Port
if (base.begins_with(":")) { if (base.begins_with(":")) {
base = base.substr(1, base.length() - 1); base = base.substr(1, base.length() - 1);
if (!base.is_valid_integer()) { if (!base.is_valid_int()) {
return ERR_INVALID_PARAMETER; return ERR_INVALID_PARAMETER;
} }
r_port = base.to_int(); r_port = base.to_int();
@ -4168,7 +4168,7 @@ String String::trim_suffix(const String &p_suffix) const {
return s; return s;
} }
bool String::is_valid_integer() const { bool String::is_valid_int() const {
int len = length(); int len = length();
if (len == 0) { if (len == 0) {
@ -4393,7 +4393,7 @@ bool String::is_valid_ip_address() const {
} }
for (int i = 0; i < ip.size(); i++) { for (int i = 0; i < ip.size(); i++) {
String n = ip[i]; String n = ip[i];
if (!n.is_valid_integer()) { if (!n.is_valid_int()) {
return false; return false;
} }
int val = n.to_int(); int val = n.to_int();

View file

@ -425,7 +425,7 @@ public:
String validate_node_name() const; String validate_node_name() const;
bool is_valid_identifier() const; bool is_valid_identifier() const;
bool is_valid_integer() const; bool is_valid_int() const;
bool is_valid_float() const; bool is_valid_float() const;
bool is_valid_hex_number(bool p_with_prefix) const; bool is_valid_hex_number(bool p_with_prefix) const;
bool is_valid_html_color() const; bool is_valid_html_color() const;

View file

@ -1380,7 +1380,7 @@ static void _register_variant_builtin_methods() {
bind_method(String, validate_node_name, sarray(), varray()); bind_method(String, validate_node_name, sarray(), varray());
bind_method(String, is_valid_identifier, sarray(), varray()); bind_method(String, is_valid_identifier, sarray(), varray());
bind_method(String, is_valid_integer, sarray(), varray()); bind_method(String, is_valid_int, sarray(), varray());
bind_method(String, is_valid_float, sarray(), varray()); bind_method(String, is_valid_float, sarray(), varray());
bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false)); bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false));
bind_method(String, is_valid_html_color, sarray(), varray()); bind_method(String, is_valid_html_color, sarray(), varray());

View file

@ -352,7 +352,7 @@
Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit. Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit.
</description> </description>
</method> </method>
<method name="is_valid_integer" qualifiers="const"> <method name="is_valid_int" qualifiers="const">
<return type="bool"> <return type="bool">
</return> </return>
<description> <description>

View file

@ -136,7 +136,7 @@ void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Tra
ERR_FAIL_COND(!tile_data); ERR_FAIL_COND(!tile_data);
Vector<String> components = String(p_property).split("/", true); Vector<String> components = String(p_property).split("/", true);
if (components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_integer()) { if (components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
int occlusion_layer = components[0].trim_prefix("occlusion_layer_").to_int(); int occlusion_layer = components[0].trim_prefix("occlusion_layer_").to_int();
if (occlusion_layer >= 0 && occlusion_layer < p_tile_set->get_occlusion_layers_count()) { if (occlusion_layer >= 0 && occlusion_layer < p_tile_set->get_occlusion_layers_count()) {
// Draw all shapes. // Draw all shapes.
@ -158,7 +158,7 @@ void TileDataCollisionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Tra
ERR_FAIL_COND(!tile_data); ERR_FAIL_COND(!tile_data);
Vector<String> components = String(p_property).split("/", true); Vector<String> components = String(p_property).split("/", true);
if (components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_integer()) { if (components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
int physics_layer = components[0].trim_prefix("physics_layer_").to_int(); int physics_layer = components[0].trim_prefix("physics_layer_").to_int();
if (physics_layer >= 0 && physics_layer < p_tile_set->get_physics_layers_count()) { if (physics_layer >= 0 && physics_layer < p_tile_set->get_physics_layers_count()) {
// Draw all shapes. // Draw all shapes.
@ -190,7 +190,7 @@ void TileDataNavigationPolygonEditor::draw_over_tile(CanvasItem *p_canvas_item,
ERR_FAIL_COND(!tile_data); ERR_FAIL_COND(!tile_data);
Vector<String> components = String(p_property).split("/", true); Vector<String> components = String(p_property).split("/", true);
if (components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_integer()) { if (components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
int navigation_layer = components[0].trim_prefix("navigation_layer_").to_int(); int navigation_layer = components[0].trim_prefix("navigation_layer_").to_int();
if (navigation_layer >= 0 && navigation_layer < p_tile_set->get_navigation_layers_count()) { if (navigation_layer >= 0 && navigation_layer < p_tile_set->get_navigation_layers_count()) {
// Draw all shapes. // Draw all shapes.

View file

@ -1040,7 +1040,7 @@ Map<Vector2i, List<const PropertyInfo *>> TileSetAtlasSourceEditor::_group_prope
Vector<String> components = String(E_property->get().name).split("/", true, 1); Vector<String> components = String(E_property->get().name).split("/", true, 1);
if (components.size() >= 1) { if (components.size() >= 1) {
Vector<String> coord_arr = components[0].split(":"); Vector<String> coord_arr = components[0].split(":");
if (coord_arr.size() == 2 && coord_arr[0].is_valid_integer() && coord_arr[1].is_valid_integer()) { if (coord_arr.size() == 2 && coord_arr[0].is_valid_int() && coord_arr[1].is_valid_int()) {
Vector2i coords = Vector2i(coord_arr[0].to_int(), coord_arr[1].to_int()); Vector2i coords = Vector2i(coord_arr[0].to_int(), coord_arr[1].to_int());
per_tile[coords].push_back(&(E_property->get())); per_tile[coords].push_back(&(E_property->get()));
} }
@ -1088,7 +1088,7 @@ void TileSetAtlasSourceEditor::_menu_option(int p_option) {
if (per_tile.has(selected.tile)) { if (per_tile.has(selected.tile)) {
for (List<const PropertyInfo *>::Element *E_property = per_tile[selected.tile].front(); E_property; E_property = E_property->next()) { for (List<const PropertyInfo *>::Element *E_property = per_tile[selected.tile].front(); E_property; E_property = E_property->next()) {
Vector<String> components = E_property->get()->name.split("/", true, 2); Vector<String> components = E_property->get()->name.split("/", true, 2);
if (components.size() >= 2 && components[1].is_valid_integer() && components[1].to_int() == selected.alternative) { if (components.size() >= 2 && components[1].is_valid_int() && components[1].to_int() == selected.alternative) {
String property = E_property->get()->name; String property = E_property->get()->name;
Variant value = tile_set_atlas_source->get(property); Variant value = tile_set_atlas_source->get(property);
if (value.get_type() != Variant::NIL) { if (value.get_type() != Variant::NIL) {

View file

@ -356,8 +356,8 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p
} }
} }
} else if ((p_property == "terrains_sets_count" && tile_data->get_terrain_set() >= (int)p_new_value) || } else if ((p_property == "terrains_sets_count" && tile_data->get_terrain_set() >= (int)p_new_value) ||
(components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer() && components[1] == "mode") || (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "mode") ||
(components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer() && components[1] == "terrains_count" && tile_data->get_terrain_set() == components[0].trim_prefix("terrain_set_").to_int() && (int)p_new_value < tile_set->get_terrains_count(tile_data->get_terrain_set()))) { (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrains_count" && tile_data->get_terrain_set() == components[0].trim_prefix("terrain_set_").to_int() && (int)p_new_value < tile_set->get_terrains_count(tile_data->get_terrain_set()))) {
ADD_UNDO(tile_data, "terrain_set"); ADD_UNDO(tile_data, "terrain_set");
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) { if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/right_side"); ADD_UNDO(tile_data, "terrains_peering_bit/right_side");
@ -423,8 +423,8 @@ void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p
ADD_UNDO(tile_data, vformat("custom_data_%d", custom_data_layer_index)); ADD_UNDO(tile_data, vformat("custom_data_%d", custom_data_layer_index));
} }
} }
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_integer() && components[1] == "type") { } else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int() && components[1] == "type") {
int custom_data_layer = components[0].trim_prefix("custom_data_layer_").is_valid_integer(); int custom_data_layer = components[0].trim_prefix("custom_data_layer_").is_valid_int();
ADD_UNDO(tile_data, vformat("custom_data_%d", custom_data_layer)); ADD_UNDO(tile_data, vformat("custom_data_%d", custom_data_layer));
} }
} }

View file

@ -801,7 +801,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
#ifndef DISABLE_DEPRECATED #ifndef DISABLE_DEPRECATED
// TODO: THIS IS HOW WE CHECK IF WE HAVE A DEPRECATED RESOURCE // TODO: THIS IS HOW WE CHECK IF WE HAVE A DEPRECATED RESOURCE
// This should be moved to a dedicated conversion system // This should be moved to a dedicated conversion system
if (components.size() >= 1 && components[0].is_valid_integer()) { if (components.size() >= 1 && components[0].is_valid_int()) {
int id = components[0].to_int(); int id = components[0].to_int();
// Get or create the compatibility object // Get or create the compatibility object
@ -966,7 +966,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
#endif // DISABLE_DEPRECATED #endif // DISABLE_DEPRECATED
// This is now a new property. // This is now a new property.
if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_integer()) { if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
// Occlusion layers. // Occlusion layers.
int index = components[0].trim_prefix("occlusion_layer_").to_int(); int index = components[0].trim_prefix("occlusion_layer_").to_int();
ERR_FAIL_COND_V(index < 0, false); ERR_FAIL_COND_V(index < 0, false);
@ -985,7 +985,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_occlusion_layer_sdf_collision(index, p_value); set_occlusion_layer_sdf_collision(index, p_value);
return true; return true;
} }
} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int(); int index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(index < 0, false); ERR_FAIL_COND_V(index < 0, false);
@ -1012,7 +1012,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_physics_layer_physics_material(index, physics_material); set_physics_layer_physics_material(index, physics_material);
return true; return true;
} }
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer()) { } else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains. // Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int(); int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
ERR_FAIL_COND_V(terrain_set_index < 0, false); ERR_FAIL_COND_V(terrain_set_index < 0, false);
@ -1029,7 +1029,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} }
set_terrains_count(terrain_set_index, p_value); set_terrains_count(terrain_set_index, p_value);
return true; return true;
} else if (components.size() >= 3 && components[1].begins_with("terrain_") && components[1].trim_prefix("terrain_").is_valid_integer()) { } else if (components.size() >= 3 && components[1].begins_with("terrain_") && components[1].trim_prefix("terrain_").is_valid_int()) {
int terrain_index = components[1].trim_prefix("terrain_").to_int(); int terrain_index = components[1].trim_prefix("terrain_").to_int();
ERR_FAIL_COND_V(terrain_index < 0, false); ERR_FAIL_COND_V(terrain_index < 0, false);
if (components[2] == "name") { if (components[2] == "name") {
@ -1054,7 +1054,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
return true; return true;
} }
} }
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// Navigation layers. // Navigation layers.
int index = components[0].trim_prefix("navigation_layer_").to_int(); int index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(index < 0, false); ERR_FAIL_COND_V(index < 0, false);
@ -1066,7 +1066,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_navigation_layer_layers(index, p_value); set_navigation_layer_layers(index, p_value);
return true; return true;
} }
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
// Custom data layers. // Custom data layers.
int index = components[0].trim_prefix("custom_data_layer_").to_int(); int index = components[0].trim_prefix("custom_data_layer_").to_int();
ERR_FAIL_COND_V(index < 0, false); ERR_FAIL_COND_V(index < 0, false);
@ -1085,8 +1085,8 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_custom_data_type(index, Variant::Type(int(p_value))); set_custom_data_type(index, Variant::Type(int(p_value)));
return true; return true;
} }
} else if (components.size() == 2 && components[0] == "sources" && components[1].is_valid_integer()) { } else if (components.size() == 2 && components[0] == "sources" && components[1].is_valid_int()) {
// Create source only if it does not exists. // Create source only if it does not exist.
int source_id = components[1].to_int(); int source_id = components[1].to_int();
if (!has_source(source_id)) { if (!has_source(source_id)) {
@ -1105,7 +1105,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
Vector<String> components = String(p_name).split("/", true, 2); Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_integer()) { if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
// Occlusion layers. // Occlusion layers.
int index = components[0].trim_prefix("occlusion_layer_").to_int(); int index = components[0].trim_prefix("occlusion_layer_").to_int();
if (index < 0 || index >= occlusion_layers.size()) { if (index < 0 || index >= occlusion_layers.size()) {
@ -1118,7 +1118,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_occlusion_layer_sdf_collision(index); r_ret = get_occlusion_layer_sdf_collision(index);
return true; return true;
} }
} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int(); int index = components[0].trim_prefix("physics_layer_").to_int();
if (index < 0 || index >= physics_layers.size()) { if (index < 0 || index >= physics_layers.size()) {
@ -1134,7 +1134,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_physics_layer_physics_material(index); r_ret = get_physics_layer_physics_material(index);
return true; return true;
} }
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_integer()) { } else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains. // Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int(); int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
if (terrain_set_index < 0 || terrain_set_index >= terrain_sets.size()) { if (terrain_set_index < 0 || terrain_set_index >= terrain_sets.size()) {
@ -1146,7 +1146,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
} else if (components[1] == "terrains_count") { } else if (components[1] == "terrains_count") {
r_ret = get_terrains_count(terrain_set_index); r_ret = get_terrains_count(terrain_set_index);
return true; return true;
} else if (components.size() >= 3 && components[1].begins_with("terrain_") && components[1].trim_prefix("terrain_").is_valid_integer()) { } else if (components.size() >= 3 && components[1].begins_with("terrain_") && components[1].trim_prefix("terrain_").is_valid_int()) {
int terrain_index = components[1].trim_prefix("terrain_").to_int(); int terrain_index = components[1].trim_prefix("terrain_").to_int();
if (terrain_index < 0 || terrain_index >= terrain_sets[terrain_set_index].terrains.size()) { if (terrain_index < 0 || terrain_index >= terrain_sets[terrain_set_index].terrains.size()) {
return false; return false;
@ -1159,7 +1159,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
return true; return true;
} }
} }
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// navigation layers. // navigation layers.
int index = components[0].trim_prefix("navigation_layer_").to_int(); int index = components[0].trim_prefix("navigation_layer_").to_int();
if (index < 0 || index >= navigation_layers.size()) { if (index < 0 || index >= navigation_layers.size()) {
@ -1169,7 +1169,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_navigation_layer_layers(index); r_ret = get_navigation_layer_layers(index);
return true; return true;
} }
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
// Custom data layers. // Custom data layers.
int index = components[0].trim_prefix("custom_data_layer_").to_int(); int index = components[0].trim_prefix("custom_data_layer_").to_int();
if (index < 0 || index >= custom_data_layers.size()) { if (index < 0 || index >= custom_data_layers.size()) {
@ -1182,7 +1182,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_custom_data_type(index); r_ret = get_custom_data_type(index);
return true; return true;
} }
} else if (components.size() == 2 && components[0] == "sources" && components[1].is_valid_integer()) { } else if (components.size() == 2 && components[0] == "sources" && components[1].is_valid_int()) {
// Atlases data. // Atlases data.
int source_id = components[1].to_int(); int source_id = components[1].to_int();
@ -1534,7 +1534,7 @@ bool TileSetAtlasSource::_set(const StringName &p_name, const Variant &p_value)
// Compute the vector2i if we have coordinates. // Compute the vector2i if we have coordinates.
Vector<String> coords_split = components[0].split(":"); Vector<String> coords_split = components[0].split(":");
Vector2i coords = TileSetSource::INVALID_ATLAS_COORDS; Vector2i coords = TileSetSource::INVALID_ATLAS_COORDS;
if (coords_split.size() == 2 && coords_split[0].is_valid_integer() && coords_split[1].is_valid_integer()) { if (coords_split.size() == 2 && coords_split[0].is_valid_int() && coords_split[1].is_valid_int()) {
coords = Vector2i(coords_split[0].to_int(), coords_split[1].to_int()); coords = Vector2i(coords_split[0].to_int(), coords_split[1].to_int());
} }
@ -1550,7 +1550,7 @@ bool TileSetAtlasSource::_set(const StringName &p_name, const Variant &p_value)
move_tile_in_atlas(coords, coords, p_value); move_tile_in_atlas(coords, coords, p_value);
} else if (components[1] == "next_alternative_id") { } else if (components[1] == "next_alternative_id") {
tiles[coords].next_alternative_id = p_value; tiles[coords].next_alternative_id = p_value;
} else if (components[1].is_valid_integer()) { } else if (components[1].is_valid_int()) {
int alternative_id = components[1].to_int(); int alternative_id = components[1].to_int();
if (alternative_id != TileSetSource::INVALID_TILE_ALTERNATIVE) { if (alternative_id != TileSetSource::INVALID_TILE_ALTERNATIVE) {
// Create the alternative if needed ? // Create the alternative if needed ?
@ -1584,7 +1584,7 @@ bool TileSetAtlasSource::_get(const StringName &p_name, Variant &r_ret) const {
// Properties. // Properties.
Vector<String> coords_split = components[0].split(":"); Vector<String> coords_split = components[0].split(":");
if (coords_split.size() == 2 && coords_split[0].is_valid_integer() && coords_split[1].is_valid_integer()) { if (coords_split.size() == 2 && coords_split[0].is_valid_int() && coords_split[1].is_valid_int()) {
Vector2i coords = Vector2i(coords_split[0].to_int(), coords_split[1].to_int()); Vector2i coords = Vector2i(coords_split[0].to_int(), coords_split[1].to_int());
if (tiles.has(coords)) { if (tiles.has(coords)) {
if (components.size() >= 2) { if (components.size() >= 2) {
@ -1595,7 +1595,7 @@ bool TileSetAtlasSource::_get(const StringName &p_name, Variant &r_ret) const {
} else if (components[1] == "next_alternative_id") { } else if (components[1] == "next_alternative_id") {
r_ret = tiles[coords].next_alternative_id; r_ret = tiles[coords].next_alternative_id;
return true; return true;
} else if (components[1].is_valid_integer()) { } else if (components[1].is_valid_int()) {
int alternative_id = components[1].to_int(); int alternative_id = components[1].to_int();
if (alternative_id != TileSetSource::INVALID_TILE_ALTERNATIVE && tiles[coords].alternatives.has(alternative_id)) { if (alternative_id != TileSetSource::INVALID_TILE_ALTERNATIVE && tiles[coords].alternatives.has(alternative_id)) {
if (components.size() >= 3) { if (components.size() >= 3) {
@ -2160,7 +2160,7 @@ int TileSetScenesCollectionSource::get_next_scene_tile_id() const {
bool TileSetScenesCollectionSource::_set(const StringName &p_name, const Variant &p_value) { bool TileSetScenesCollectionSource::_set(const StringName &p_name, const Variant &p_value) {
Vector<String> components = String(p_name).split("/", true, 2); Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() >= 2 && components[0] == "scenes" && components[1].is_valid_integer()) { if (components.size() >= 2 && components[0] == "scenes" && components[1].is_valid_int()) {
int scene_id = components[1].to_int(); int scene_id = components[1].to_int();
if (components.size() >= 3 && components[2] == "scene") { if (components.size() >= 3 && components[2] == "scene") {
if (has_scene_tile_id(scene_id)) { if (has_scene_tile_id(scene_id)) {
@ -2184,7 +2184,7 @@ bool TileSetScenesCollectionSource::_set(const StringName &p_name, const Variant
bool TileSetScenesCollectionSource::_get(const StringName &p_name, Variant &r_ret) const { bool TileSetScenesCollectionSource::_get(const StringName &p_name, Variant &r_ret) const {
Vector<String> components = String(p_name).split("/", true, 2); Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() >= 2 && components[0] == "scenes" && components[1].is_valid_integer() && scenes.has(components[1].to_int())) { if (components.size() >= 2 && components[0] == "scenes" && components[1].is_valid_int() && scenes.has(components[1].to_int())) {
if (components.size() >= 3 && components[2] == "scene") { if (components.size() >= 3 && components[2] == "scene") {
r_ret = scenes[components[1].to_int()].scene; r_ret = scenes[components[1].to_int()].scene;
return true; return true;
@ -2526,7 +2526,7 @@ Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const {
bool TileData::_set(const StringName &p_name, const Variant &p_value) { bool TileData::_set(const StringName &p_name, const Variant &p_value) {
Vector<String> components = String(p_name).split("/", true, 2); Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_integer()) { if (components.size() == 2 && components[0].begins_with("occlusion_layer_") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
// Occlusion layers. // Occlusion layers.
int layer_index = components[0].trim_prefix("occlusion_layer_").to_int(); int layer_index = components[0].trim_prefix("occlusion_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2546,7 +2546,7 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
set_occluder(layer_index, polygon); set_occluder(layer_index, polygon);
return true; return true;
} }
} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_integer()) { } else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int(); int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2564,7 +2564,7 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
} }
set_collision_shapes_count(layer_index, p_value); set_collision_shapes_count(layer_index, p_value);
return true; return true;
} else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_integer()) { } else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_int()) {
int shape_index = components[1].trim_prefix("shape_").to_int(); int shape_index = components[1].trim_prefix("shape_").to_int();
ERR_FAIL_COND_V(shape_index < 0, false); ERR_FAIL_COND_V(shape_index < 0, false);
@ -2593,7 +2593,7 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return true; return true;
} }
} }
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// Navigation layers. // Navigation layers.
int layer_index = components[0].trim_prefix("navigation_layer_").to_int(); int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2651,7 +2651,7 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return false; return false;
} }
return true; return true;
} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_integer()) { } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
// Custom data layers. // Custom data layers.
int layer_index = components[0].trim_prefix("custom_data_").to_int(); int layer_index = components[0].trim_prefix("custom_data_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2675,7 +2675,7 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
Vector<String> components = String(p_name).split("/", true, 2); Vector<String> components = String(p_name).split("/", true, 2);
if (tile_set) { if (tile_set) {
if (components.size() == 2 && components[0].begins_with("occlusion_layer") && components[0].trim_prefix("occlusion_layer_").is_valid_integer()) { if (components.size() == 2 && components[0].begins_with("occlusion_layer") && components[0].trim_prefix("occlusion_layer_").is_valid_int()) {
// Occlusion layers. // Occlusion layers.
int layer_index = components[0].trim_prefix("occlusion_layer_").to_int(); int layer_index = components[0].trim_prefix("occlusion_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2686,7 +2686,7 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_occluder(layer_index); r_ret = get_occluder(layer_index);
return true; return true;
} }
} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_integer()) { } else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers. // Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int(); int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2696,7 +2696,7 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
if (components.size() == 2 && components[1] == "shapes_count") { if (components.size() == 2 && components[1] == "shapes_count") {
r_ret = get_collision_shapes_count(layer_index); r_ret = get_collision_shapes_count(layer_index);
return true; return true;
} else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_integer()) { } else if (components.size() == 3 && components[1].begins_with("shape_") && components[1].trim_prefix("shape_").is_valid_int()) {
int shape_index = components[1].trim_prefix("shape_").to_int(); int shape_index = components[1].trim_prefix("shape_").to_int();
ERR_FAIL_COND_V(shape_index < 0, false); ERR_FAIL_COND_V(shape_index < 0, false);
if (shape_index >= physics[layer_index].shapes.size()) { if (shape_index >= physics[layer_index].shapes.size()) {
@ -2751,7 +2751,7 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
return false; return false;
} }
return true; return true;
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_integer()) { } else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// Occlusion layers. // Occlusion layers.
int layer_index = components[0].trim_prefix("navigation_layer_").to_int(); int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);
@ -2762,7 +2762,7 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_navigation_polygon(layer_index); r_ret = get_navigation_polygon(layer_index);
return true; return true;
} }
} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_integer()) { } else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
// Custom data layers. // Custom data layers.
int layer_index = components[0].trim_prefix("custom_data_").to_int(); int layer_index = components[0].trim_prefix("custom_data_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false); ERR_FAIL_COND_V(layer_index < 0, false);

View file

@ -631,7 +631,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
if (!_is_number(last_char)) { if (!_is_number(last_char)) {
return _make_token(TK_ERROR, "Invalid (integer) numeric constant"); return _make_token(TK_ERROR, "Invalid (integer) numeric constant");
} }
if (!str.is_valid_integer()) { if (!str.is_valid_int()) {
return _make_token(TK_ERROR, "Invalid numeric constant"); return _make_token(TK_ERROR, "Invalid numeric constant");
} }
} }

View file

@ -1317,7 +1317,7 @@ TEST_CASE("[String] Is_*") {
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
String s = String(data[i]); String s = String(data[i]);
CHECK(s.is_numeric() == isnum[i]); CHECK(s.is_numeric() == isnum[i]);
CHECK(s.is_valid_integer() == isint[i]); CHECK(s.is_valid_int() == isint[i]);
CHECK(s.is_valid_hex_number(false) == ishex[i]); CHECK(s.is_valid_hex_number(false) == ishex[i]);
CHECK(s.is_valid_hex_number(true) == ishex_p[i]); CHECK(s.is_valid_hex_number(true) == ishex_p[i]);
CHECK(s.is_valid_float() == isflt[i]); CHECK(s.is_valid_float() == isflt[i]);