2 copyright: Steve Dekorte, 2006. All rights reserved.
3 license: See _BSDLicense.txt.
12 UArray
*UArray_newWithFormat_(const char *format
, ...)
17 self
= UArray_newWithVargs_(format
, ap
);
22 UArray
*UArray_newWithVargs_(const char *format
, va_list ap
)
24 UArray
*self
= UArray_new();
25 UArray_fromVargs_(self
, format
,ap
);
29 UArray
*UArray_fromFormat_(UArray
*self
, const char *format
, ...)
33 UArray_fromVargs_(self
, format
, ap
);
38 void UArray_fromVargs_(UArray
*self
, const char *format
, va_list ap
)
48 char *s
= va_arg(ap
, char *);
49 if (!s
) { printf("UArray_fromVargs_ missing param"); return; }
50 UArray_appendCString_(self
, s
);
52 else if (*format
== 'i' || *format
== 'd')
54 int i
= va_arg(ap
, int);
57 snprintf(s
, 100, "%i", i
);
58 UArray_appendCString_(self
, s
);
60 else if (*format
== 'f')
62 double d
= va_arg(ap
, double);
65 snprintf(s
, 100, "%f", d
);
66 UArray_appendCString_(self
, s
);
68 else if (*format
== 'p')
70 void *p
= va_arg(ap
, void *);
73 snprintf(s
, 100, "%p", p
);
74 UArray_appendCString_(self
, s
);
76 // new format command for a given number adding spaces
77 else if (*format
== '#')
79 int n
, i
= va_arg(ap
, int);
82 for (n
= 0; n
< i
; n
++)
84 UArray_appendCString_(self
, s
);
92 snprintf(s
, 2, "%c", *format
);
93 UArray_appendCString_(self
, s
);
100 UArray
*UArray_asNewHexStringUArray(UArray
*self
)
102 size_t i
, newSize
= self
->size
* 2;
103 UArray
*ba
= UArray_new();
104 UArray_setSize_(ba
, newSize
);
106 for(i
= 0; i
< self
->size
; i
++)
108 int v
= UArray_longAt_(self
, i
);
109 char *s
= (char *)(ba
->data
+ i
* 2);
113 snprintf(s
, newSize
, "0%x", (int)v
);
117 snprintf(s
, newSize
, "%x", (int)v
);