d_snprintf 1.0.0
Port of C99-snprintf
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
This is a port of Holger Weiß' implementation of snprintf (available at http://www.jhweiss.de/software/snprintf.html). This version has no dependencies on other external libraries or the C standard library. It does use D's TypeInfo inorder to access varargs in a typesafe and convenient manner. All Code is nothrow and @nogc.
This library defines snprintf and vsnprintf as well as a few templates that allow you to easely define a version of (v)asprinf, (v)fprintf and (v)printf that use a specific function to allocate memory or write to a file. An example using C standard library functions:
import d_snprintf.snprintf;
import core.stdc.stdio : FILE, stdout, fwrite;
import core.stdc.stdlib : malloc;
void write_file(void* p_file, ubyte[] data) {
fwrite(data.ptr, 1, data.length, cast(FILE*)p_file);
}
void* alloc_func(size_t size) { // wrapper with D calling convention
return malloc(size);
}
alias asprintf = rpl_asprintf!alloc_func;
alias vasprintf = rpl_vasprintf!alloc_func;
int fprintf(FILE* file, string format, ...) {
mixin va_start;
return rpl_vfprintf!write_file(cast(void*)file, format, va_args);
}
int vfprintf(FILE* file, string format, va_list ap) {
return rpl_vfprintf!write_file(cast(void*)file, format, ap);
}
int printf(string format, ...) {
mixin va_start;
return rpl_vfprintf!write_file(cast(void*)stdout, format, va_args);
}
int vprintf(string format, va_list ap) {
return rpl_vfprintf!write_file(cast(void*)stdout, format, ap);
}
You can define the version-flag "SNPRINTF_TEST" to test this version of snprintf against the C version of your system.
- Registered by Kyto
- 1.0.0 released 4 years ago
- KytoDragon/d_snprintf
- github.com/KytoDragon/d_snprintf/
- MIT
- Copyright © 2020 KytoDragon, Copyright © 2008 Holger Weiß, Copyright © 1995 Patrick Powell
- Authors:
- Dependencies:
- none
- Versions:
-
1.2.3 2024-Aug-24 1.2.2 2024-Jun-27 1.2.1 2023-Jan-22 1.2.0 2023-Jan-22 1.1.1 2021-Jun-16 - Download Stats:
-
-
0 downloads today
-
1 downloads this week
-
10 downloads this month
-
344 downloads total
-
- Score:
- 0.8
- Short URL:
- d_snprintf.dub.pm