Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit fc73dac

Browse files
committed
[[ Foundation ]] Added MCListAppendFormat() method.
1 parent 89aba0f commit fc73dac

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

libfoundation/include/foundation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,13 @@ bool MCListCreateMutable(char_t delimiter, MCListRef& r_list);
17431743

17441744
// Eventually this will accept any value type, but for now - just strings, names, and booleans.
17451745
bool MCListAppend(MCListRef list, MCValueRef value);
1746+
1747+
// Append a sequence of native chars as an element.
17461748
bool MCListAppendNativeChars(MCListRef list, const char_t *chars, uindex_t char_count);
17471749

1750+
// Append a formatted string as an element.
1751+
bool MCListAppendFormat(MCListRef list, const char *format, ...);
1752+
17481753
// Make an immutable copy of the list.
17491754
// Note that this method is fragile at the moment and should only be used to
17501755
// copy a list out of an autolistref that is about to be deallocated.

libfoundation/src/foundation-list.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ bool MCListCopyAsStringAndRelease(MCListRef self, MCStringRef& r_string)
103103
return true;
104104
}
105105

106+
bool MCListAppendFormat(MCListRef self, const char *p_format, ...)
107+
{
108+
bool t_success;
109+
t_success = true;
110+
111+
MCStringRef t_string;
112+
t_string = nil;
113+
114+
va_list t_args;
115+
va_start(t_args, p_format);
116+
t_success = MCStringFormatV(t_string, p_format, t_args);
117+
va_end(t_args);
118+
119+
if (t_success)
120+
t_success = MCListAppend(self, t_string);
121+
122+
if (t_string != nil)
123+
MCValueRelease(t_string);
124+
125+
return t_success;
126+
}
127+
106128
bool MCListAppendNativeChars(MCListRef self, const char_t *p_chars, uindex_t p_char_count)
107129
{
108130
bool t_first = self->buffer == nil;

0 commit comments

Comments
 (0)