Skip to content

Commit

Permalink
Merge pull request #49659 from LightningAA/string-valid-integer-to-int
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jun 18, 2021
2 parents 98b5280 + b6af2a2 commit 92f20fd
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r
// Port
if (base.begins_with(":")) {
base = base.substr(1, base.length() - 1);
if (!base.is_valid_integer()) {
if (!base.is_valid_int()) {
return ERR_INVALID_PARAMETER;
}
r_port = base.to_int();
Expand Down Expand Up @@ -4168,7 +4168,7 @@ String String::trim_suffix(const String &p_suffix) const {
return s;
}

bool String::is_valid_integer() const {
bool String::is_valid_int() const {
int len = length();

if (len == 0) {
Expand Down Expand Up @@ -4393,7 +4393,7 @@ bool String::is_valid_ip_address() const {
}
for (int i = 0; i < ip.size(); i++) {
String n = ip[i];
if (!n.is_valid_integer()) {
if (!n.is_valid_int()) {
return false;
}
int val = n.to_int();
Expand Down
2 changes: 1 addition & 1 deletion core/string/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class String {
String validate_node_name() const;

bool is_valid_identifier() const;
bool is_valid_integer() const;
bool is_valid_int() const;
bool is_valid_float() const;
bool is_valid_hex_number(bool p_with_prefix) const;
bool is_valid_html_color() const;
Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ static void _register_variant_builtin_methods() {
bind_method(String, validate_node_name, 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_hex_number, sarray("with_prefix"), varray(false));
bind_method(String, is_valid_html_color, sarray(), varray());
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/String.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</description>
</method>
<method name="is_valid_integer" qualifiers="const">
<method name="is_valid_int" qualifiers="const">
<return type="bool">
</return>
<description>
Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/tiles/tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Tra
ERR_FAIL_COND(!tile_data);

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();
if (occlusion_layer >= 0 && occlusion_layer < p_tile_set->get_occlusion_layers_count()) {
// Draw all shapes.
Expand All @@ -158,7 +158,7 @@ void TileDataCollisionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Tra
ERR_FAIL_COND(!tile_data);

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();
if (physics_layer >= 0 && physics_layer < p_tile_set->get_physics_layers_count()) {
// Draw all shapes.
Expand Down Expand Up @@ -190,7 +190,7 @@ void TileDataNavigationPolygonEditor::draw_over_tile(CanvasItem *p_canvas_item,
ERR_FAIL_COND(!tile_data);

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();
if (navigation_layer >= 0 && navigation_layer < p_tile_set->get_navigation_layers_count()) {
// Draw all shapes.
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/tiles/tile_set_atlas_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ Map<Vector2i, List<const PropertyInfo *>> TileSetAtlasSourceEditor::_group_prope
Vector<String> components = String(E_property->get().name).split("/", true, 1);
if (components.size() >= 1) {
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());
per_tile[coords].push_back(&(E_property->get()));
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ void TileSetAtlasSourceEditor::_menu_option(int p_option) {
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()) {
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;
Variant value = tile_set_atlas_source->get(property);
if (value.get_type() != Variant::NIL) {
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/tiles/tile_set_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
(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_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] == "mode") ||
(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");
if (tile_data->is_valid_peering_bit_terrain(TileSet::CELL_NEIGHBOR_RIGHT_SIDE)) {
ADD_UNDO(tile_data, "terrains_peering_bit/right_side");
Expand Down Expand Up @@ -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));
}
}
} 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") {
int 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() && components[1] == "type") {
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));
}
}
Expand Down
Loading

0 comments on commit 92f20fd

Please sign in to comment.