MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / appendText

Function appendText

modules/dasSQLITE/sqlite/shell.c:959–993  ·  view source on GitHub ↗

zIn is either a pointer to a NULL-terminated string in memory obtained ** from malloc(), or a NULL pointer. The string pointed to by zAppend is ** added to zIn, and the result returned in memory obtained from malloc(). ** zIn, if it was not NULL, is freed. ** ** If the third argument, quote, is not '\0', then it is used as a ** quote character for zAppend. */

Source from the content-addressed store, hash-verified

957** quote character for zAppend.
958*/
959static void appendText(ShellText *p, const char *zAppend, char quote){
960 i64 len;
961 i64 i;
962 i64 nAppend = strlen30(zAppend);
963
964 len = nAppend+p->n+1;
965 if( quote ){
966 len += 2;
967 for(i=0; i<nAppend; i++){
968 if( zAppend[i]==quote ) len++;
969 }
970 }
971
972 if( p->z==0 || p->n+len>=p->nAlloc ){
973 p->nAlloc = p->nAlloc*2 + len + 20;
974 p->z = realloc(p->z, p->nAlloc);
975 shell_check_oom(p->z);
976 }
977
978 if( quote ){
979 char *zCsr = p->z+p->n;
980 *zCsr++ = quote;
981 for(i=0; i<nAppend; i++){
982 *zCsr++ = zAppend[i];
983 if( zAppend[i]==quote ) *zCsr++ = quote;
984 }
985 *zCsr++ = quote;
986 p->n = (int)(zCsr - p->z);
987 *zCsr = '\0';
988 }else{
989 memcpy(p->z+p->n, zAppend, nAppend);
990 p->n += nAppend;
991 p->z[p->n] = '\0';
992 }
993}
994
995/*
996** Attempt to determine if identifier zName needs to be quoted, either

Callers 4

shellFakeSchemaFunction · 0.85
captureOutputCallbackFunction · 0.85
dump_callbackFunction · 0.85
do_meta_commandFunction · 0.85

Calls 2

strlen30Function · 0.85
shell_check_oomFunction · 0.85

Tested by

no test coverage detected