pcsprintf
This commit is contained in:
parent
8e00b06cfa
commit
cdf2ee5c8a
BIN
examples/example
BIN
examples/example
Binary file not shown.
Binary file not shown.
|
@ -5,12 +5,17 @@
|
||||||
using namespace pipecolors;
|
using namespace pipecolors;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
char * buffer;
|
|
||||||
|
char buffer[128];
|
||||||
|
char * buf;
|
||||||
int num = 5;
|
int num = 5;
|
||||||
const char* str = "My number is";
|
const char* str = "My number is";
|
||||||
|
const char* str2 = "|10My number is|07";
|
||||||
int len = pcprintf("|01%s |41|09%d|39\n", str, num);
|
int len = pcprintf("|01%s |41|09%d|39\n", str, num);
|
||||||
pcprintf("|10Length of Len is : |15|30%d\n|07", len);
|
pcprintf("|10Length of Len is : |15|30%d\n|07", len);
|
||||||
int len2 = pcsprintf(buffer, "%s %d\n", str, num);
|
int len2 = pcsprintf(buffer, "%s %d\n", str2, num);
|
||||||
printf("%s\n", buffer);
|
printf("\n%s %d\n", buffer, len2);
|
||||||
|
int len3 = asprintf(&buf, "%s %d\n", str2, num);
|
||||||
|
printf("\n%s %d\n", buf, len3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -107,14 +107,14 @@ namespace pipecolors {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pcprintf( const char * fmt, ...)
|
int pcprintf( const char * format, ...)
|
||||||
{
|
{
|
||||||
char * buffer;
|
char * buffer;
|
||||||
va_list args;
|
va_list args;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, format);
|
||||||
ret = vasprintf(&buffer, fmt, args);
|
ret = vasprintf(&buffer, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -130,24 +130,29 @@ namespace pipecolors {
|
||||||
return(result.second);
|
return(result.second);
|
||||||
|
|
||||||
}
|
}
|
||||||
int pcsprintf( char * str, const char * fmt, ... ) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
|
|
||||||
|
int pcsprintf( char * str, const char * format, ... ) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
std::cout << sizeof(str);
|
||||||
|
char** str1 = (char**)str;
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
|
||||||
ret = vasprintf(&str, fmt, args);
|
va_start(args, format);
|
||||||
|
ret = vasprintf(str1, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
free(str);
|
free(str1);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string s(str);
|
std::string s(*str1);
|
||||||
//free(buffer);
|
free(*str1);
|
||||||
|
std::pair<std::string, int> result = replace_colors(s);
|
||||||
//std::pair<std::string, int> result = replace_colors(s);
|
const char * s2 = (const char *)result.first.c_str();
|
||||||
//char* buffer = result.first;
|
strcpy(str, s2);
|
||||||
|
return result.second;
|
||||||
return s.length();
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -32,9 +32,9 @@ pcsprintf \- convert pipecode (|10) to ansi colors
|
||||||
.sp
|
.sp
|
||||||
.B using namespace pipecolors;
|
.B using namespace pipecolors;
|
||||||
.sp
|
.sp
|
||||||
.BI "int pcprintf(const char *" format ", ...);"
|
.BI "int pcprintf(const char * " format ", ...);"
|
||||||
.br
|
.br
|
||||||
.BI "int pcsprintf(char *" str ", const char *" format ", ...);"
|
.BI "int pcsprintf(char * " str ", const char * " format ", ...);"
|
||||||
.sp
|
.sp
|
||||||
.in -4n
|
.in -4n
|
||||||
.ad
|
.ad
|
||||||
|
|
|
@ -11,7 +11,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int pcprintf( const char * format, ... );
|
int pcprintf( const char * format, ... );
|
||||||
int pcsprintf( char * str, const char * fmt, ... );
|
int pcsprintf( char * str, const char * format, ... );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue