- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
// Array below is for faster processing of variable length fields with ascii length.
// Varbuut sho var arii initcializeet dinamiski.
char an[1000][3] =
{
{'0','0','0'},{'0','0','1'},{'0','0','2'},{'0','0','3'},{'0','0','4'},{'0','0','5'},{'0','0','6'},{'0','0','7'},{'0','0','8'},{'0','0','9'},
{'0','1','0'},{'0','1','1'},{'0','1','2'},{'0','1','3'},{'0','1','4'},{'0','1','5'},{'0','1','6'},{'0','1','7'},{'0','1','8'},{'0','1','9'},
{'0','2','0'},{'0','2','1'},{'0','2','2'},{'0','2','3'},{'0','2','4'},{'0','2','5'},{'0','2','6'},{'0','2','7'},{'0','2','8'},{'0','2','9'},
{'0','3','0'},{'0','3','1'},{'0','3','2'},{'0','3','3'},{'0','3','4'},{'0','3','5'},{'0','3','6'},{'0','3','7'},{'0','3','8'},{'0','3','9'},
// 84 lines deleted
{'8','8','0'},{'8','8','1'},{'8','8','2'},{'8','8','3'},{'8','8','4'},{'8','8','5'},{'8','8','6'},{'8','8','7'},{'8','8','8'},{'8','8','9'},
{'9','0','0'},{'9','0','1'},{'9','0','2'},{'9','0','3'},{'9','0','4'},{'9','0','5'},{'9','0','6'},{'9','0','7'},{'9','0','8'},{'9','0','9'},
// 6 lines deleted
{'9','7','0'},{'9','7','1'},{'9','7','2'},{'9','7','3'},{'9','7','4'},{'9','7','5'},{'9','7','6'},{'9','7','7'},{'9','7','8'},{'9','7','9'},
{'9','8','0'},{'9','8','1'},{'9','8','2'},{'9','8','3'},{'9','8','4'},{'9','8','5'},{'9','8','6'},{'9','8','7'},{'9','8','8'},{'9','8','9'}
};
int ll = f->cfg.len_len;
long dl = f->data_len;
// Prepare length
if ( NULL == dst )
{
dst_len = f->data_len + ll + 1 ;
dst = (char*) malloc ( dst_len );
}
else
//if( dst_len < ll + dl )
if( dst_len < (unsigned) (ll + dl) )
{
// TO DOO - error should be processed
break;
}
long i2;
if ( ll < 2 )
{
dst[0]=an[dl][2];
}
else if ( ll < 3 )
{
dst[0]=an[dl][1];
dst[1]=an[dl][2];
}
else if ( ll < 4 )
{
dst[0]=an[dl][0];
dst[1]=an[dl][1];
dst[2]=an[dl][2];
}
else if ( ll < 5 )
{
i2 = dl / 1000;
dst[0]=an[i2][2];
i2 = dl % 1000;
dst[3]=an[i2][2];
dst[2]=an[i2][1];
dst[1]=an[i2][0];
}
else if ( ll < 6 )
{
i2 = dl / 1000;
dst[0]=an[i2][1];
dst[1]=an[i2][2];
i2 = dl % 1000;
dst[4]=an[i2][2];
dst[3]=an[i2][1];
dst[2]=an[i2][0];
}
else
{
// General case
for ( int k = ll ; k > 0 ; k-- )
{
dst[k-1] ='0' + dl % 10;
dl/=10;
}
}
dst[dl]=0;
This is a faster version of itoa() or sprintf(str,"%d",value)...
Unfortunately it has a bug - lines of array with numbers 890-899 and 990-999 is missing.