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;
|
||||
|
||||
int main(void) {
|
||||
char * buffer;
|
||||
|
||||
char buffer[128];
|
||||
char * buf;
|
||||
int num = 5;
|
||||
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);
|
||||
pcprintf("|10Length of Len is : |15|30%d\n|07", len);
|
||||
int len2 = pcsprintf(buffer, "%s %d\n", str, num);
|
||||
printf("%s\n", buffer);
|
||||
int len2 = pcsprintf(buffer, "%s %d\n", str2, num);
|
||||
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;
|
||||
}
|
|
@ -107,14 +107,14 @@ namespace pipecolors {
|
|||
|
||||
}
|
||||
|
||||
int pcprintf( const char * fmt, ...)
|
||||
int pcprintf( const char * format, ...)
|
||||
{
|
||||
char * buffer;
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
va_start(args, fmt);
|
||||
ret = vasprintf(&buffer, fmt, args);
|
||||
va_start(args, format);
|
||||
ret = vasprintf(&buffer, format, args);
|
||||
va_end(args);
|
||||
if(ret == -1) {
|
||||
free(buffer);
|
||||
|
@ -130,24 +130,29 @@ namespace pipecolors {
|
|||
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_start(args, fmt);
|
||||
ret = vasprintf(&str, fmt, args);
|
||||
|
||||
va_start(args, format);
|
||||
ret = vasprintf(str1, format, args);
|
||||
va_end(args);
|
||||
|
||||
if(ret == -1) {
|
||||
free(str);
|
||||
free(str1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string s(str);
|
||||
//free(buffer);
|
||||
|
||||
//std::pair<std::string, int> result = replace_colors(s);
|
||||
//char* buffer = result.first;
|
||||
|
||||
return s.length();
|
||||
std::string s(*str1);
|
||||
free(*str1);
|
||||
std::pair<std::string, int> result = replace_colors(s);
|
||||
const char * s2 = (const char *)result.first.c_str();
|
||||
strcpy(str, s2);
|
||||
return result.second;
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -11,7 +11,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
int pcprintf( const char * format, ... );
|
||||
int pcsprintf( char * str, const char * fmt, ... );
|
||||
int pcsprintf( char * str, const char * format, ... );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue