From: Rico Tzschichholz Date: Mon, 12 Jun 2023 13:13:15 +0000 (+0200) Subject: vala: Add MarkupReader.has_attribute() helper and use it accordingly X-Git-Tag: 0.56.11~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec39b86f902bd92063c43773301af0a6a250cb19;p=thirdparty%2Fvala.git vala: Add MarkupReader.has_attribute() helper and use it accordingly --- diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 3703b6f51..a00042d0b 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -2279,7 +2279,7 @@ public class Vala.GirParser : CodeVisitor { parse_enumeration (); } } else { - if ((reader.get_attribute ("glib:error-quark") != null) || (reader.get_attribute ("glib:error-domain") != null)) { + if (reader.has_attribute ("glib:error-quark") || reader.has_attribute ("glib:error-domain")) { parse_error_domain (); } else { parse_enumeration (); @@ -2303,7 +2303,7 @@ public class Vala.GirParser : CodeVisitor { } else if (element_get_type_id () != null) { parse_boxed ("record"); } else if (!reader.get_attribute ("name").has_suffix ("Private")) { - if (reader.get_attribute ("glib:is-gtype-struct-for") == null && reader.get_attribute ("disguised") == "1") { + if (!reader.has_attribute ("glib:is-gtype-struct-for") && reader.get_attribute ("disguised") == "1") { parse_boxed ("record"); } else { parse_record (); @@ -2725,12 +2725,12 @@ public class Vala.GirParser : CodeVisitor { var src = get_current_src (); if (type_name == null) { - if (reader.get_attribute ("length") != null) { + if (reader.has_attribute ("length")) { array_length_idx = int.parse (reader.get_attribute ("length")); no_array_length = false; array_null_terminated = false; } - if (reader.get_attribute ("fixed-size") != null) { + if (reader.has_attribute ("fixed-size")) { fixed_length = int.parse (reader.get_attribute ("fixed-size")); array_null_terminated = false; } @@ -2738,7 +2738,7 @@ public class Vala.GirParser : CodeVisitor { no_array_length = true; array_null_terminated = true; } - if (reader.get_attribute ("zero-terminated") != null) { + if (reader.has_attribute ("zero-terminated")) { array_null_terminated = int.parse (reader.get_attribute ("zero-terminated")) != 0; } next (); diff --git a/vala/valamarkupreader.vala b/vala/valamarkupreader.vala index e8e858910..3ad25e045 100644 --- a/vala/valamarkupreader.vala +++ b/vala/valamarkupreader.vala @@ -73,6 +73,10 @@ public class Vala.MarkupReader { column = 1; } + public bool has_attribute (string attr) { + return attributes.contains (attr); + } + public string? get_attribute (string attr) { return attributes[attr]; }