| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 462 } |
| 463 | 463 |
| 464 String String::format(const char *format, ...) | 464 String String::format(const char *format, ...) |
| 465 { | 465 { |
| 466 va_list args; | 466 va_list args; |
| 467 va_start(args, format); | 467 va_start(args, format); |
| 468 | 468 |
| 469 Vector<char, 256> buffer; | 469 Vector<char, 256> buffer; |
| 470 | 470 |
| 471 // Do the format once to get the length. | 471 // Do the format once to get the length. |
| 472 #if COMPILER(MSVC) | |
| 473 int result = _vscprintf(format, args); | |
| 474 #else | |
| 475 char ch; | 472 char ch; |
| 476 int result = vsnprintf(&ch, 1, format, args); | 473 int result = vsnprintf(&ch, 1, format, args); |
| 477 // We need to call va_end() and then va_start() again here, as the | 474 // We need to call va_end() and then va_start() again here, as the |
| 478 // contents of args is undefined after the call to vsnprintf | 475 // contents of args is undefined after the call to vsnprintf |
| 479 // according to http://man.cx/snprintf(3) | 476 // according to http://man.cx/snprintf(3) |
| 480 // | 477 // |
| 481 // Not calling va_end/va_start here happens to work on lots of | 478 // Not calling va_end/va_start here happens to work on lots of |
| 482 // systems, but fails e.g. on 64bit Linux. | 479 // systems, but fails e.g. on 64bit Linux. |
| 483 va_end(args); | 480 va_end(args); |
| 484 va_start(args, format); | 481 va_start(args, format); |
| 485 #endif | |
| 486 | 482 |
| 487 if (result == 0) | 483 if (result == 0) |
| 488 return String(""); | 484 return String(""); |
| 489 if (result < 0) | 485 if (result < 0) |
| 490 return String(); | 486 return String(); |
| 491 unsigned len = result; | 487 unsigned len = result; |
| 492 buffer.grow(len + 1); | 488 buffer.grow(len + 1); |
| 493 | 489 |
| 494 // Now do the formatting again, guaranteed to fit. | 490 // Now do the formatting again, guaranteed to fit. |
| 495 vsnprintf(buffer.data(), buffer.size(), format, args); | 491 vsnprintf(buffer.data(), buffer.size(), format, args); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 else | 1004 else |
| 1009 digitValue = c - 'A' + 10; | 1005 digitValue = c - 'A' + 10; |
| 1010 | 1006 |
| 1011 if (value > maxMultiplier || (value == maxMultiplier && digitValue > (in
tegralMax % base) + isNegative)) | 1007 if (value > maxMultiplier || (value == maxMultiplier && digitValue > (in
tegralMax % base) + isNegative)) |
| 1012 goto bye; | 1008 goto bye; |
| 1013 | 1009 |
| 1014 value = base * value + digitValue; | 1010 value = base * value + digitValue; |
| 1015 ++data; | 1011 ++data; |
| 1016 } | 1012 } |
| 1017 | 1013 |
| 1018 #if COMPILER(MSVC) | |
| 1019 #pragma warning(push, 0) | |
| 1020 #pragma warning(disable:4146) | |
| 1021 #endif | |
| 1022 | |
| 1023 if (isNegative) | 1014 if (isNegative) |
| 1024 value = -value; | 1015 value = -value; |
| 1025 | 1016 |
| 1026 #if COMPILER(MSVC) | |
| 1027 #pragma warning(pop) | |
| 1028 #endif | |
| 1029 | |
| 1030 // skip trailing space | 1017 // skip trailing space |
| 1031 while (length && isSpaceOrNewline(*data)) { | 1018 while (length && isSpaceOrNewline(*data)) { |
| 1032 --length; | 1019 --length; |
| 1033 ++data; | 1020 ++data; |
| 1034 } | 1021 } |
| 1035 | 1022 |
| 1036 if (!length) | 1023 if (!length) |
| 1037 isOk = true; | 1024 isOk = true; |
| 1038 bye: | 1025 bye: |
| 1039 if (ok) | 1026 if (ok) |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 buffer.append('\0'); | 1258 buffer.append('\0'); |
| 1272 return buffer; | 1259 return buffer; |
| 1273 } | 1260 } |
| 1274 | 1261 |
| 1275 Vector<char> asciiDebug(String& string) | 1262 Vector<char> asciiDebug(String& string) |
| 1276 { | 1263 { |
| 1277 return asciiDebug(string.impl()); | 1264 return asciiDebug(string.impl()); |
| 1278 } | 1265 } |
| 1279 | 1266 |
| 1280 #endif | 1267 #endif |
| OLD | NEW |