Hi,
Przemyslaw Czerpak wrote:
There are also some small differences to original print behavior, f.e.:
%012d in C printf() is 0 padded 12 length 'd' formatting and in this code
it's parameter 12-th 'd' formatting.
Can you give an error example? I'm unable to find the bug. I get correct
result for:
? HB_SPRINTF( "[%012d]", 123 ) // [000000000123]
I also do not see support for string
cutting, f.e.:
printf( "[%.3s]", "ABCDEF" );
Thanks! I'll fix it. I was using the first google link for printf()
reference and some tests on linux's printf() function, but I did not
know the meaning of "." for strings. I'll try to use a better docs to
know details better.
If the formatting will be C compatible then I vote for HB_SPRINTF()
otherwise HB_STRFORMAT().
I see full C compatibility is not possible due Harbour language nature,
so, let's call it HB_STRFORMAT().
Month ago I crated for my friend sprintf() implementation to use in embedded
system. It should be fully ANSI C compatible though some things like double
, long long support or positional parameters can be disabled to reduce the
code size, external dependencies and memory/stack usage and such reduced
version is used.
If does not support A, a, E, e, G, g conversions and simply redirect them
to F or f and conversions which needs locale setting. See notes in the code.
They were not necessary in this project and also they are not necessary for
us.
Now this code is strongly GCC related and will have to be updated for
other compilers but it can be easy done and it can be used as our own
hb_snprintf() implementation (of course I'll update copyright notice).
I'm attaching it. It should quite well show how different flags are
interpreted and their precedence in different conversions.
I'll still a little confused on functionality of Harbour's formats
itself. Should we support argument length modifier (h,l,L) because
Harbour has argument length determined by item structure, etc. Anyone's
ideas are welcome.
You've proposed rc_snprintf(). Do you mean HB_STRFORMAT() should use
original C s[n]printf() function, thus making it's output more C
compatible, but possibly STR() incompatible for rounding errors, etc?
I've used hb_itemStrBuf() to avoid incompatible results for STR(nValue,
20, 10) and HB_STRFORMAT("%20.10f", nValue).
Best regards,
Mindaugas
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour