add morphisms
- unicode - value delimited seq - zigzag encoding (still lacking any way to get to signed integer yet'..)
This commit is contained in:
parent
630948139b
commit
d0118b56b1
3 changed files with 190 additions and 0 deletions
morphisms
71
morphisms/value_delim.morphism-base
Normal file
71
morphisms/value_delim.morphism-base
Normal file
|
@ -0,0 +1,71 @@
|
|||
```
|
||||
#include <array/length-prefix.h>
|
||||
#include <stdlib.h>
|
||||
```
|
||||
|
||||
morph_seqseq_valsep_uint8 (T: Type, SrcDelim: T, DstDelim: T)
|
||||
< Seq <Seq T> >
|
||||
~ < ValueSep SrcDelim T >
|
||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
||||
|
||||
--> < Seq <Seq T> >
|
||||
~ < ValueSep DstDelim T >
|
||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
||||
```
|
||||
length_prefix_uint8_array_clear( dst );
|
||||
|
||||
uint8_t * dst_items = dst->items;
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
if( src->items[i] == SrcDelim ) {
|
||||
length_prefix_uint8_array_push( dst, DstDelim );
|
||||
} else if( src->items[i] == DstDelim ) {
|
||||
if( DstDelim == '\n' ) {
|
||||
length_prefix_uint8_array_push( dst, '\\' );
|
||||
length_prefix_uint8_array_push( dst, 'n' );
|
||||
}
|
||||
} else {
|
||||
length_prefix_uint8_array_push( dst, src->items[i] );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
```
|
||||
|
||||
|
||||
morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
||||
< Seq <Seq T> >
|
||||
~ < ValueSep T Delim >
|
||||
~ < Seq~<LengthPrefix x86.UInt64> T >
|
||||
|
||||
--> < Seq~<LengthPrefix x86.UInt64>
|
||||
<Seq~<LengthPrefix x86.UInt64> T >
|
||||
~ <RefMut < Seq~<LengthPrefix x86.UInt64> T>>
|
||||
~ x86.Address
|
||||
~ x86.UInt64
|
||||
>
|
||||
```
|
||||
length_prefix_uint64_array_clear( dst );
|
||||
|
||||
struct LengthPrefixUInt8Array * cur_item = NULL;
|
||||
|
||||
uint8_t const * start = &src->items[0];
|
||||
uint8_t const * cur = start;
|
||||
uint8_t const * end = &src->items[src->len];
|
||||
|
||||
while( cur < end ) {
|
||||
if( *cur == Delim || cur+1 == end ) {
|
||||
uint64_t len = cur - start;
|
||||
|
||||
cur_item = malloc( sizeof(uint64_t) + sizeof(uint8_t) * len );
|
||||
cur_item->len = len;
|
||||
memcpy( cur_item->items, start, len );
|
||||
|
||||
length_prefix_uint64_array_push( dst, (uint64_t)cur_item );
|
||||
start = ++cur;
|
||||
} else {
|
||||
cur++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue