Commit f7393e10 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Remove workaround for snprintf of older MSVC.

It's unnecessary since VS2015.

Change-Id: Iba63fa152ea0fbc2f567903e21b3cba9065a746a
Reviewed-on: https://chromium-review.googlesource.com/987637
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547400}
parent 226bffdd
...@@ -60,7 +60,6 @@ ...@@ -60,7 +60,6 @@
#include "platform/weborigin/SecurityOrigin.h" #include "platform/weborigin/SecurityOrigin.h"
#include "platform/wtf/Assertions.h" #include "platform/wtf/Assertions.h"
#include "platform/wtf/StdLibExtras.h" #include "platform/wtf/StdLibExtras.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/Time.h" #include "platform/wtf/Time.h"
#include "platform/wtf/text/CString.h" #include "platform/wtf/text/CString.h"
#include "platform/wtf/text/StringBuilder.h" #include "platform/wtf/text/StringBuilder.h"
......
...@@ -72,7 +72,6 @@ ...@@ -72,7 +72,6 @@
#include "platform/Histogram.h" #include "platform/Histogram.h"
#include "platform/KillRing.h" #include "platform/KillRing.h"
#include "platform/scroll/Scrollbar.h" #include "platform/scroll/Scrollbar.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/text/AtomicString.h" #include "platform/wtf/text/AtomicString.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "public/platform/WebEditingCommandType.h" #include "public/platform/WebEditingCommandType.h"
......
...@@ -72,7 +72,6 @@ ...@@ -72,7 +72,6 @@
#include "platform/network/HTTPParsers.h" #include "platform/network/HTTPParsers.h"
#include "platform/plugins/PluginData.h" #include "platform/plugins/PluginData.h"
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/text/CString.h" #include "platform/wtf/text/CString.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
......
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/weborigin/SecurityOrigin.h" #include "platform/weborigin/SecurityOrigin.h"
#include "platform/wtf/AutoReset.h" #include "platform/wtf/AutoReset.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/Threading.h" #include "platform/wtf/Threading.h"
#include "platform/wtf/Vector.h" #include "platform/wtf/Vector.h"
#include "platform/wtf/text/UTF8.h" #include "platform/wtf/text/UTF8.h"
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "platform/bindings/ScriptState.h" #include "platform/bindings/ScriptState.h"
#include "platform/bindings/V8Binding.h" #include "platform/bindings/V8Binding.h"
#include "platform/bindings/V8ObjectConstructor.h" #include "platform/bindings/V8ObjectConstructor.h"
#include "platform/wtf/StringExtras.h"
namespace blink { namespace blink {
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "platform/KeyboardCodes.h" #include "platform/KeyboardCodes.h"
#include "platform/wtf/ASCIICType.h" #include "platform/wtf/ASCIICType.h"
#include "platform/wtf/Assertions.h" #include "platform/wtf/Assertions.h"
#include "platform/wtf/StringExtras.h"
#include "public/platform/WebGestureEvent.h" #include "public/platform/WebGestureEvent.h"
#include "public/platform/WebKeyboardEvent.h" #include "public/platform/WebKeyboardEvent.h"
#include "public/platform/WebMouseWheelEvent.h" #include "public/platform/WebMouseWheelEvent.h"
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "platform/fonts/FontCache.h" #include "platform/fonts/FontCache.h"
#include "platform/text/ICUError.h" #include "platform/text/ICUError.h"
#include "platform/wtf/HashMap.h" #include "platform/wtf/HashMap.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/text/StringHash.h" #include "platform/wtf/text/StringHash.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "platform/geometry/LayoutRect.h" #include "platform/geometry/LayoutRect.h"
#include "platform/geometry/LayoutSize.h" #include "platform/geometry/LayoutSize.h"
#include "platform/wtf/MathExtras.h" #include "platform/wtf/MathExtras.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
namespace blink { namespace blink {
......
...@@ -326,7 +326,6 @@ jumbo_source_set("wtf_unittests_sources") { ...@@ -326,7 +326,6 @@ jumbo_source_set("wtf_unittests_sources") {
"RefPtrTest.cpp", "RefPtrTest.cpp",
"SaturatedArithmeticTest.cpp", "SaturatedArithmeticTest.cpp",
"ScopedLoggerTest.cpp", "ScopedLoggerTest.cpp",
"StringExtrasTest.cpp",
"StringHasherTest.cpp", "StringHasherTest.cpp",
"TreeNodeTest.cpp", "TreeNodeTest.cpp",
"TypeTraitsTest.cpp", "TypeTraitsTest.cpp",
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#ifndef WTF_StringExtras_h #ifndef WTF_StringExtras_h
#define WTF_StringExtras_h #define WTF_StringExtras_h
#include <stdarg.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "build/build_config.h" #include "build/build_config.h"
...@@ -38,44 +36,6 @@ ...@@ -38,44 +36,6 @@
#if defined(COMPILER_MSVC) #if defined(COMPILER_MSVC)
// FIXME: why a compiler check instead of OS? also, these should be HAVE checks // FIXME: why a compiler check instead of OS? also, these should be HAVE checks
#if _MSC_VER < 1900
// snprintf is implemented in VS 2015
inline int snprintf(char* buffer, size_t count, const char* format, ...) {
int result;
va_list args;
va_start(args, format);
result = _vsnprintf(buffer, count, format, args);
va_end(args);
// In the case where the string entirely filled the buffer, _vsnprintf will
// not null-terminate it, but snprintf must.
if (count > 0)
buffer[count - 1] = '\0';
return result;
}
inline double wtf_vsnprintf(char* buffer, // NOLINT
size_t count,
const char* format,
va_list args) {
int result = _vsnprintf(buffer, count, format, args);
// In the case where the string entirely filled the buffer, _vsnprintf will
// not null-terminate it, but vsnprintf must.
if (count > 0)
buffer[count - 1] = '\0';
return result;
}
// Work around a difference in Microsoft's implementation of vsnprintf, where
// vsnprintf does not null terminate the buffer. WebKit can rely on the null
// termination. Microsoft's implementation is fixed in VS 2015.
#define vsnprintf(buffer, count, format, args) \
wtf_vsnprintf(buffer, count, format, args)
#endif
inline int strncasecmp(const char* s1, const char* s2, size_t len) { inline int strncasecmp(const char* s1, const char* s2, size_t len) {
return _strnicmp(s1, s2, len); return _strnicmp(s1, s2, len);
} }
...@@ -84,6 +44,6 @@ inline int strcasecmp(const char* s1, const char* s2) { ...@@ -84,6 +44,6 @@ inline int strcasecmp(const char* s1, const char* s2) {
return _stricmp(s1, s2); return _stricmp(s1, s2);
} }
#endif #endif // defined(COMPILER_MSVC)
#endif // WTF_StringExtras_h #endif // WTF_StringExtras_h
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform/wtf/StringExtras.h"
#include <limits>
#include "build/build_config.h"
#include "platform/wtf/text/CString.h"
#include "platform/wtf/text/WTFString.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace WTF {
template <typename IntegerType>
struct PrintfFormatTrait {
static const char kFormat[];
};
template <>
struct PrintfFormatTrait<short> {
static const char kFormat[];
};
const char PrintfFormatTrait<short>::kFormat[] = "%hd";
template <>
struct PrintfFormatTrait<int> {
static const char kFormat[];
};
const char PrintfFormatTrait<int>::kFormat[] = "%d";
template <>
struct PrintfFormatTrait<long> {
static const char kFormat[];
};
const char PrintfFormatTrait<long>::kFormat[] = "%ld";
template <>
struct PrintfFormatTrait<long long> {
static const char kFormat[];
};
#if defined(OS_WIN)
const char PrintfFormatTrait<long long>::kFormat[] = "%I64i";
#else
const char PrintfFormatTrait<long long>::kFormat[] = "%lli";
#endif // defined(OS_WIN)
template <>
struct PrintfFormatTrait<unsigned short> {
static const char kFormat[];
};
const char PrintfFormatTrait<unsigned short>::kFormat[] = "%hu";
template <>
struct PrintfFormatTrait<unsigned> {
static const char kFormat[];
};
const char PrintfFormatTrait<unsigned>::kFormat[] = "%u";
template <>
struct PrintfFormatTrait<unsigned long> {
static const char kFormat[];
};
const char PrintfFormatTrait<unsigned long>::kFormat[] = "%lu";
template <>
struct PrintfFormatTrait<unsigned long long> {
static const char kFormat[];
};
#if defined(OS_WIN)
const char PrintfFormatTrait<unsigned long long>::kFormat[] = "%I64u";
#else
const char PrintfFormatTrait<unsigned long long>::kFormat[] = "%llu";
#endif // defined(OS_WIN)
// FIXME: use snprintf from StringExtras.h
template <typename IntegerType>
void TestBoundaries() {
const unsigned kBufferSize = 256;
Vector<char, kBufferSize> buffer;
buffer.resize(kBufferSize);
const IntegerType min = std::numeric_limits<IntegerType>::min();
CString min_string_data = String::Number(min).Latin1();
snprintf(buffer.data(), kBufferSize, PrintfFormatTrait<IntegerType>::kFormat,
min);
EXPECT_STREQ(buffer.data(), min_string_data.data());
const IntegerType max = std::numeric_limits<IntegerType>::max();
CString max_string_data = String::Number(max).Latin1();
snprintf(buffer.data(), kBufferSize, PrintfFormatTrait<IntegerType>::kFormat,
max);
EXPECT_STREQ(buffer.data(), max_string_data.data());
}
template <typename IntegerType>
void TestNumbers() {
const unsigned kBufferSize = 256;
Vector<char, kBufferSize> buffer;
buffer.resize(kBufferSize);
for (int i = -100; i < 100; ++i) {
const IntegerType number = static_cast<IntegerType>(i);
CString number_string_data = String::Number(number).Latin1();
snprintf(buffer.data(), kBufferSize,
PrintfFormatTrait<IntegerType>::kFormat, number);
EXPECT_STREQ(buffer.data(), number_string_data.data());
}
}
TEST(StringExtraTest, IntegerToStringConversionSignedIntegerBoundaries) {
TestBoundaries<short>();
TestBoundaries<int>();
TestBoundaries<long>();
TestBoundaries<long long>();
}
TEST(StringExtraTest, IntegerToStringConversionSignedIntegerRegularNumbers) {
TestNumbers<short>();
TestNumbers<int>();
TestNumbers<long>();
TestNumbers<long long>();
}
TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerBoundaries) {
TestBoundaries<unsigned short>();
TestBoundaries<unsigned>();
TestBoundaries<unsigned long>();
TestBoundaries<unsigned long long>();
}
TEST(StringExtraTest, IntegerToStringConversionUnsignedIntegerRegularNumbers) {
TestNumbers<unsigned short>();
TestNumbers<unsigned>();
TestNumbers<unsigned long>();
TestNumbers<unsigned long long>();
}
} // namespace WTF
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "platform/wtf/text/Base64.h" #include "platform/wtf/text/Base64.h"
#include "platform/wtf/StringExtras.h"
#include <limits.h> #include <limits.h>
namespace WTF { namespace WTF {
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include "platform/wtf/text/TextCodec.h" #include "platform/wtf/text/TextCodec.h"
#include "platform/wtf/StringExtras.h"
namespace WTF { namespace WTF {
TextCodec::~TextCodec() = default; TextCodec::~TextCodec() = default;
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "platform/wtf/ASCIICType.h" #include "platform/wtf/ASCIICType.h"
#include "platform/wtf/MathExtras.h" #include "platform/wtf/MathExtras.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/Vector.h" #include "platform/wtf/Vector.h"
#include "platform/wtf/dtoa.h" #include "platform/wtf/dtoa.h"
#include "platform/wtf/text/CString.h" #include "platform/wtf/text/CString.h"
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "platform/wtf/Assertions.h" #include "platform/wtf/Assertions.h"
#include "platform/wtf/StdLibExtras.h" #include "platform/wtf/StdLibExtras.h"
#include "platform/wtf/StringExtras.h"
#include "platform/wtf/Threading.h" #include "platform/wtf/Threading.h"
#include "platform/wtf/ThreadingPrimitives.h" #include "platform/wtf/ThreadingPrimitives.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment