Compare commits
4 commits
8b8acb81a6
...
4c7302c4a3
Author | SHA1 | Date | |
---|---|---|---|
4c7302c4a3 | |||
17a1e499d8 | |||
f8725c0624 | |||
24b332c682 |
4 changed files with 52 additions and 5 deletions
|
@ -12,8 +12,10 @@ morph_digit_as_char_to_uint8 (Radix:ℤ)
|
|||
*dst = 0xa + *src - 'a';
|
||||
else if( *src >= 'A' && *src <= 'F')
|
||||
*dst = 0xa + *src - 'A';
|
||||
else
|
||||
else {
|
||||
fprintf(stderr, "invalid digit 0x%x\n", *src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( *dst < Radix ) {
|
||||
return 0;
|
||||
|
@ -33,8 +35,10 @@ morph_digit_as_char_to_uint64 (Radix:ℤ)
|
|||
*dst = 0xa + *src - 'a';
|
||||
else if( *src >= 'A' && *src <= 'F')
|
||||
*dst = 0xa + *src - 'A';
|
||||
else
|
||||
else {
|
||||
fprintf(stderr, "invalid digit 0x%x\n", *src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( *dst < Radix ) {
|
||||
return 0;
|
||||
|
|
15
morphisms/timepoint.morphism-base
Normal file
15
morphisms/timepoint.morphism-base
Normal file
|
@ -0,0 +1,15 @@
|
|||
```
|
||||
#include <time.h>
|
||||
```
|
||||
|
||||
morph_unixtime_to_iso ()
|
||||
TimePoint ~ <TimeSince UnixEpoch> ~ Duration ~ Seconds ~ ℝ ~ <QuantizedLinear 0 1 1> ~ ℕ ~ x86.UInt64
|
||||
--> TimePoint ~ ISO8601 ~ <Seq~<ValueTerminated 0> Char~Ascii~x86.UInt8>
|
||||
```
|
||||
time_t rawtime = (time_t)(*src);
|
||||
struct tm *timeinfo = gmtime(&rawtime);
|
||||
if (!timeinfo) return -1;
|
||||
|
||||
strftime((char*)dst, 20, "%Y-%m-%dT%H:%M:%SZ", timeinfo);
|
||||
return 0;
|
||||
```
|
|
@ -3,7 +3,7 @@
|
|||
```
|
||||
|
||||
morph_string_as_ascii_to_utf8 ()
|
||||
<Seq ~ <ValueTerminated '\0'> Char~Ascii~x86.UInt8>
|
||||
<Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
||||
--> <Seq Char~Unicode>
|
||||
~ UTF-8
|
||||
~ <Seq~<ValueTerminated 0> x86.UInt8>
|
||||
|
@ -17,7 +17,7 @@ morph_string_as_utf8_to_ascii ()
|
|||
<Seq Char~Unicode>
|
||||
~ UTF-8
|
||||
~ <Seq~<ValueTerminated 0> x86.UInt8>
|
||||
--> <Seq ~ <ValueTerminated '\0'> Char~Ascii~x86.UInt8>
|
||||
--> <Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
||||
```
|
||||
while( *src ) {
|
||||
if( *src < 128 ) {
|
||||
|
@ -32,7 +32,7 @@ morph_string_as_utf8_to_ascii ()
|
|||
```
|
||||
|
||||
morph_string_as_ascii_to_utf32 ()
|
||||
<Seq ~ <ValueTerminated '\0'> Char~Ascii~x86.UInt8>
|
||||
<Seq ~ <ValueTerminated 0> Char~Ascii~x86.UInt8>
|
||||
--> <Seq Char~Unicode>
|
||||
~ UTF-32LE
|
||||
~ <Seq~<ValueTerminated 0> x86.UInt32>
|
||||
|
|
|
@ -69,3 +69,31 @@ morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
|||
|
||||
return 0;
|
||||
```
|
||||
|
||||
morph_seqeq_as_lenpfx_to_valsep (T: Type, Delim: T, EscKey: T)
|
||||
< Seq~<LengthPrefix x86.UInt64>
|
||||
<Seq~<LengthPrefix x86.UInt64> T >
|
||||
~ <RefMut < Seq~<LengthPrefix x86.UInt64> T>>
|
||||
~ x86.Address
|
||||
~ x86.UInt64
|
||||
>
|
||||
--> < Seq <Seq T> >
|
||||
~ < ValueSep T Delim >
|
||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
||||
```
|
||||
length_prefix_uint8_array_clear( dst );
|
||||
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
LengthPrefixUInt8Array * item = src->items[i];
|
||||
|
||||
for( uint64_t j = 0; j < item->len; ++j ) {
|
||||
length_prefix_uint8_array_push( items->items[j] );
|
||||
}
|
||||
|
||||
if( i+1 < src->len ) {
|
||||
length_prefix_uint8_array_push( Delim );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue