Returns the length
| 279 | |
| 280 | // Returns the length |
| 281 | size_t asCString::Format(const char *format, ...) |
| 282 | { |
| 283 | va_list args; |
| 284 | va_start(args, format); |
| 285 | |
| 286 | const size_t startSize = 1024; |
| 287 | char tmp[startSize]; |
| 288 | int r = asVSNPRINTF(tmp, startSize-1, format, args); |
| 289 | |
| 290 | if( r > 0 && r < int(startSize) ) |
| 291 | { |
| 292 | Assign(tmp, r); |
| 293 | } |
| 294 | else |
| 295 | { |
| 296 | // TODO: For some reason this doesn't work properly on Linux. Perhaps the |
| 297 | // problem is related to vsnprintf not keeping the state of va_arg. |
| 298 | // Perhaps I need to rewrite this in some way to keep the state |
| 299 | size_t n = startSize*2; |
| 300 | asCString str; // Use temporary string in case the current buffer is a parameter |
| 301 | str.Allocate(n, false); |
| 302 | |
| 303 | while( (r = asVSNPRINTF(str.AddressOf(), n, format, args)) < 0 || r >= int(n) ) |
| 304 | { |
| 305 | n *= 2; |
| 306 | str.Allocate(n, false); |
| 307 | } |
| 308 | |
| 309 | Assign(str.AddressOf(), r); |
| 310 | } |
| 311 | |
| 312 | va_end(args); |
| 313 | |
| 314 | return length; |
| 315 | } |
| 316 | |
| 317 | char &asCString::operator [](size_t index) |
| 318 | { |
no test coverage detected