text
stringlengths
0
357
}
char* dc_stock_str_repl_int(dc_context_t* context, int id, int to_insert_int)
{
char* ret = get_string(context, id, to_insert_int);
char* to_insert_str = dc_mprintf("%i", (int)to_insert_int);
dc_str_replace(&ret, "%1$s", to_insert_str);
dc_str_replace(&ret, "%1$d", to_insert_str);
free(to_insert_str);
return ret;
}
char* dc_stock_str_repl_string2(dc_context_t* context, int id, const char* to_insert, const char* to_insert2)
{
char* ret = get_string(context, id, 0);
dc_str_replace(&ret, "%1$s", to_insert);
dc_str_replace(&ret, "%1$d", to_insert);
dc_str_replace(&ret, "%2$s", to_insert2);
dc_str_replace(&ret, "%2$d", to_insert2);
return ret;
}
char* dc_stock_system_msg(dc_context_t* context, int str_id,
const char* param1, const char* param2,
uint32_t from_id)
{
char* ret = NULL;
dc_contact_t* mod_contact = NULL;
char* mod_displayname = NULL;
dc_contact_t* from_contact = NULL;
char* from_displayname = NULL;
/* if the first parameter is an email-address,
expand it to name+address */
if (str_id==DC_STR_MSGADDMEMBER || str_id==DC_STR_MSGDELMEMBER) {
uint32_t mod_contact_id = dc_lookup_contact_id_by_addr(context, param1);
if (mod_contact_id!=0) {
mod_contact = dc_get_contact(context, mod_contact_id);
mod_displayname = dc_contact_get_name_n_addr(mod_contact);
param1 = mod_displayname;
}
}
char* action = dc_stock_str_repl_string2(context,
str_id,
param1, param2);
if (from_id)
{
// to simplify building of sentencens in some languages,
// remove the full-stop from the action string
if (strlen(action) && action[strlen(action)-1]=='.') {
action[strlen(action)-1] = 0;
}
from_contact = dc_get_contact(context, from_id);
from_displayname = dc_contact_get_display_name(from_contact);
ret = dc_stock_str_repl_string2(context,
from_id==DC_CONTACT_ID_SELF? DC_STR_MSGACTIONBYME : DC_STR_MSGACTIONBYUSER,
action, from_displayname);
}
else
{
ret = dc_strdup(action);
}
free(action);
free(from_displayname);
free(mod_displayname);
dc_contact_unref(from_contact);
dc_contact_unref(mod_contact);
return ret;
}
```
Filename: dc_strbuilder.c
```c
#include "dc_context.h"
/**
* Init a string-builder-object.
* A string-builder-object is placed typically on the stack and contains a string-buffer
* which is initially empty.
*
* You can add data to the string-buffer using eg. dc_strbuilder_cat() or
* dc_strbuilder_catf() - the buffer is reallocated as needed.
*
* When you're done with string building, the ready-to-use, null-terminates
* string can be found at dc_strbuilder_t::buf, you can do whatever you like
* with this buffer, however, never forget to call free() when done.
*
* @param strbuilder The object to initialze.
* @param init_bytes The number of bytes to reserve for the string. If you have an
* idea about how long the resulting string will be, you can give this as a hint here;
* this avoids some reallocations; if the string gets longer, reallocation is done.