Commit 1dbda4bf38d22df0959b4478203637d2d99e92e4

Authored by Cédric RICARD
1 parent 4504033e

- new functions datef_dmy() and dhour_format()

- new function hexadecimal_scan()
- string:percentage() function now uses point instead of comma
anubis_dev/library/locale/L3LanguageInfo.anubis
... ... @@ -20,21 +20,27 @@ public type L3LanguageInfo:
20 20  
21 21  
22 22  
23   -public define String datef_dmy ( Int dat ) =
24   - with d = convert_time(dat),
  23 +public define String datef_dmy ( Date_and_Time d ) =
25 24 zero_pad_n(2,day(d))+"/"+zero_pad_n(2,month(d))+"/"+year(d).
  25 +
  26 +public define String datef_dmy ( Int dat ) =
  27 + datef_dmy(convert_time(dat) ).
26 28  
27   -public define String datef_ymd ( Int dat ) =
28   - with d = convert_time(dat),
  29 +public define String datef_ymd ( Date_and_Time d ) =
29 30 year(d)+"/"+zero_pad_n(2,month(d))+"/"+zero_pad_n(2,day(d)).
30 31  
  32 +public define String datef_ymd ( Int dat ) =
  33 + datef_ymd( convert_time(dat) ).
  34 +
31 35 public define String datee_ymd = "yyyy/mm/dd".
32 36 public define String datee_dmy = "dd/mm/yyyy".
33 37  
34 38  
35   -public define String dhour_format ( Int dat ) =
36   - with d = convert_time(dat),
  39 +public define String dhour_format ( Date_and_Time d ) =
37 40 zero_pad_n(2,hour(d))+":"+zero_pad_n(2,minute(d))+":"+zero_pad_n(2,second(d)).
  41 +
  42 +public define String dhour_format ( Int dat ) =
  43 + dhour_format( convert_time(dat) ).
38 44  
39 45  
40 46  
... ...
anubis_dev/library/system/convert.anubis
... ... @@ -293,3 +293,26 @@ public define String
293 293 to_decimal(v).
294 294  
295 295  
  296 +define Maybe(Int)
  297 + _hexadecimal_scan
  298 + (
  299 + List(Word8) str,
  300 + Int value
  301 + ) =
  302 + if str is
  303 + {
  304 + [] then success(value),
  305 + [h . t] then
  306 + if h >=+ '0' & h +=< '9' then _hexadecimal_scan(t, (value * 16) + to_Int(h - '0'))
  307 + else if h >=+ 'A' & h +=< 'F' then _hexadecimal_scan(t, (value * 16) + to_Int(h - 'A') + 10)
  308 + else if h >=+ 'a' & h +=< 'f' then _hexadecimal_scan(t, (value * 16) + to_Int(h - 'a') + 10)
  309 + else
  310 + failure
  311 + }.
  312 +
  313 +public define Maybe(Int)
  314 + hexadecimal_scan
  315 + (
  316 + String str
  317 + ) =
  318 + _hexadecimal_scan(explode(str), 0).
... ...
anubis_dev/library/system/string.anubis
... ... @@ -1027,13 +1027,13 @@ public define String
1027 1027 ) =
1028 1028 if ((10^(precision+2))*value)/reference is
1029 1029 {
1030   - failure then "0,0",
  1030 + failure then "0.0",
1031 1031 success(p) then if p is (q,r) then
1032 1032 if q/(10^precision) is
1033 1033 {
1034   - failure then "0,0",
  1034 + failure then "0.0",
1035 1035 success(p1) then if p1 is (q1,r1) then
1036   - to_decimal(q1)+","+to_decimal(r1)
  1036 + to_decimal(q1)+"."+to_decimal(r1)
1037 1037 }
1038 1038 }.
1039 1039  
... ...
anubis_dev/library/test/system/convert.unit_test.anubis
... ... @@ -93,7 +93,13 @@ define One
93 93  
94 94 unique.
95 95  
96   -
  96 +define One
  97 + hexadecimal_scan_test
  98 + (
  99 + UnitTestContext ut
  100 + ) =
  101 + assertIsSuccess(ut, hexadecimal_scan("123ABC"), to_Int((Word32)0x123ABC), abs_to_hexa, "Test 1");
  102 + unique.
97 103  
98 104  
99 105 public define UnitTestSuite make_convert_test_suite
... ... @@ -104,4 +110,5 @@ public define UnitTestSuite make_convert_test_suite
104 110 ut_fixture("Host to Big Endian", host_to_bendian_test),
105 111 //ut_fixture("Host to Little Endian", host_to_lendian_test),
106 112 //ut_fixture("Host to Little Endian (IntXX)", host_to_lendian_intxx_test),
  113 + ut_fixture("hexadecimal_scan", hexadecimal_scan_test),
107 114 ]).
... ...