From 56194669959fc4baf3f6a4870bbc161cc50b463b Mon Sep 17 00:00:00 2001 From: David René Date: Wed, 18 Apr 2007 19:44:25 +0000 Subject: [PATCH] no message --- anubis_dev/library/system/muscle.anubis | 20 ++++++++++++++------ anubis_dev/library/system/string.anubis | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- anubis_dev/library/tools/findstring.anubis | 31 +++++++++++++++++++++++++++---- 3 files changed, 135 insertions(+), 11 deletions(-) diff --git a/anubis_dev/library/system/muscle.anubis b/anubis_dev/library/system/muscle.anubis index 506179c..39d1b98 100644 --- a/anubis_dev/library/system/muscle.anubis +++ b/anubis_dev/library/system/muscle.anubis @@ -33,6 +33,7 @@ public type Message:... public define Maybe(Message) unflatten_message ( Data_IO io ). public define Maybe(ByteArray) flatten_message ( Message msg ). + public type Message_Send_Result: flatten_error, network_error, @@ -88,7 +89,16 @@ public type Message: Var(Int32) numField, Var(List(Message_field)) fields ). - + + + /** Create an empty message with only his what code */ +public define Message + message + ( + Int32 what + )= + message(var(what), var(0), var([ ])). + define Int32 get_Int32_type_code ( @@ -638,7 +648,6 @@ define Maybe(Message_field) { failure then failure, success(nb_items) then - print("nb_items" + nb_items + "\n"); if read_field_items(source, type_code, nb_items) is { failure then failure, @@ -651,7 +660,6 @@ define Maybe(Message_field) { failure then failure, success(nb_items) then - print("nb_items custom " + nb_items + "\n"); if read_field_items(source, type_code, nb_items) is { failure then failure, @@ -891,13 +899,12 @@ define Maybe(Message) failure then failure, success(protocolVersion) then if protocolVersion = _CURRENT_PROTOCOL_VERSION then - print("CURRENT_PROTOCOL_VERSION OK\n"); //get the 'what' code if read_Int32(io) is { failure then failure, success(what_code) then - print("what code = [" + to_ascii(what_code) + "] "+ what_code + "\n"); + print("what code = [" + to_ascii(what_code) + "] 0x"+ to_hexa(what_code) + " " + what_code + "\n"); //get the number of entries at this level if read_Int32(io) is { @@ -971,7 +978,8 @@ define Maybe(Muscle_object) /********************** Add collection ********************/ - /** Generic method, capable of adding any type of data to the Message. + /** @fn add_data + * Generic method, capable of adding any type of data to the Message. * @param message The message where the data to be add * @param field_name Name of the field to add (or add to) * @param type_code The _B_*_TYPE code indicating the type of data that will be added. diff --git a/anubis_dev/library/system/string.anubis b/anubis_dev/library/system/string.anubis index f8cbfd5..a65a9e5 100644 --- a/anubis_dev/library/system/string.anubis +++ b/anubis_dev/library/system/string.anubis @@ -278,8 +278,98 @@ public define Maybe(String) success(position) then sub_string(email, position+1, length(email) - (position+1)) }. + +define List(String) + split_by_token + ( + List(Word8) line, + Word8 token, + List(Word8) current, + List(String) so_far + ) = + if line is + { + [] then + if length(current) > 0 then + reverse([ implode(reverse(current)) . so_far]) + else + reverse(so_far), + [ char . t ] then + if char = token then + split_by_token( t, token, [], [ implode(reverse(current)) . so_far]) + else + split_by_token( t, token, [ char . current ], so_far) + }. + +public define List(String) + split_by_token + ( + String line, + Word8 token + )= + split_by_token(explode(line), token, [], []). - +define (Int32, Int32) + trim + ( + List(Word8) left, + Word8 token, + Int32 start, + Int32 last_char, + Int32 current + )= + if left is + { + [] then (start, last_char), + [h . t] then + if h = token then + trim(t, token, start, last_char, current + 1) + else + trim(t, token, start, current + 1, current + 1) + }. + +define (Int32, Int32) + trim + ( + List(Word8) string, + Word8 token, + Int32 current + )= + if string is + { + [] then (0, 0), + [ h . t ] then + if h = token then + trim(t, token, current + 1) + else + trim(t, token, current, 1, 1) + }. + +public define String + trim + ( + String string + )= + if trim(explode(string), ' ', 0) is (start, length) then + if sub_string(string, start, length) is + { + failure then "", + success(s) then s + }. + +public define String + trim_token + ( + String string, + Word8 token + )= + if trim(explode(string), token, 0) is (start, length) then + if sub_string(string, start, length) is + { + failure then "", + success(s) then s + }. + public define String append ( @@ -302,6 +392,9 @@ public define String [h . t] then h+append(t) }. + + // *** COMPARISON + define Bool insensitive_equal ( diff --git a/anubis_dev/library/tools/findstring.anubis b/anubis_dev/library/tools/findstring.anubis index 19d67d2..24b9ccb 100644 --- a/anubis_dev/library/tools/findstring.anubis +++ b/anubis_dev/library/tools/findstring.anubis @@ -1,4 +1,4 @@ - + *Project* The Anubis Project *Title* Finding a substring in a string. @@ -36,7 +36,14 @@ public define Maybe(Int32) Int32 n ). - + return true if the string 'a' start with the string 'b' + +public define Bool + start_with + ( + String a, + String b + ). It also defines 'find_all': @@ -210,7 +217,23 @@ public define List(Int32) ) = find_all(t,s,0,[]). - + +public define Bool + start_with + ( + String a, + String pattern + )= + with pattern_len = length(pattern), + if sub_string(a, 0, pattern_len) is + { + failure then false, + success(start) then + if start = pattern then + true + else + false + }. -------------------------------------------------------------------------------- @@ -240,4 +263,4 @@ public define List(Int32) print(find_all(t,s)). - \ No newline at end of file + -- libgit2 0.21.4