2018-12-16 01:42:37 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-12-16 02:47:21 +08:00
|
|
|
#include "compiler.h"
|
2018-12-16 01:42:37 +08:00
|
|
|
#include "string_utils.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate the space and join two strings.
|
|
|
|
*/
|
|
|
|
char *mstrjoin(const char *src1, const char *src2) {
|
2018-12-16 02:47:21 +08:00
|
|
|
auto str = ccalloc(strlen(src1)+strlen(src2)+1, char);
|
2018-12-16 01:42:37 +08:00
|
|
|
|
|
|
|
strcpy(str, src1);
|
|
|
|
strcat(str, src2);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate the space and join two strings;
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
mstrjoin3(const char *src1, const char *src2, const char *src3) {
|
2018-12-16 02:47:21 +08:00
|
|
|
auto str = ccalloc(strlen(src1)+strlen(src2)+strlen(src3)+1, char);
|
2018-12-16 01:42:37 +08:00
|
|
|
|
|
|
|
strcpy(str, src1);
|
|
|
|
strcat(str, src2);
|
|
|
|
strcat(str, src3);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concatenate a string on heap with another string.
|
|
|
|
*/
|
|
|
|
void mstrextend(char **psrc1, const char *src2) {
|
2018-12-16 02:47:21 +08:00
|
|
|
*psrc1 = crealloc(*psrc1, (*psrc1 ? strlen(*psrc1) : 0)+strlen(src2)+1);
|
2018-12-16 01:42:37 +08:00
|
|
|
|
|
|
|
strcat(*psrc1, src2);
|
|
|
|
}
|