summaryrefslogtreecommitdiffstats
path: root/src/Util.vala
blob: b33cb5f322024dd698b49e8079067a20d8983911 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace Eva {
  private string binary_to_string(uchar* array, ulong len) {
    string ret = "";
    
    for(ulong i = 0; i < len; ++i) {
      if(array[i] == 0)
        break;
      
      string buf = string.nfill(6, 0);
      ((unichar)array[i]).to_utf8(buf);
      
      ret += buf;
    }
    
    return ret;
  }
  
  private char[]? string_to_binary(string str) {
    char[] ret = new char[str.length];
    int index = 0;
    
    for(unowned string rest = str; rest.length > 0; rest = rest.next_char()) {
      unichar c = rest.get_char();
      
      if(c > 255)
        return null;
      
      ret[index++] = (char)c;
    }
    
    return ret;
  }
  
  private List string_to_list(string str) {
    if(str.length == 0) {
      return List.empty;
    }
    else {
      return new Cons(new UInt(str.get_char()), string_to_list(str.next_char()));
    }
  }
}