Compare commits

...

4 commits

4 changed files with 52 additions and 5 deletions

View file

@ -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;

View 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;
```

View file

@ -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>

View file

@ -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;
```