property.c 856 B

123456789101112131415161718192021222324252627282930313233
  1. #include "property.h"
  2. #include <core/check.h>
  3. void property_value_out(PropertyValueContext* ctx, const char* fmt, unsigned int nparts, ...) {
  4. furi_assert(ctx);
  5. furi_string_reset(ctx->key);
  6. va_list args;
  7. va_start(args, nparts);
  8. for(size_t i = 0; i < nparts; ++i) {
  9. const char* keypart = va_arg(args, const char*);
  10. furi_string_cat(ctx->key, keypart);
  11. if(i < nparts - 1) {
  12. furi_string_push_back(ctx->key, ctx->sep);
  13. }
  14. }
  15. const char* value_str;
  16. if(fmt) {
  17. furi_string_vprintf(ctx->value, fmt, args);
  18. value_str = furi_string_get_cstr(ctx->value);
  19. } else {
  20. // C string passthrough (no formatting)
  21. value_str = va_arg(args, const char*);
  22. }
  23. va_end(args);
  24. ctx->out(furi_string_get_cstr(ctx->key), value_str, ctx->last, ctx->context);
  25. }