| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. |
| 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if (!m_impl) | 396 if (!m_impl) |
| 397 return 0; | 397 return 0; |
| 398 if (m_impl->hasTerminatingNullCharacter()) | 398 if (m_impl->hasTerminatingNullCharacter()) |
| 399 return m_impl->characters(); | 399 return m_impl->characters(); |
| 400 m_impl = StringImpl::createWithTerminatingNullCharacter(*m_impl); | 400 m_impl = StringImpl::createWithTerminatingNullCharacter(*m_impl); |
| 401 return m_impl->characters(); | 401 return m_impl->characters(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 String String::format(const char *format, ...) | 404 String String::format(const char *format, ...) |
| 405 { | 405 { |
| 406 #if OS(WINCE) | |
| 407 va_list args; | 406 va_list args; |
| 408 va_start(args, format); | 407 va_start(args, format); |
| 409 | 408 |
| 410 Vector<char, 256> buffer; | |
| 411 | |
| 412 int bufferSize = 256; | |
| 413 buffer.resize(bufferSize); | |
| 414 for (;;) { | |
| 415 int written = vsnprintf(buffer.data(), bufferSize, format, args); | |
| 416 va_end(args); | |
| 417 | |
| 418 if (written == 0) | |
| 419 return String(""); | |
| 420 if (written > 0) | |
| 421 return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data
()), written); | |
| 422 | |
| 423 bufferSize <<= 1; | |
| 424 buffer.resize(bufferSize); | |
| 425 va_start(args, format); | |
| 426 } | |
| 427 | |
| 428 #else | |
| 429 va_list args; | |
| 430 va_start(args, format); | |
| 431 | |
| 432 Vector<char, 256> buffer; | 409 Vector<char, 256> buffer; |
| 433 | 410 |
| 434 // Do the format once to get the length. | 411 // Do the format once to get the length. |
| 435 #if COMPILER(MSVC) | 412 #if COMPILER(MSVC) |
| 436 int result = _vscprintf(format, args); | 413 int result = _vscprintf(format, args); |
| 437 #else | 414 #else |
| 438 char ch; | 415 char ch; |
| 439 int result = vsnprintf(&ch, 1, format, args); | 416 int result = vsnprintf(&ch, 1, format, args); |
| 440 // We need to call va_end() and then va_start() again here, as the | 417 // We need to call va_end() and then va_start() again here, as the |
| 441 // contents of args is undefined after the call to vsnprintf | 418 // contents of args is undefined after the call to vsnprintf |
| (...skipping 11 matching lines...) Expand all Loading... |
| 453 return String(); | 430 return String(); |
| 454 unsigned len = result; | 431 unsigned len = result; |
| 455 buffer.grow(len + 1); | 432 buffer.grow(len + 1); |
| 456 | 433 |
| 457 // Now do the formatting again, guaranteed to fit. | 434 // Now do the formatting again, guaranteed to fit. |
| 458 vsnprintf(buffer.data(), buffer.size(), format, args); | 435 vsnprintf(buffer.data(), buffer.size(), format, args); |
| 459 | 436 |
| 460 va_end(args); | 437 va_end(args); |
| 461 | 438 |
| 462 return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), len
); | 439 return StringImpl::create(reinterpret_cast<const LChar*>(buffer.data()), len
); |
| 463 #endif | |
| 464 } | 440 } |
| 465 | 441 |
| 466 String String::number(int number) | 442 String String::number(int number) |
| 467 { | 443 { |
| 468 return numberToStringSigned<String>(number); | 444 return numberToStringSigned<String>(number); |
| 469 } | 445 } |
| 470 | 446 |
| 471 String String::number(unsigned int number) | 447 String String::number(unsigned int number) |
| 472 { | 448 { |
| 473 return numberToStringUnsigned<String>(number); | 449 return numberToStringUnsigned<String>(number); |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 buffer.append('\0'); | 1215 buffer.append('\0'); |
| 1240 return buffer; | 1216 return buffer; |
| 1241 } | 1217 } |
| 1242 | 1218 |
| 1243 Vector<char> asciiDebug(String& string) | 1219 Vector<char> asciiDebug(String& string) |
| 1244 { | 1220 { |
| 1245 return asciiDebug(string.impl()); | 1221 return asciiDebug(string.impl()); |
| 1246 } | 1222 } |
| 1247 | 1223 |
| 1248 #endif | 1224 #endif |
| OLD | NEW |