Commit 56194669959fc4baf3f6a4870bbc161cc50b463b

Authored by David René
1 parent c08a3135

no message

anubis_dev/library/system/muscle.anubis
... ... @@ -33,6 +33,7 @@ public type Message:...
33 33 public define Maybe(Message) unflatten_message ( Data_IO io ).
34 34 public define Maybe(ByteArray) flatten_message ( Message msg ).
35 35  
  36 +
36 37 public type Message_Send_Result:
37 38 flatten_error,
38 39 network_error,
... ... @@ -88,7 +89,16 @@ public type Message:
88 89 Var(Int32) numField,
89 90 Var(List(Message_field)) fields
90 91 ).
91   -
  92 +
  93 +
  94 + /** Create an empty message with only his what code */
  95 +public define Message
  96 + message
  97 + (
  98 + Int32 what
  99 + )=
  100 + message(var(what), var(0), var([ ])).
  101 +
92 102 define Int32
93 103 get_Int32_type_code
94 104 (
... ... @@ -638,7 +648,6 @@ define Maybe(Message_field)
638 648 {
639 649 failure then failure,
640 650 success(nb_items) then
641   - print("nb_items" + nb_items + "\n");
642 651 if read_field_items(source, type_code, nb_items) is
643 652 {
644 653 failure then failure,
... ... @@ -651,7 +660,6 @@ define Maybe(Message_field)
651 660 {
652 661 failure then failure,
653 662 success(nb_items) then
654   - print("nb_items custom " + nb_items + "\n");
655 663 if read_field_items(source, type_code, nb_items) is
656 664 {
657 665 failure then failure,
... ... @@ -891,13 +899,12 @@ define Maybe(Message)
891 899 failure then failure,
892 900 success(protocolVersion) then
893 901 if protocolVersion = _CURRENT_PROTOCOL_VERSION then
894   - print("CURRENT_PROTOCOL_VERSION OK\n");
895 902 //get the 'what' code
896 903 if read_Int32(io) is
897 904 {
898 905 failure then failure,
899 906 success(what_code) then
900   - print("what code = [" + to_ascii(what_code) + "] "+ what_code + "\n");
  907 + print("what code = [" + to_ascii(what_code) + "] 0x"+ to_hexa(what_code) + " " + what_code + "\n");
901 908 //get the number of entries at this level
902 909 if read_Int32(io) is
903 910 {
... ... @@ -971,7 +978,8 @@ define Maybe(Muscle_object)
971 978  
972 979 /********************** Add collection ********************/
973 980  
974   - /** Generic method, capable of adding any type of data to the Message.
  981 + /** @fn add_data
  982 + * Generic method, capable of adding any type of data to the Message.
975 983 * @param message The message where the data to be add
976 984 * @param field_name Name of the field to add (or add to)
977 985 * @param type_code The _B_*_TYPE code indicating the type of data that will be added.
... ...
anubis_dev/library/system/string.anubis
... ... @@ -278,8 +278,98 @@ public define Maybe(String)
278 278 success(position) then sub_string(email, position+1, length(email) - (position+1))
279 279 }.
280 280  
  281 +
  282 +define List(String)
  283 + split_by_token
  284 + (
  285 + List(Word8) line,
  286 + Word8 token,
  287 + List(Word8) current,
  288 + List(String) so_far
  289 + ) =
  290 + if line is
  291 + {
  292 + [] then
  293 + if length(current) > 0 then
  294 + reverse([ implode(reverse(current)) . so_far])
  295 + else
  296 + reverse(so_far),
  297 + [ char . t ] then
  298 + if char = token then
  299 + split_by_token( t, token, [], [ implode(reverse(current)) . so_far])
  300 + else
  301 + split_by_token( t, token, [ char . current ], so_far)
  302 + }.
  303 +
  304 +public define List(String)
  305 + split_by_token
  306 + (
  307 + String line,
  308 + Word8 token
  309 + )=
  310 + split_by_token(explode(line), token, [], []).
281 311  
282   -
  312 +define (Int32, Int32)
  313 + trim
  314 + (
  315 + List(Word8) left,
  316 + Word8 token,
  317 + Int32 start,
  318 + Int32 last_char,
  319 + Int32 current
  320 + )=
  321 + if left is
  322 + {
  323 + [] then (start, last_char),
  324 + [h . t] then
  325 + if h = token then
  326 + trim(t, token, start, last_char, current + 1)
  327 + else
  328 + trim(t, token, start, current + 1, current + 1)
  329 + }.
  330 +
  331 +define (Int32, Int32)
  332 + trim
  333 + (
  334 + List(Word8) string,
  335 + Word8 token,
  336 + Int32 current
  337 + )=
  338 + if string is
  339 + {
  340 + [] then (0, 0),
  341 + [ h . t ] then
  342 + if h = token then
  343 + trim(t, token, current + 1)
  344 + else
  345 + trim(t, token, current, 1, 1)
  346 + }.
  347 +
  348 +public define String
  349 + trim
  350 + (
  351 + String string
  352 + )=
  353 + if trim(explode(string), ' ', 0) is (start, length) then
  354 + if sub_string(string, start, length) is
  355 + {
  356 + failure then "",
  357 + success(s) then s
  358 + }.
  359 +
  360 +public define String
  361 + trim_token
  362 + (
  363 + String string,
  364 + Word8 token
  365 + )=
  366 + if trim(explode(string), token, 0) is (start, length) then
  367 + if sub_string(string, start, length) is
  368 + {
  369 + failure then "",
  370 + success(s) then s
  371 + }.
  372 +
283 373 public define String
284 374 append
285 375 (
... ... @@ -302,6 +392,9 @@ public define String
302 392 [h . t] then h+append(t)
303 393 }.
304 394  
  395 +
  396 + // *** COMPARISON
  397 +
305 398 define Bool
306 399 insensitive_equal
307 400 (
... ...
anubis_dev/library/tools/findstring.anubis
1   -
  1 +
2 2 *Project* The Anubis Project
3 3  
4 4 *Title* Finding a substring in a string.
... ... @@ -36,7 +36,14 @@ public define Maybe(Int32)
36 36 Int32 n
37 37 ).
38 38  
39   -
  39 + return true if the string 'a' start with the string 'b'
  40 +
  41 +public define Bool
  42 + start_with
  43 + (
  44 + String a,
  45 + String b
  46 + ).
40 47  
41 48 It also defines 'find_all':
42 49  
... ... @@ -210,7 +217,23 @@ public define List(Int32)
210 217 ) =
211 218 find_all(t,s,0,[]).
212 219  
213   -
  220 +
  221 +public define Bool
  222 + start_with
  223 + (
  224 + String a,
  225 + String pattern
  226 + )=
  227 + with pattern_len = length(pattern),
  228 + if sub_string(a, 0, pattern_len) is
  229 + {
  230 + failure then false,
  231 + success(start) then
  232 + if start = pattern then
  233 + true
  234 + else
  235 + false
  236 + }.
214 237  
215 238  
216 239 --------------------------------------------------------------------------------
... ... @@ -240,4 +263,4 @@ public define List(Int32)
240 263 print(find_all(t,s)).
241 264  
242 265  
243   -
244 266 \ No newline at end of file
  267 +
... ...