/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/utils/utils.vala

  • Committer: Gustav Hartvigsson
  • Date: 2023-05-02 12:10:44 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20230502121044-iw02t7e85jsnm1yy
* Fixed up Utils.collect_string, added seperator argument.
* added cnames to the functions missing that in in utils.vala

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
namespace Utils {
8
8
  // int32 is missinng the abs method. This will have to do for the time being.
9
9
  // BUG: https://gitlab.gnome.org/GNOME/vala/-/issues/1328
 
10
  [CCode (cname = "v_int32_abs")]
10
11
  static int32 int32_abs (int32 N) { return ((N < 0) ? ( -N ) : (N)); }
11
12
 
12
13
  [CCode (cname = "v_str_cmp")]
35
36
     return strbldr.str;
36
37
  }
37
38
 
38
 
  string collect_string (string[] segments) {
39
 
    if (segments.length == 0) {
 
39
  [CCode (cname = "v_collect_string")]
 
40
  string collect_string (string[] segments, string? separator = null) {
 
41
    var _len = segments.length;
 
42
    if (_len == 0) {
40
43
      return "";
41
44
    }
42
 
    if (segments.length == 1) {
 
45
    if (_len == 1) {
43
46
      return segments[0];
44
47
    }
45
48
    StringBuilder strbldr = new StringBuilder ();
46
 
    foreach (var segment in segments) {
47
 
      strbldr.append (segment);
48
 
    }
 
49
    if (separator != null) {
 
50
      for (var i = 0; i <= _len; i++) {
 
51
        strbldr.append (segments[i]);
 
52
        if (i < _len) {
 
53
          strbldr.append (separator);
 
54
        }
 
55
      }
 
56
    } else {
 
57
      for (var i = 0; i <= _len; i++) {
 
58
        strbldr.append (segments[i]);
 
59
      }
 
60
    } 
49
61
    return strbldr.str;
50
62
  }
51
63
 
90
102
                 .append (prop_name)
91
103
                 .append (":");
92
104
 
93
 
 
94
 
      
95
 
      
96
105
      switch (prop_val.type ()) {
97
106
        case (GLib.Type.STRING):
98
107
          if (prop_val.dup_string () == null) {