Skip to content

Commit

Permalink
array library
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Nov 28, 2023
1 parent d2a0a44 commit c00a3bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/data/repository.vala
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ public string[] list_available_packages () {
//DOC: `string create_index_data (string fpath):`
//DOC: generate remote repository index data
public string create_index_data (string fpath) {
StringBuilder index_builder = new StringBuilder();
index_builder.append("index:\n");
array a = new array();
a.add("index:\n");
string md5sum = "";
int size=0;
string path = srealpath (fpath);
Expand All @@ -341,7 +341,7 @@ public string create_index_data (string fpath) {
}
var tar = new archive ();
var yaml = new yamlfile ();
index_builder.append(" name: %s\n".printf(index_name));
a.add(" name: %s\n".printf(index_name));
foreach (string file in find (path)) {
if (endswith (file, ".ymp")) {
if (get_bool ("move")) {
Expand Down Expand Up @@ -402,12 +402,12 @@ public string create_index_data (string fpath) {
if (line == "" || line == null) {
continue;
}
index_builder.append(" %s\n".printf(line));
a.add(" %s\n".printf(line));
}
index_builder.append(" md5sum: %s\n".printf(md5sum));
index_builder.append(" size: %s\n".printf(size.to_string ()));
index_builder.append(" uri: %s\n\n".printf(file));
a.add(" md5sum: %s\n".printf(md5sum));
a.add(" size: %s\n".printf(size.to_string ()));
a.add(" uri: %s\n\n".printf(file));
}
}
return index_builder.str;
return a.get_string();
}
14 changes: 8 additions & 6 deletions src/util/file.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public string readfile_byte (string path, long n) {
//DOC: read file from **path** and remove commends
public string readfile (string path) {
debug (_ ("Read file: %s").printf (path));
string new_data = "";
if (!isfile (path)) {
return new_data;
return "";
}
string data = readfile_raw (path);
if (data.length == 0) {
return new_data;
return "";
}
array a = new array();
debug (_ ("Remove commend lines: %s").printf (path));
foreach (string line in ssplit (data, "\n")) {
if ("#" in line) {
Expand All @@ -55,15 +55,17 @@ public string readfile (string path) {
}
line = ssplit (line, "#")[0];
if (line.strip () != "") {
new_data += line + "\n";
a.add(line);
a.add("\n");
}
}else {
if (line.length > 0) {
new_data += line + "\n";
a.add(line);
a.add("\n");
}
}
}
return new_data;
return a.get_string();
}

//DOC: `string safedir (string dir):`
Expand Down
5 changes: 3 additions & 2 deletions src/util/yamlparser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class yamlfile {
//DOC: Yaml file content
public string data;
private int offset = 0;
private StringBuilder area_builder;


//DOC: `void yamlfile.load (string path):`
Expand Down Expand Up @@ -53,7 +54,7 @@ public class yamlfile {
debug (_ ("Get area list: %s").printf (path));
string[] ret = {};
bool e=false;
StringBuilder area_builder = new StringBuilder();
area_builder = new StringBuilder();
foreach (string line in ssplit (fdata, "\n")) {
if (!startswith (line, " ") && ":" in line) {
string name = ssplit (line, ":")[0];
Expand Down Expand Up @@ -163,7 +164,7 @@ public class yamlfile {
}

bool e = false;
StringBuilder area_builder = new StringBuilder();
area_builder = new StringBuilder();
int i = 0;

string[] lines = ssplit(fdata, "\n");
Expand Down

0 comments on commit c00a3bb

Please sign in to comment.