From 94d0ce9c2d2c06def54ab5071a66711b4da4b342 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Thu, 26 Dec 2024 00:45:53 +0800 Subject: [PATCH] :memo: format --- std/csv.nas | 10 +++++----- std/file.nas | 24 +++++++++++------------- std/queue.nas | 24 ++++++++++++------------ std/stack.nas | 4 ++-- std/string.nas | 6 ++++-- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/std/csv.nas b/std/csv.nas index c2d843d..d6edac4 100644 --- a/std/csv.nas +++ b/std/csv.nas @@ -2,14 +2,14 @@ # ValKmjolnir 2022/10/15 use std.io; -var read = func(path, delimeter=",", endline="\n") { +var read = func(path, delimeter = ",", endline = "\n") { var context = io.readfile(path); context = split(endline, context); - forindex(var i;context) { - context[i] = split(delimeter,context[i]); + forindex(var i; context) { + context[i] = split(delimeter, context[i]); } - if (size(context)<=1) { - die("incorrect csv file <"~path~">: "~size(context)~" line(s)."); + if (size(context) <= 1) { + die("incorrect csv file <" ~ path ~ ">: " ~ size(context) ~ " line(s)."); } return { property: context[0], diff --git a/std/file.nas b/std/file.nas index 1138a54..d7bf765 100644 --- a/std/file.nas +++ b/std/file.nas @@ -4,12 +4,10 @@ use std.io; use std.unix; var SEEK_SET = io.SEEK_SET; - var SEEK_CUR = io.SEEK_CUR; - var SEEK_END = io.SEEK_END; -var new = func(filename, mode="r") { +var new = func(filename, mode = "r") { if (!io.exists(filename)) { return nil; } @@ -56,7 +54,7 @@ var find_all_files = func(path) { var dd = unix.opendir(path); var res = []; while(var n = unix.readdir(dd)) { - if (unix.isfile(path~"/"~n)) { + if (unix.isfile(path ~ "/" ~ n)) { append(res, n); } } @@ -74,11 +72,11 @@ var recursive_find_files = func(path) { files: [] }; while(var n = unix.readdir(dd)) { - if (unix.isfile(path~"/"~n)) { + if (unix.isfile(path ~ "/" ~ n)) { append(res.files, n); - } elsif (unix.isdir(path~"/"~n) and n!="." and n!="..") { - var tmp = recursive_find_files(path~"/"~n); - if (tmp!=nil) { + } elsif (unix.isdir(path ~ "/" ~ n) and n != "." and n != "..") { + var tmp = recursive_find_files(path ~ "/" ~ n); + if (tmp != nil) { append(res.files, tmp); } } @@ -89,19 +87,19 @@ var recursive_find_files = func(path) { var recursive_find_files_flat = func(path) { var tree_files = recursive_find_files(path); - if (tree_files==nil) { + if (tree_files == nil) { return []; } var flat = []; var bfs = [tree_files]; - while(size(bfs)!=0) { + while(size(bfs) != 0) { var first = pop(bfs); foreach(var file_record; first.files) { if (ishash(file_record)) { append(bfs, file_record); continue; } - append(flat, first.dir~"/"~file_record); + append(flat, first.dir ~ "/" ~ file_record); } } return flat; @@ -110,7 +108,7 @@ var recursive_find_files_flat = func(path) { var recursive_find_files_with_extension = func(path, extensions...) { var in_vec = func(ext) { foreach(var i; extensions) { - if (ext==i) { + if (ext == i) { return 1; } } @@ -121,7 +119,7 @@ var recursive_find_files_with_extension = func(path, extensions...) { var res = []; foreach(var filename; files) { var tmp = split('.', filename); - if (size(tmp)>1 and in_vec(tmp[-1])) { + if (size(tmp) > 1 and in_vec(tmp[-1])) { append(res, filename); } } diff --git a/std/queue.nas b/std/queue.nas index d662e77..392600a 100644 --- a/std/queue.nas +++ b/std/queue.nas @@ -4,32 +4,32 @@ var new = func() { var (begin, end) = (nil, nil); return{ push: func(elem) { - var new_node={ + var new_node = { elem:elem, next:nil }; - if (begin==nil) - begin=end=new_node; + if (begin == nil) + begin = end = new_node; else { - end.next=new_node; - end=new_node; + end.next = new_node; + end = new_node; } }, pop: func() { - if (begin!=nil) - begin=begin.next; - if (begin==nil) - end=nil; + if (begin != nil) + begin = begin.next; + if (begin == nil) + end = nil; }, front: func() { - if (begin!=nil) + if (begin != nil) return begin.elem; }, clear: func() { - begin=end=nil; + begin = end = nil; }, empty: func() { - return begin==nil; + return begin == nil; } }; } diff --git a/std/stack.nas b/std/stack.nas index 596a603..6fc8544 100644 --- a/std/stack.nas +++ b/std/stack.nas @@ -10,7 +10,7 @@ var stack = func() { return pop(vec); }, top: func() { - if (size(vec)!=0) { + if (size(vec) != 0) { return vec[-1]; } }, @@ -18,7 +18,7 @@ var stack = func() { vec = []; }, empty: func() { - return size(vec)==0; + return size(vec) == 0; } }; } diff --git a/std/string.nas b/std/string.nas index b14d2ce..f2ab3b5 100644 --- a/std/string.nas +++ b/std/string.nas @@ -33,11 +33,13 @@ func() { }(); var to_char = func(number) { - return 0<=number and number<256? __num_to_char[number]:""; + return 0 <= number and number < 256? __num_to_char[number] : ""; } var to_num = func(character) { - return __temp_contains(__char_to_num, character)? __char_to_num[character]:-1; + return __temp_contains(__char_to_num, character) + ? __char_to_num[character] + : -1; } var __string_split_with_empty_substr = func(separator, str) {