libweave: Remove unnecessary code from base lib
Mostly strings, logs and command line routines.
BUG=brillo:1256
TEST=`FEATURES=test emerge-gizmo libweave buffet`
Change-Id: I69cf44792ee1277109ca1a4b5995c5021d84d434
Reviewed-on: https://chromium-review.googlesource.com/294173
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/libweave/external/base/atomicops.h b/libweave/external/base/atomicops.h
index 6a5371c..eea00ed 100644
--- a/libweave/external/base/atomicops.h
+++ b/libweave/external/base/atomicops.h
@@ -37,7 +37,7 @@
#include <cstddef>
#include "base/base_export.h"
-#include "build/build_config.h"
+#include "base/build/build_config.h"
#if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
// windows.h #defines this (only on x64). This causes problems because the
diff --git a/libweave/external/base/atomicops_unittest.cc b/libweave/external/base/atomicops_unittest.cc
index 3fd5597..7771142 100644
--- a/libweave/external/base/atomicops_unittest.cc
+++ b/libweave/external/base/atomicops_unittest.cc
@@ -7,7 +7,7 @@
#include <stdint.h>
#include <string.h>
-#include "testing/gtest/include/gtest/gtest.h"
+#include <gtest/gtest.h>
template <class AtomicType>
static void TestAtomicIncrement() {
diff --git a/libweave/external/base/base_export.h b/libweave/external/base/base_export.h
index 723b38a..89693b4 100644
--- a/libweave/external/base/base_export.h
+++ b/libweave/external/base/base_export.h
@@ -5,30 +5,7 @@
#ifndef BASE_BASE_EXPORT_H_
#define BASE_BASE_EXPORT_H_
-#if defined(COMPONENT_BUILD)
-#if defined(WIN32)
-
-#if defined(BASE_IMPLEMENTATION)
-#define BASE_EXPORT __declspec(dllexport)
-#define BASE_EXPORT_PRIVATE __declspec(dllexport)
-#else
-#define BASE_EXPORT __declspec(dllimport)
-#define BASE_EXPORT_PRIVATE __declspec(dllimport)
-#endif // defined(BASE_IMPLEMENTATION)
-
-#else // defined(WIN32)
-#if defined(BASE_IMPLEMENTATION)
-#define BASE_EXPORT __attribute__((visibility("default")))
-#define BASE_EXPORT_PRIVATE __attribute__((visibility("default")))
-#else
#define BASE_EXPORT
#define BASE_EXPORT_PRIVATE
-#endif // defined(BASE_IMPLEMENTATION)
-#endif
-
-#else // defined(COMPONENT_BUILD)
-#define BASE_EXPORT
-#define BASE_EXPORT_PRIVATE
-#endif
#endif // BASE_BASE_EXPORT_H_
diff --git a/libweave/external/base/basictypes.h b/libweave/external/base/basictypes.h
index d71abd9..154688d 100644
--- a/libweave/external/base/basictypes.h
+++ b/libweave/external/base/basictypes.h
@@ -16,7 +16,7 @@
#include <stdint.h> // For intptr_t.
#include "base/macros.h"
-#include "build/build_config.h"
+#include "base/build/build_config.h"
// DEPRECATED: Please use (u)int{8,16,32,64}_t instead (and include <stdint.h>).
typedef int8_t int8;
diff --git a/libweave/external/base/bind_helpers.h b/libweave/external/base/bind_helpers.h
index 4003dea..09deb33 100644
--- a/libweave/external/base/bind_helpers.h
+++ b/libweave/external/base/bind_helpers.h
@@ -261,21 +261,21 @@
// Helpers to assert that arguments of a recounted type are bound with a
// scoped_refptr.
template <bool IsClasstype, typename T>
-struct UnsafeBindtoRefCountedArgHelper : false_type {
+struct UnsafeBindtoRefCountedArgHelper : std::false_type {
};
template <typename T>
struct UnsafeBindtoRefCountedArgHelper<true, T>
- : integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
+ : std::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
};
template <typename T>
-struct UnsafeBindtoRefCountedArg : false_type {
+struct UnsafeBindtoRefCountedArg : std::false_type {
};
template <typename T>
struct UnsafeBindtoRefCountedArg<T*>
- : UnsafeBindtoRefCountedArgHelper<is_class<T>::value, T> {
+ : UnsafeBindtoRefCountedArgHelper<std::is_class<T>::value, T> {
};
template <typename T>
@@ -550,14 +550,14 @@
// The first argument should be the type of the object that will be received by
// the method.
template <bool IsMethod, typename... Args>
-struct IsWeakMethod : public false_type {};
+struct IsWeakMethod : public std::false_type {};
template <typename T, typename... Args>
-struct IsWeakMethod<true, WeakPtr<T>, Args...> : public true_type {};
+struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {};
template <typename T, typename... Args>
struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...>
- : public true_type {};
+ : public std::true_type {};
// Packs a list of types to hold them in a single type.
diff --git a/libweave/external/base/bind_internal.h b/libweave/external/base/bind_internal.h
index e053218..6d500a5 100644
--- a/libweave/external/base/bind_internal.h
+++ b/libweave/external/base/bind_internal.h
@@ -6,12 +6,11 @@
#define BASE_BIND_INTERNAL_H_
#include "base/bind_helpers.h"
+#include "base/build/build_config.h"
#include "base/callback_internal.h"
-#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"
#include "base/tuple.h"
-#include "build/build_config.h"
#if defined(OS_WIN)
#include "base/bind_internal_win.h"
@@ -70,7 +69,7 @@
// Implementation note: This non-specialized case handles zero-arity case only.
// Non-zero-arity cases should be handled by the specialization below.
template <typename Sig>
-struct HasNonConstReferenceParam : false_type {};
+struct HasNonConstReferenceParam : std::false_type {};
// Implementation note: Select true_type if the first parameter is a non-const
// reference. Otherwise, skip the first parameter and check rest of parameters
@@ -78,7 +77,7 @@
template <typename R, typename T, typename... Args>
struct HasNonConstReferenceParam<R(T, Args...)>
: SelectType<is_non_const_reference<T>::value,
- true_type,
+ std::true_type,
HasNonConstReferenceParam<R(Args...)>>::Type {};
// HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw
@@ -86,16 +85,7 @@
// Implementation note: This non-specialized case handles zero-arity case only.
// Non-zero-arity cases should be handled by the specialization below.
template <typename... Args>
-struct HasRefCountedTypeAsRawPtr : false_type {};
-
-// Implementation note: Select true_type if the first parameter is a raw pointer
-// to a RefCounted type. Otherwise, skip the first parameter and check rest of
-// parameters recursively.
-template <typename T, typename... Args>
-struct HasRefCountedTypeAsRawPtr<T, Args...>
- : SelectType<NeedsScopedRefptrButGetsRawPtr<T>::value,
- true_type,
- HasRefCountedTypeAsRawPtr<Args...>>::Type {};
+struct HasRefCountedTypeAsRawPtr : std::false_type {};
// BindsArrayToFirstArg selects true_type when |is_method| is true and the first
// item of |Args| is an array type.
@@ -103,10 +93,10 @@
// zero-arity case only. Other cases should be handled by the specialization
// below.
template <bool is_method, typename... Args>
-struct BindsArrayToFirstArg : false_type {};
+struct BindsArrayToFirstArg : std::false_type {};
template <typename T, typename... Args>
-struct BindsArrayToFirstArg<true, T, Args...> : is_array<T> {};
+struct BindsArrayToFirstArg<true, T, Args...> : std::is_array<T> {};
// HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except
// when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument.
@@ -166,7 +156,7 @@
class RunnableAdapter<R(T::*)(Args...)> {
public:
typedef R (RunType)(T*, Args...);
- typedef true_type IsMethod;
+ typedef std::true_type IsMethod;
explicit RunnableAdapter(R(T::*method)(Args...))
: method_(method) {
@@ -185,7 +175,7 @@
class RunnableAdapter<R(T::*)(Args...) const> {
public:
typedef R (RunType)(const T*, Args...);
- typedef true_type IsMethod;
+ typedef std::true_type IsMethod;
explicit RunnableAdapter(R(T::*method)(Args...) const)
: method_(method) {
@@ -311,7 +301,7 @@
// WeakCalls are only supported for functions with a void return type.
// Otherwise, the function result would be undefined if the the WeakPtr<>
// is invalidated.
- COMPILE_ASSERT(is_void<ReturnType>::value,
+ COMPILE_ASSERT(std::is_void<ReturnType>::value,
weak_ptrs_can_only_bind_to_methods_without_return_values);
};
diff --git a/libweave/external/base/bind_unittest.cc b/libweave/external/base/bind_unittest.cc
index f885403..d3cc79a 100644
--- a/libweave/external/base/bind_unittest.cc
+++ b/libweave/external/base/bind_unittest.cc
@@ -4,12 +4,13 @@
#include "base/bind.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Mock;
using ::testing::Return;
diff --git a/libweave/external/base/build/build_config.h b/libweave/external/base/build/build_config.h
index 5181b2b..904965a 100644
--- a/libweave/external/base/build/build_config.h
+++ b/libweave/external/base/build/build_config.h
@@ -12,8 +12,8 @@
// ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64)
// ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
-#ifndef BUILD_BUILD_CONFIG_H_
-#define BUILD_BUILD_CONFIG_H_
+#ifndef BASE_BUILD_BUILD_CONFIG_H_
+#define BASE_BUILD_BUILD_CONFIG_H_
// Add Brillo-specific defines.
#if defined(__BRILLO__)
@@ -151,25 +151,6 @@
#error Please add support for your architecture in build/build_config.h
#endif
-// Type detection for wchar_t.
-#if defined(OS_WIN)
-#define WCHAR_T_IS_UTF16
-#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
- defined(__WCHAR_MAX__) && \
- (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
-#define WCHAR_T_IS_UTF32
-#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \
- defined(__WCHAR_MAX__) && \
- (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
-// On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
-// compile in this mode (in particular, Chrome doesn't). This is intended for
-// other projects using base who manage their own dependencies and make sure
-// short wchar works for them.
-#define WCHAR_T_IS_UTF16
-#else
-#error Please add support for your compiler in build/build_config.h
-#endif
-
#if defined(OS_ANDROID)
// The compiler thinks std::string::const_iterator and "const char*" are
// equivalent types.
@@ -179,4 +160,4 @@
#define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
#endif
-#endif // BUILD_BUILD_CONFIG_H_
+#endif // BASE_BUILD_BUILD_CONFIG_H_
diff --git a/libweave/external/base/callback_internal.h b/libweave/external/base/callback_internal.h
index 3e5ed9d..84c5dc8 100644
--- a/libweave/external/base/callback_internal.h
+++ b/libweave/external/base/callback_internal.h
@@ -108,7 +108,7 @@
static NoType Test(...);
static const bool value = sizeof((Test<T>(0))) == sizeof(YesType) &&
- !is_const<T>::value;
+ !std::is_const<T>::value;
};
// Mark std::unique_ptr<T> and common containers using unique_ptr as MoveOnly
@@ -236,12 +236,14 @@
// parameter to another callback. This is to support Callbacks that return
// the movable-but-not-copyable types whitelisted above.
template <typename T>
-typename enable_if<!IsMoveOnlyType<T>::value, T>::type& CallbackForward(T& t) {
+typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& CallbackForward(
+ T& t) {
return t;
}
template <typename T>
-typename enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward(T& t) {
+typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward(
+ T& t) {
return t.Pass();
}
diff --git a/libweave/external/base/callback_list_unittest.cc b/libweave/external/base/callback_list_unittest.cc
index 9adbabb..3b50622 100644
--- a/libweave/external/base/callback_list_unittest.cc
+++ b/libweave/external/base/callback_list_unittest.cc
@@ -4,11 +4,12 @@
#include "base/callback_list.h"
+#include <gtest/gtest.h>
+
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
diff --git a/libweave/external/base/callback_unittest.cc b/libweave/external/base/callback_unittest.cc
index 2844aa9..3630176 100644
--- a/libweave/external/base/callback_unittest.cc
+++ b/libweave/external/base/callback_unittest.cc
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/bind.h"
#include "base/callback.h"
-#include "base/callback_helpers.h"
+
+#include <gtest/gtest.h>
+
+#include "base/bind.h"
#include "base/callback_internal.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -148,15 +149,6 @@
Closure cb;
};
-TEST_F(CallbackTest, ResetAndReturn) {
- TestForReentrancy tfr;
- ASSERT_FALSE(tfr.cb.is_null());
- ASSERT_FALSE(tfr.cb_already_run);
- ResetAndReturn(&tfr.cb).Run();
- ASSERT_TRUE(tfr.cb.is_null());
- ASSERT_TRUE(tfr.cb_already_run);
-}
-
class CallbackOwner : public base::RefCounted<CallbackOwner> {
public:
explicit CallbackOwner(bool* deleted) {
diff --git a/libweave/external/base/command_line.h b/libweave/external/base/command_line.h
index 3de8873..662a4d4 100644
--- a/libweave/external/base/command_line.h
+++ b/libweave/external/base/command_line.h
@@ -16,234 +16,14 @@
#define BASE_COMMAND_LINE_H_
#include <stddef.h>
-#include <map>
-#include <string>
-#include <vector>
#include "base/base_export.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_piece.h"
-#include "build/build_config.h"
namespace base {
-class FilePath;
-
class BASE_EXPORT CommandLine {
public:
-#if defined(OS_WIN)
- // The native command line string type.
- typedef base::string16 StringType;
-#elif defined(OS_POSIX)
- typedef std::string StringType;
-#endif
-
- typedef StringType::value_type CharType;
- typedef std::vector<StringType> StringVector;
- typedef std::map<std::string, StringType> SwitchMap;
- typedef std::map<base::StringPiece, const StringType*> StringPieceSwitchMap;
-
- // A constructor for CommandLines that only carry switches and arguments.
- enum NoProgram { NO_PROGRAM };
- explicit CommandLine(NoProgram no_program);
-
- // Construct a new command line with |program| as argv[0].
- explicit CommandLine(const FilePath& program);
-
- // Construct a new command line from an argument list.
- CommandLine(int argc, const CharType* const* argv);
- explicit CommandLine(const StringVector& argv);
-
- // Override copy and assign to ensure |switches_by_stringpiece_| is valid.
- CommandLine(const CommandLine& other);
- CommandLine& operator=(const CommandLine& other);
-
- ~CommandLine();
-
-#if defined(OS_WIN)
- // By default this class will treat command-line arguments beginning with
- // slashes as switches on Windows, but not other platforms.
- //
- // If this behavior is inappropriate for your application, you can call this
- // function BEFORE initializing the current process' global command line
- // object and the behavior will be the same as Posix systems (only hyphens
- // begin switches, everything else will be an arg).
- static void set_slash_is_not_a_switch();
-#endif
-
- // Initialize the current process CommandLine singleton. On Windows, ignores
- // its arguments (we instead parse GetCommandLineW() directly) because we
- // don't trust the CRT's parsing of the command line, but it still must be
- // called to set up the command line. Returns false if initialization has
- // already occurred, and true otherwise. Only the caller receiving a 'true'
- // return value should take responsibility for calling Reset.
- static bool Init(int argc, const char* const* argv);
-
- // Destroys the current process CommandLine singleton. This is necessary if
- // you want to reset the base library to its initial state (for example, in an
- // outer library that needs to be able to terminate, and be re-initialized).
- // If Init is called only once, as in main(), Reset() is not necessary.
- static void Reset();
-
- // Get the singleton CommandLine representing the current process's
- // command line. Note: returned value is mutable, but not thread safe;
- // only mutate if you know what you're doing!
- static CommandLine* ForCurrentProcess();
-
- // Returns true if the CommandLine has been initialized for the given process.
- static bool InitializedForCurrentProcess();
-
-#if defined(OS_WIN)
- static CommandLine FromString(const base::string16& command_line);
-#endif
-
- // Initialize from an argv vector.
- void InitFromArgv(int argc, const CharType* const* argv);
- void InitFromArgv(const StringVector& argv);
-
- // Constructs and returns the represented command line string.
- // CAUTION! This should be avoided on POSIX because quoting behavior is
- // unclear.
- StringType GetCommandLineString() const {
- return GetCommandLineStringInternal(false);
- }
-
-#if defined(OS_WIN)
- // Constructs and returns the represented command line string. Assumes the
- // command line contains placeholders (eg, %1) and quotes any program or
- // argument with a '%' in it. This should be avoided unless the placeholder is
- // required by an external interface (eg, the Windows registry), because it is
- // not generally safe to replace it with an arbitrary string. If possible,
- // placeholders should be replaced *before* converting the command line to a
- // string.
- StringType GetCommandLineStringWithPlaceholders() const {
- return GetCommandLineStringInternal(true);
- }
-#endif
-
- // Constructs and returns the represented arguments string.
- // CAUTION! This should be avoided on POSIX because quoting behavior is
- // unclear.
- StringType GetArgumentsString() const {
- return GetArgumentsStringInternal(false);
- }
-
-#if defined(OS_WIN)
- // Constructs and returns the represented arguments string. Assumes the
- // command line contains placeholders (eg, %1) and quotes any argument with a
- // '%' in it. This should be avoided unless the placeholder is required by an
- // external interface (eg, the Windows registry), because it is not generally
- // safe to replace it with an arbitrary string. If possible, placeholders
- // should be replaced *before* converting the arguments to a string.
- StringType GetArgumentsStringWithPlaceholders() const {
- return GetArgumentsStringInternal(true);
- }
-#endif
-
- // Returns the original command line string as a vector of strings.
- const StringVector& argv() const { return argv_; }
-
- // Get and Set the program part of the command line string (the first item).
- FilePath GetProgram() const;
- void SetProgram(const FilePath& program);
-
- // Returns true if this command line contains the given switch.
- // Switch names must be lowercase.
- // The second override provides an optimized version to avoid inlining codegen
- // at every callsite to find the length of the constant and construct a
- // StringPiece.
- bool HasSwitch(const base::StringPiece& switch_string) const;
- bool HasSwitch(const char switch_constant[]) const;
-
- // Returns the value associated with the given switch. If the switch has no
- // value or isn't present, this method returns the empty string.
- // Switch names must be lowercase.
- std::string GetSwitchValueASCII(const base::StringPiece& switch_string) const;
- FilePath GetSwitchValuePath(const base::StringPiece& switch_string) const;
- StringType GetSwitchValueNative(const base::StringPiece& switch_string) const;
-
- // Get a copy of all switches, along with their values.
- const SwitchMap& GetSwitches() const { return switches_; }
-
- // Append a switch [with optional value] to the command line.
- // Note: Switches will precede arguments regardless of appending order.
- void AppendSwitch(const std::string& switch_string);
- void AppendSwitchPath(const std::string& switch_string,
- const FilePath& path);
- void AppendSwitchNative(const std::string& switch_string,
- const StringType& value);
- void AppendSwitchASCII(const std::string& switch_string,
- const std::string& value);
-
- // Copy a set of switches (and any values) from another command line.
- // Commonly used when launching a subprocess.
- void CopySwitchesFrom(const CommandLine& source,
- const char* const switches[],
- size_t count);
-
- // Get the remaining arguments to the command.
- StringVector GetArgs() const;
-
- // Append an argument to the command line. Note that the argument is quoted
- // properly such that it is interpreted as one argument to the target command.
- // AppendArg is primarily for ASCII; non-ASCII input is interpreted as UTF-8.
- // Note: Switches will precede arguments regardless of appending order.
- void AppendArg(const std::string& value);
- void AppendArgPath(const FilePath& value);
- void AppendArgNative(const StringType& value);
-
- // Append the switches and arguments from another command line to this one.
- // If |include_program| is true, include |other|'s program as well.
- void AppendArguments(const CommandLine& other, bool include_program);
-
- // Insert a command before the current command.
- // Common for debuggers, like "valgrind" or "gdb --args".
- void PrependWrapper(const StringType& wrapper);
-
-#if defined(OS_WIN)
- // Initialize by parsing the given command line string.
- // The program name is assumed to be the first item in the string.
- void ParseFromString(const base::string16& command_line);
-#endif
-
- private:
- // Disallow default constructor; a program name must be explicitly specified.
- CommandLine();
- // Allow the copy constructor. A common pattern is to copy of the current
- // process's command line and then add some flags to it. For example:
- // CommandLine cl(*CommandLine::ForCurrentProcess());
- // cl.AppendSwitch(...);
-
- // Internal version of GetCommandLineString. If |quote_placeholders| is true,
- // also quotes parts with '%' in them.
- StringType GetCommandLineStringInternal(bool quote_placeholders) const;
-
- // Internal version of GetArgumentsString. If |quote_placeholders| is true,
- // also quotes parts with '%' in them.
- StringType GetArgumentsStringInternal(bool quote_placeholders) const;
-
- // Reconstruct |switches_by_stringpiece| to be a mirror of |switches|.
- // |switches_by_stringpiece| only contains pointers to objects owned by
- // |switches|.
- void ResetStringPieces();
-
- // The singleton CommandLine representing the current process's command line.
- static CommandLine* current_process_commandline_;
-
- // The argv array: { program, [(--|-|/)switch[=value]]*, [--], [argument]* }
- StringVector argv_;
-
- // Parsed-out switch keys and values.
- SwitchMap switches_;
-
- // A mirror of |switches_| with only references to the actual strings.
- // The StringPiece internally holds a pointer to a key in |switches_| while
- // the mapped_type points to a value in |switches_|.
- // Used for allocation-free lookups.
- StringPieceSwitchMap switches_by_stringpiece_;
-
- // The index after the program and switches, any arguments start here.
- size_t begin_args_;
+ static bool Init(int argc, const char* const* argv) { return true; }
};
} // namespace base
diff --git a/libweave/external/base/compiler_specific.h b/libweave/external/base/compiler_specific.h
index 63297dc..8c2ba34 100644
--- a/libweave/external/base/compiler_specific.h
+++ b/libweave/external/base/compiler_specific.h
@@ -5,7 +5,7 @@
#ifndef BASE_COMPILER_SPECIFIC_H_
#define BASE_COMPILER_SPECIFIC_H_
-#include "build/build_config.h"
+#include "base/build/build_config.h"
#if defined(COMPILER_MSVC)
diff --git a/libweave/external/base/gtest_prod_util.h b/libweave/external/base/gtest_prod_util.h
index 3289e63..b90cd4e 100644
--- a/libweave/external/base/gtest_prod_util.h
+++ b/libweave/external/base/gtest_prod_util.h
@@ -5,7 +5,7 @@
#ifndef BASE_GTEST_PROD_UTIL_H_
#define BASE_GTEST_PROD_UTIL_H_
-#include "testing/gtest/include/gtest/gtest_prod.h"
+#include <gtest/gtest_prod.h>
// This is a wrapper for gtest's FRIEND_TEST macro that friends
// test with all possible prefixes. This is very helpful when changing the test
diff --git a/libweave/external/base/guid.h b/libweave/external/base/guid.h
index abcc589..420ec17 100644
--- a/libweave/external/base/guid.h
+++ b/libweave/external/base/guid.h
@@ -9,7 +9,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "build/build_config.h"
+#include "base/build/build_config.h"
namespace base {
@@ -19,9 +19,6 @@
// the GUID. The Windows implementation uses system services.
BASE_EXPORT std::string GenerateGUID();
-// Returns true if the input string conforms to the GUID format.
-BASE_EXPORT bool IsValidGUID(const std::string& guid);
-
#if defined(OS_POSIX)
// For unit testing purposes only. Do not use outside of tests.
BASE_EXPORT std::string RandomDataToGUIDString(const uint64 bytes[2]);
diff --git a/libweave/external/base/guid_unittest.cc b/libweave/external/base/guid_unittest.cc
index 1485497..37b4edc 100644
--- a/libweave/external/base/guid_unittest.cc
+++ b/libweave/external/base/guid_unittest.cc
@@ -6,8 +6,9 @@
#include <limits>
+#include <gtest/gtest.h>
+
#include "base/strings/string_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -15,6 +16,32 @@
namespace {
+template <typename Char>
+inline bool IsHexDigit(Char c) {
+ return (c >= '0' && c <= '9') ||
+ (c >= 'A' && c <= 'F') ||
+ (c >= 'a' && c <= 'f');
+}
+
+bool IsValidGUID(const std::string& guid) {
+ const size_t kGUIDLength = 36U;
+ if (guid.length() != kGUIDLength)
+ return false;
+
+ for (size_t i = 0; i < guid.length(); ++i) {
+ char current = guid[i];
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ if (current != '-')
+ return false;
+ } else {
+ if (!IsHexDigit(current))
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool IsGUIDv4(const std::string& guid) {
// The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
// where y is one of [8, 9, A, B].
@@ -43,8 +70,6 @@
for (int it = 0; it < kIterations; ++it) {
std::string guid = GenerateGUID();
EXPECT_TRUE(IsValidGUID(guid));
- EXPECT_TRUE(IsValidGUID(StringToLowerASCII(guid)));
- EXPECT_TRUE(IsValidGUID(StringToUpperASCII(guid)));
}
}
diff --git a/libweave/external/base/json/json_parser.cc b/libweave/external/base/json/json_parser.cc
index 4d79be3..964fcd4 100644
--- a/libweave/external/base/json/json_parser.cc
+++ b/libweave/external/base/json/json_parser.cc
@@ -13,7 +13,6 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversion_utils.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/third_party/icu/icu_utf.h"
#include "base/values.h"
@@ -142,10 +141,6 @@
string_piece_.CopyToString(out_value);
return true;
}
- bool GetAsString(string16* out_value) const override {
- *out_value = UTF8ToUTF16(string_piece_);
- return true;
- }
Value* DeepCopy() const override {
return new StringValue(string_piece_.as_string());
}
@@ -885,7 +880,7 @@
int len = 0;
char c = first;
- while (CanConsume(1) && IsAsciiDigit(c)) {
+ while (CanConsume(1) && std::isdigit(c)) {
c = *NextChar();
++len;
}
diff --git a/libweave/external/base/json/json_parser.h b/libweave/external/base/json/json_parser.h
index b4d0b1b..c8ed0cd 100644
--- a/libweave/external/base/json/json_parser.h
+++ b/libweave/external/base/json/json_parser.h
@@ -10,30 +10,14 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
#include "base/json/json_reader.h"
#include "base/strings/string_piece.h"
-#if !defined(OS_CHROMEOS)
-#include "base/gtest_prod_util.h"
-#endif
-
namespace base {
class Value;
}
-#if defined(OS_CHROMEOS)
-// Chromium and Chromium OS check out gtest to different places, so this is
-// unable to compile on both if gtest_prod.h is included here. Instead, include
-// its only contents -- this will need to be updated if the macro ever changes.
-#define FRIEND_TEST(test_case_name, test_name)\
-friend class test_case_name##_##test_name##_Test
-
-#define FRIEND_TEST_ALL_PREFIXES(test_case_name, test_name) \
- FRIEND_TEST(test_case_name, test_name); \
- FRIEND_TEST(test_case_name, DISABLED_##test_name); \
- FRIEND_TEST(test_case_name, FLAKY_##test_name)
-#endif // OS_CHROMEOS
-
namespace base {
namespace internal {
diff --git a/libweave/external/base/json/json_parser_unittest.cc b/libweave/external/base/json/json_parser_unittest.cc
index f776ddf..c432eee 100644
--- a/libweave/external/base/json/json_parser_unittest.cc
+++ b/libweave/external/base/json/json_parser_unittest.cc
@@ -4,10 +4,11 @@
#include "base/json/json_parser.h"
+#include <gtest/gtest.h>
+
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace internal {
diff --git a/libweave/external/base/json/json_reader_unittest.cc b/libweave/external/base/json/json_reader_unittest.cc
index 7d3a6d9..a5f2530 100644
--- a/libweave/external/base/json/json_reader_unittest.cc
+++ b/libweave/external/base/json/json_reader_unittest.cc
@@ -4,16 +4,14 @@
#include "base/json/json_reader.h"
-#include "base/base_paths.h"
-#include "base/files/file_util.h"
+#include <gtest/gtest.h>
+
+#include "base/build/build_config.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
-#include "base/path_service.h"
#include "base/strings/string_piece.h"
-#include "base/strings/utf_string_conversions.h"
+#include "base/strings/utf_string_conversion_utils.h"
#include "base/values.h"
-#include "build/build_config.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -225,7 +223,7 @@
EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
str_val.clear();
EXPECT_TRUE(root->GetAsString(&str_val));
- EXPECT_EQ(std::wstring(L"A\0\x1234", 3), UTF8ToWide(str_val));
+ EXPECT_EQ((std::string{'A', '\0', '\xE1', '\x88', '\xB4'}), str_val);
// Test invalid strings
root = JSONReader().ReadToValue("\"no closing quote");
@@ -482,7 +480,7 @@
EXPECT_TRUE(root->IsType(Value::TYPE_STRING));
str_val.clear();
EXPECT_TRUE(root->GetAsString(&str_val));
- EXPECT_EQ(L"\x7f51\x9875", UTF8ToWide(str_val));
+ EXPECT_EQ("\xE7\xBD\x91\xE9\xA1\xB5", str_val);
root = JSONReader().ReadToValue(
"{\"path\": \"/tmp/\xc3\xa0\xc3\xa8\xc3\xb2.png\"}");
@@ -551,22 +549,6 @@
EXPECT_EQ("root", str_val);
}
-TEST(JSONReaderTest, ReadFromFile) {
- FilePath path;
- ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path));
- path = path.AppendASCII("json");
- ASSERT_TRUE(base::PathExists(path));
-
- std::string input;
- ASSERT_TRUE(ReadFileToString(
- path.Append(FILE_PATH_LITERAL("bom_feff.json")), &input));
-
- JSONReader reader;
- scoped_ptr<Value> root(reader.ReadToValue(input));
- ASSERT_TRUE(root.get()) << reader.GetErrorMessage();
- EXPECT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
-}
-
// Tests that the root of a JSON object can be deleted safely while its
// children outlive it.
TEST(JSONReaderTest, StringOptimizations) {
diff --git a/libweave/external/base/json/json_writer.cc b/libweave/external/base/json/json_writer.cc
index abfead8..8bf4c6f 100644
--- a/libweave/external/base/json/json_writer.cc
+++ b/libweave/external/base/json/json_writer.cc
@@ -9,7 +9,7 @@
#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
-#include "base/strings/utf_string_conversions.h"
+#include "base/strings/utf_string_conversion_utils.h"
#include "base/values.h"
namespace base {
diff --git a/libweave/external/base/json/json_writer_unittest.cc b/libweave/external/base/json/json_writer_unittest.cc
index 0daeafc..cb88cde 100644
--- a/libweave/external/base/json/json_writer_unittest.cc
+++ b/libweave/external/base/json/json_writer_unittest.cc
@@ -3,8 +3,10 @@
// found in the LICENSE file.
#include "base/json/json_writer.h"
+
+#include <gtest/gtest.h>
+
#include "base/values.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
diff --git a/libweave/external/base/json/string_escape.cc b/libweave/external/base/json/string_escape.cc
index 469f9f9..7ba612f 100644
--- a/libweave/external/base/json/string_escape.cc
+++ b/libweave/external/base/json/string_escape.cc
@@ -6,10 +6,10 @@
#include <string>
+#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversion_utils.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/third_party/icu/icu_utf.h"
namespace base {
@@ -107,12 +107,6 @@
return EscapeJSONStringImpl(str, put_in_quotes, dest);
}
-bool EscapeJSONString(const StringPiece16& str,
- bool put_in_quotes,
- std::string* dest) {
- return EscapeJSONStringImpl(str, put_in_quotes, dest);
-}
-
std::string GetQuotedJSONString(const StringPiece& str) {
std::string dest;
bool ok = EscapeJSONStringImpl(str, true, &dest);
@@ -120,13 +114,6 @@
return dest;
}
-std::string GetQuotedJSONString(const StringPiece16& str) {
- std::string dest;
- bool ok = EscapeJSONStringImpl(str, true, &dest);
- DCHECK(ok);
- return dest;
-}
-
std::string EscapeBytesAsInvalidJSONString(const StringPiece& str,
bool put_in_quotes) {
std::string dest;
diff --git a/libweave/external/base/json/string_escape.h b/libweave/external/base/json/string_escape.h
index b66b7e5..c3a34bd 100644
--- a/libweave/external/base/json/string_escape.h
+++ b/libweave/external/base/json/string_escape.h
@@ -29,17 +29,9 @@
bool put_in_quotes,
std::string* dest);
-// Performs a similar function to the UTF-8 StringPiece version above,
-// converting UTF-16 code units to UTF-8 code units and escaping non-printing
-// control characters. On return, |dest| will contain a valid UTF-8 JSON string.
-BASE_EXPORT bool EscapeJSONString(const StringPiece16& str,
- bool put_in_quotes,
- std::string* dest);
-
// Helper functions that wrap the above two functions but return the value
// instead of appending. |put_in_quotes| is always true.
BASE_EXPORT std::string GetQuotedJSONString(const StringPiece& str);
-BASE_EXPORT std::string GetQuotedJSONString(const StringPiece16& str);
// Given an arbitrary byte string |str|, this will escape all non-ASCII bytes
// as \uXXXX escape sequences. This function is *NOT* meant to be used with
diff --git a/libweave/external/base/json/string_escape_unittest.cc b/libweave/external/base/json/string_escape_unittest.cc
index 100373f..615acc4 100644
--- a/libweave/external/base/json/string_escape_unittest.cc
+++ b/libweave/external/base/json/string_escape_unittest.cc
@@ -4,9 +4,10 @@
#include "base/json/string_escape.h"
+#include <gtest/gtest.h>
+
#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/strings/utf_string_conversion_utils.h"
namespace base {
@@ -68,91 +69,6 @@
EXPECT_TRUE(IsStringUTF8(out));
}
-TEST(JSONStringEscapeTest, EscapeUTF16) {
- const struct {
- const wchar_t* to_escape;
- const char* escaped;
- } cases[] = {
- {L"b\uffb1\u00ff", "b\xEF\xBE\xB1\xC3\xBF"},
- {L"\b\001aZ\"\\wee", "\\b\\u0001aZ\\\"\\\\wee"},
- {L"a\b\f\n\r\t\v\1\\.\"z",
- "a\\b\\f\\n\\r\\t\\u000B\\u0001\\\\.\\\"z"},
- {L"b\x0f\x7f\xf0\xff!", "b\\u000F\x7F\xC3\xB0\xC3\xBF!"},
- {L"c<>d", "c\\u003C>d"},
- };
-
- for (size_t i = 0; i < arraysize(cases); ++i) {
- string16 in = WideToUTF16(cases[i].to_escape);
-
- std::string out;
- EscapeJSONString(in, false, &out);
- EXPECT_EQ(std::string(cases[i].escaped), out);
- EXPECT_TRUE(IsStringUTF8(out));
-
- out = GetQuotedJSONString(in);
- EXPECT_EQ("\"" + std::string(cases[i].escaped) + "\"", out);
- EXPECT_TRUE(IsStringUTF8(out));
- }
-
- string16 in = WideToUTF16(cases[0].to_escape);
- std::string out;
- EscapeJSONString(in, false, &out);
- EXPECT_TRUE(IsStringUTF8(out));
-
- // test quoting
- std::string out_quoted;
- EscapeJSONString(in, true, &out_quoted);
- EXPECT_EQ(out.length() + 2, out_quoted.length());
- EXPECT_EQ(out_quoted.find(out), 1U);
- EXPECT_TRUE(IsStringUTF8(out));
-
- // now try with a NULL in the string
- string16 null_prepend = WideToUTF16(L"test");
- null_prepend.push_back(0);
- in = null_prepend + in;
- std::string expected = "test\\u0000";
- expected += cases[0].escaped;
- out.clear();
- EscapeJSONString(in, false, &out);
- EXPECT_EQ(expected, out);
- EXPECT_TRUE(IsStringUTF8(out));
-}
-
-TEST(JSONStringEscapeTest, EscapeUTF16OutsideBMP) {
- {
- // {a, U+10300, !}, SMP.
- string16 test;
- test.push_back('a');
- test.push_back(0xD800);
- test.push_back(0xDF00);
- test.push_back('!');
- std::string actual;
- EXPECT_TRUE(EscapeJSONString(test, false, &actual));
- EXPECT_EQ("a\xF0\x90\x8C\x80!", actual);
- }
- {
- // {U+20021, U+2002B}, SIP.
- string16 test;
- test.push_back(0xD840);
- test.push_back(0xDC21);
- test.push_back(0xD840);
- test.push_back(0xDC2B);
- std::string actual;
- EXPECT_TRUE(EscapeJSONString(test, false, &actual));
- EXPECT_EQ("\xF0\xA0\x80\xA1\xF0\xA0\x80\xAB", actual);
- }
- {
- // {?, U+D800, @}, lone surrogate.
- string16 test;
- test.push_back('?');
- test.push_back(0xD800);
- test.push_back('@');
- std::string actual;
- EXPECT_FALSE(EscapeJSONString(test, false, &actual));
- EXPECT_EQ("?\xEF\xBF\xBD@", actual);
- }
-}
-
TEST(JSONStringEscapeTest, EscapeBytes) {
const struct {
const char* to_escape;
diff --git a/libweave/external/base/location.cc b/libweave/external/base/location.cc
index 1333e6e..b31cae8 100644
--- a/libweave/external/base/location.cc
+++ b/libweave/external/base/location.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "build/build_config.h"
+#include "base/build/build_config.h"
#if defined(COMPILER_MSVC)
#include <intrin.h>
diff --git a/libweave/external/base/location.h b/libweave/external/base/location.h
index 477dc02..4a38264 100644
--- a/libweave/external/base/location.h
+++ b/libweave/external/base/location.h
@@ -10,7 +10,6 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "base/containers/hash_tables.h"
namespace tracked_objects {
@@ -47,26 +46,6 @@
std::string ToString() const;
- // Hash operator for hash maps.
- struct Hash {
- size_t operator()(const Location& location) const {
- // Compute the hash value using file name pointer and line number.
- // No need to use |function_name_| since the other two fields uniquely
- // identify this location.
-
- // The file name will always be uniquely identified by its pointer since
- // it comes from __FILE__, so no need to check the contents of the string.
- // See the definition of FROM_HERE in location.h, and how it is used
- // elsewhere.
-
- // Due to inconsistent definitions of uint64_t and uintptr_t, casting the
- // file name pointer to a uintptr_t causes a compiler error for some
- // platforms. The solution is to explicitly cast it to a uint64_t.
- return base::HashPair(reinterpret_cast<uint64_t>(location.file_name()),
- location.line_number());
- }
- };
-
// Translate the some of the state in this instance into a human readable
// string with HTML characters in the function names escaped, and append that
// string to |output|. Inclusion of the file_name_ and function_name_ are
diff --git a/libweave/external/base/logging.cc b/libweave/external/base/logging.cc
index 71528ad..1a796b8 100644
--- a/libweave/external/base/logging.cc
+++ b/libweave/external/base/logging.cc
@@ -4,39 +4,14 @@
#include "base/logging.h"
-#if defined(OS_WIN)
-#include <io.h>
-#include <windows.h>
-typedef HANDLE FileHandle;
-typedef HANDLE MutexHandle;
-// Windows warns on using write(). It prefers _write().
-#define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
-// Windows doesn't define STDERR_FILENO. Define it here.
-#define STDERR_FILENO 2
-#elif defined(OS_MACOSX)
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-#include <mach-o/dyld.h>
-#elif defined(OS_POSIX)
-#if defined(OS_NACL)
-#include <sys/time.h> // timespec doesn't seem to be in <time.h>
-#else
#include <sys/syscall.h>
-#endif
#include <time.h>
-#endif
-
-#if defined(OS_POSIX)
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#define MAX_PATH PATH_MAX
-typedef FILE* FileHandle;
-typedef pthread_mutex_t* MutexHandle;
-#endif
#include <algorithm>
#include <cstring>
@@ -45,34 +20,16 @@
#include <ostream>
#include <string>
-#include "base/base_switches.h"
-#include "base/command_line.h"
-#include "base/debug/alias.h"
-#include "base/debug/debugger.h"
-#include "base/debug/stack_trace.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/synchronization/lock_impl.h"
-#include "base/threading/platform_thread.h"
-#include "base/vlog.h"
-#if defined(OS_POSIX)
-#include "base/posix/safe_strerror.h"
-#endif
-
-#if defined(OS_ANDROID)
-#include <android/log.h>
-#endif
+#include "base/strings/utf_string_conversion_utils.h"
namespace logging {
namespace {
-VlogInfo* g_vlog_info = nullptr;
-VlogInfo* g_vlog_info_prev = nullptr;
-
const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
"INFO", "WARNING", "ERROR", "FATAL" };
@@ -89,24 +46,8 @@
// For LOG_ERROR and above, always print to stderr.
const int kAlwaysPrintErrorLevel = LOG_ERROR;
-// Which log file to use? This is initialized by InitLogging or
-// will be lazily initialized to the default value when it is
-// first needed.
-#if defined(OS_WIN)
-typedef std::wstring PathString;
-#else
-typedef std::string PathString;
-#endif
-PathString* g_log_file_name = nullptr;
-
-// This file is lazily opened and the handle may be nullptr
-FileHandle g_log_file = nullptr;
-
// What should be prepended to each message?
-bool g_log_process_id = false;
-bool g_log_thread_id = false;
bool g_log_timestamp = true;
-bool g_log_tickcount = false;
// Should we pop up fatal debug messages in a dialog?
bool show_error_dialogs = false;
@@ -119,281 +60,15 @@
// Helper functions to wrap platform differences.
-int32 CurrentProcessId() {
-#if defined(OS_WIN)
- return GetCurrentProcessId();
-#elif defined(OS_POSIX)
- return getpid();
-#endif
-}
-
-uint64 TickCount() {
-#if defined(OS_WIN)
- return GetTickCount();
-#elif defined(OS_MACOSX)
- return mach_absolute_time();
-#elif defined(OS_NACL)
- // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h
- // So we have to use clock() for now.
- return clock();
-#elif defined(OS_POSIX)
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
-
- uint64 absolute_micro =
- static_cast<int64>(ts.tv_sec) * 1000000 +
- static_cast<int64>(ts.tv_nsec) / 1000;
-
- return absolute_micro;
-#endif
-}
-
-void DeleteFilePath(const PathString& log_name) {
-#if defined(OS_WIN)
- DeleteFile(log_name.c_str());
-#elif defined(OS_NACL)
- // Do nothing; unlink() isn't supported on NaCl.
-#else
- unlink(log_name.c_str());
-#endif
-}
-
-PathString GetDefaultLogFile() {
-#if defined(OS_WIN)
- // On Windows we use the same path as the exe.
- wchar_t module_name[MAX_PATH];
- GetModuleFileName(nullptr, module_name, MAX_PATH);
-
- PathString log_name = module_name;
- PathString::size_type last_backslash = log_name.rfind('\\', log_name.size());
- if (last_backslash != PathString::npos)
- log_name.erase(last_backslash + 1);
- log_name += L"debug.log";
- return log_name;
-#elif defined(OS_POSIX)
- // On other platforms we just use the current directory.
- return PathString("debug.log");
-#endif
-}
-
-// This class acts as a wrapper for locking the logging files.
-// LoggingLock::Init() should be called from the main thread before any logging
-// is done. Then whenever logging, be sure to have a local LoggingLock
-// instance on the stack. This will ensure that the lock is unlocked upon
-// exiting the frame.
-// LoggingLocks can not be nested.
-class LoggingLock {
- public:
- LoggingLock() {
- LockLogging();
- }
-
- ~LoggingLock() {
- UnlockLogging();
- }
-
- static void Init(LogLockingState lock_log, const PathChar* new_log_file) {
- if (initialized)
- return;
- lock_log_file = lock_log;
- if (lock_log_file == LOCK_LOG_FILE) {
-#if defined(OS_WIN)
- if (!log_mutex) {
- std::wstring safe_name;
- if (new_log_file)
- safe_name = new_log_file;
- else
- safe_name = GetDefaultLogFile();
- // \ is not a legal character in mutex names so we replace \ with /
- std::replace(safe_name.begin(), safe_name.end(), '\\', '/');
- std::wstring t(L"Global\\");
- t.append(safe_name);
- log_mutex = ::CreateMutex(nullptr, FALSE, t.c_str());
-
- if (log_mutex == nullptr) {
-#if DEBUG
- // Keep the error code for debugging
- int error = GetLastError(); // NOLINT
- base::debug::BreakDebugger();
-#endif
- // Return nicely without putting initialized to true.
- return;
- }
- }
-#endif
- } else {
- log_lock = new base::internal::LockImpl();
- }
- initialized = true;
- }
-
- private:
- static void LockLogging() {
- if (lock_log_file == LOCK_LOG_FILE) {
-#if defined(OS_WIN)
- ::WaitForSingleObject(log_mutex, INFINITE);
- // WaitForSingleObject could have returned WAIT_ABANDONED. We don't
- // abort the process here. UI tests might be crashy sometimes,
- // and aborting the test binary only makes the problem worse.
- // We also don't use LOG macros because that might lead to an infinite
- // loop. For more info see http://crbug.com/18028.
-#elif defined(OS_POSIX)
- pthread_mutex_lock(&log_mutex);
-#endif
- } else {
- // use the lock
- log_lock->Lock();
- }
- }
-
- static void UnlockLogging() {
- if (lock_log_file == LOCK_LOG_FILE) {
-#if defined(OS_WIN)
- ReleaseMutex(log_mutex);
-#elif defined(OS_POSIX)
- pthread_mutex_unlock(&log_mutex);
-#endif
- } else {
- log_lock->Unlock();
- }
- }
-
- // The lock is used if log file locking is false. It helps us avoid problems
- // with multiple threads writing to the log file at the same time. Use
- // LockImpl directly instead of using Lock, because Lock makes logging calls.
- static base::internal::LockImpl* log_lock;
-
- // When we don't use a lock, we are using a global mutex. We need to do this
- // because LockFileEx is not thread safe.
-#if defined(OS_WIN)
- static MutexHandle log_mutex;
-#elif defined(OS_POSIX)
- static pthread_mutex_t log_mutex;
-#endif
-
- static bool initialized;
- static LogLockingState lock_log_file;
-};
-
-// static
-bool LoggingLock::initialized = false;
-// static
-base::internal::LockImpl* LoggingLock::log_lock = nullptr;
-// static
-LogLockingState LoggingLock::lock_log_file = LOCK_LOG_FILE;
-
-#if defined(OS_WIN)
-// static
-MutexHandle LoggingLock::log_mutex = nullptr;
-#elif defined(OS_POSIX)
-pthread_mutex_t LoggingLock::log_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-// Called by logging functions to ensure that |g_log_file| is initialized
-// and can be used for writing. Returns false if the file could not be
-// initialized. |g_log_file| will be nullptr in this case.
-bool InitializeLogFileHandle() {
- if (g_log_file)
- return true;
-
- if (!g_log_file_name) {
- // Nobody has called InitLogging to specify a debug log file, so here we
- // initialize the log file name to a default.
- g_log_file_name = new PathString(GetDefaultLogFile());
- }
-
- if ((g_logging_destination & LOG_TO_FILE) != 0) {
-#if defined(OS_WIN)
- g_log_file = CreateFile(g_log_file_name->c_str(), GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
- // try the current directory
- g_log_file = CreateFile(L".\\debug.log", GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
- g_log_file = nullptr;
- return false;
- }
- }
- SetFilePointer(g_log_file, 0, 0, FILE_END);
-#elif defined(OS_POSIX)
- g_log_file = fopen(g_log_file_name->c_str(), "a");
- if (g_log_file == nullptr)
- return false;
-#endif
- }
-
- return true;
-}
-
-void CloseFile(FileHandle log) {
-#if defined(OS_WIN)
- CloseHandle(log);
-#else
- fclose(log);
-#endif
-}
-
-void CloseLogFileUnlocked() {
- if (!g_log_file)
- return;
-
- CloseFile(g_log_file);
- g_log_file = nullptr;
-}
-
} // namespace
LoggingSettings::LoggingSettings()
- : logging_dest(LOG_DEFAULT),
- log_file(nullptr),
- lock_log(LOCK_LOG_FILE),
- delete_old(APPEND_TO_OLD_LOG_FILE) {}
+ : logging_dest(LOG_DEFAULT) {}
bool BaseInitLoggingImpl(const LoggingSettings& settings) {
-#if defined(OS_NACL)
- // Can log only to the system debug log.
- CHECK_EQ(settings.logging_dest & ~LOG_TO_SYSTEM_DEBUG_LOG, 0);
-#endif
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- // Don't bother initializing |g_vlog_info| unless we use one of the
- // vlog switches.
- if (command_line->HasSwitch(switches::kV) ||
- command_line->HasSwitch(switches::kVModule)) {
- // NOTE: If |g_vlog_info| has already been initialized, it might be in use
- // by another thread. Don't delete the old VLogInfo, just create a second
- // one. We keep track of both to avoid memory leak warnings.
- CHECK(!g_vlog_info_prev);
- g_vlog_info_prev = g_vlog_info;
-
- g_vlog_info =
- new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
- command_line->GetSwitchValueASCII(switches::kVModule),
- &g_min_log_level);
- }
-
g_logging_destination = settings.logging_dest;
- // ignore file options unless logging to file is set.
- if ((g_logging_destination & LOG_TO_FILE) == 0)
- return true;
-
- LoggingLock::Init(settings.lock_log, settings.log_file);
- LoggingLock logging_lock;
-
- // Calling InitLogging twice or after some log call has already opened the
- // default log file will re-initialize to the new options.
- CloseLogFileUnlocked();
-
- if (!g_log_file_name)
- g_log_file_name = new PathString();
- *g_log_file_name = settings.log_file;
- if (settings.delete_old == DELETE_OLD_LOG_FILE)
- DeleteFilePath(*g_log_file_name);
-
- return InitializeLogFileHandle();
+ return true;
}
void SetMinLogLevel(int level) {
@@ -410,20 +85,12 @@
int GetVlogLevelHelper(const char* file, size_t N) {
DCHECK_GT(N, 0U);
- // Note: |g_vlog_info| may change on a different thread during startup
- // (but will always be valid or nullptr).
- VlogInfo* vlog_info = g_vlog_info;
- return vlog_info ?
- vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
- GetVlogVerbosity();
+ return 0;
}
void SetLogItems(bool enable_process_id, bool enable_thread_id,
bool enable_timestamp, bool enable_tickcount) {
- g_log_process_id = enable_process_id;
- g_log_thread_id = enable_thread_id;
g_log_timestamp = enable_timestamp;
- g_log_tickcount = enable_tickcount;
}
void SetShowErrorDialogs(bool enable_dialogs) {
@@ -454,68 +121,6 @@
template std::string* MakeCheckOpString<std::string, std::string>(
const std::string&, const std::string&, const char* name);
-#if !defined(NDEBUG)
-// Displays a message box to the user with the error message in it.
-// Used for fatal messages, where we close the app simultaneously.
-// This is for developers only; we don't use this in circumstances
-// (like release builds) where users could see it, since users don't
-// understand these messages anyway.
-void DisplayDebugMessageInDialog(const std::string& str) {
- if (str.empty())
- return;
-
- if (!show_error_dialogs)
- return;
-
-#if defined(OS_WIN)
- // For Windows programs, it's possible that the message loop is
- // messed up on a fatal error, and creating a MessageBox will cause
- // that message loop to be run. Instead, we try to spawn another
- // process that displays its command line. We look for "Debug
- // Message.exe" in the same directory as the application. If it
- // exists, we use it, otherwise, we use a regular message box.
- wchar_t prog_name[MAX_PATH];
- GetModuleFileNameW(nullptr, prog_name, MAX_PATH);
- wchar_t* backslash = wcsrchr(prog_name, '\\');
- if (backslash)
- backslash[1] = 0;
- wcscat_s(prog_name, MAX_PATH, L"debug_message.exe");
-
- std::wstring cmdline = base::UTF8ToWide(str);
- if (cmdline.empty())
- return;
-
- STARTUPINFO startup_info;
- memset(&startup_info, 0, sizeof(startup_info));
- startup_info.cb = sizeof(startup_info);
-
- PROCESS_INFORMATION process_info;
- if (CreateProcessW(prog_name, &cmdline[0], nullptr, nullptr, false, 0,
- nullptr, nullptr, &startup_info, &process_info)) {
- WaitForSingleObject(process_info.hProcess, INFINITE);
- CloseHandle(process_info.hThread);
- CloseHandle(process_info.hProcess);
- } else {
- // debug process broken, let's just do a message box
- MessageBoxW(nullptr, &cmdline[0], L"Fatal error",
- MB_OK | MB_ICONHAND | MB_TOPMOST);
- }
-#else
- // We intentionally don't implement a dialog on other platforms.
- // You can just look at stderr.
-#endif // defined(OS_WIN)
-}
-#endif // !defined(NDEBUG)
-
-#if defined(OS_WIN)
-LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
-}
-
-LogMessage::SaveLastError::~SaveLastError() {
- ::SetLastError(last_error_);
-}
-#endif // defined(OS_WIN)
-
LogMessage::LogMessage(const char* file, int line, LogSeverity severity)
: severity_(severity), file_(file), line_(line) {
Init(file, line);
@@ -537,14 +142,6 @@
}
LogMessage::~LogMessage() {
-#if !defined(NDEBUG) && !defined(OS_NACL) && !defined(__UCLIBC__)
- if (severity_ == LOG_FATAL) {
- // Include a stack trace on a fatal.
- base::debug::StackTrace trace;
- stream_ << std::endl; // Newline to separate from log message.
- trace.OutputToStream(&stream_);
- }
-#endif
stream_ << std::endl;
std::string str_newline(stream_.str());
@@ -557,27 +154,6 @@
}
if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) {
-#if defined(OS_WIN)
- OutputDebugStringA(str_newline.c_str());
-#elif defined(OS_ANDROID)
- android_LogPriority priority =
- (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
- switch (severity_) {
- case LOG_INFO:
- priority = ANDROID_LOG_INFO;
- break;
- case LOG_WARNING:
- priority = ANDROID_LOG_WARN;
- break;
- case LOG_ERROR:
- priority = ANDROID_LOG_ERROR;
- break;
- case LOG_FATAL:
- priority = ANDROID_LOG_FATAL;
- break;
- }
- __android_log_write(priority, "chromium", str_newline.c_str());
-#endif
ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr));
fflush(stderr);
} else if (severity_ >= kAlwaysPrintErrorLevel) {
@@ -588,55 +164,18 @@
fflush(stderr);
}
- // write to log file
- if ((g_logging_destination & LOG_TO_FILE) != 0) {
- // We can have multiple threads and/or processes, so try to prevent them
- // from clobbering each other's writes.
- // If the client app did not call InitLogging, and the lock has not
- // been created do it now. We do this on demand, but if two threads try
- // to do this at the same time, there will be a race condition to create
- // the lock. This is why InitLogging should be called from the main
- // thread at the beginning of execution.
- LoggingLock::Init(LOCK_LOG_FILE, nullptr);
- LoggingLock logging_lock;
- if (InitializeLogFileHandle()) {
-#if defined(OS_WIN)
- SetFilePointer(g_log_file, 0, 0, SEEK_END);
- DWORD num_written;
- WriteFile(g_log_file,
- static_cast<const void*>(str_newline.c_str()),
- static_cast<DWORD>(str_newline.length()),
- &num_written,
- nullptr);
-#else
- ignore_result(fwrite(
- str_newline.data(), str_newline.size(), 1, g_log_file));
- fflush(g_log_file);
-#endif
- }
- }
-
if (severity_ == LOG_FATAL) {
// Ensure the first characters of the string are on the stack so they
// are contained in minidumps for diagnostic purposes.
char str_stack[1024];
str_newline.copy(str_stack, arraysize(str_stack));
- base::debug::Alias(str_stack);
if (log_assert_handler) {
// Make a copy of the string for the handler out of paranoia.
log_assert_handler(std::string(stream_.str()));
} else {
- // Don't use the string with the newline, get a fresh version to send to
- // the debug message process. We also don't display assertions to the
- // user in release mode. The enduser can't do anything with this
- // information, and displaying message boxes when the application is
- // hosed can cause additional problems.
-#ifndef NDEBUG
- DisplayDebugMessageInDialog(stream_.str());
-#endif
// Crash the process to generate a dump.
- base::debug::BreakDebugger();
+ abort();
}
}
}
@@ -651,10 +190,6 @@
// TODO(darin): It might be nice if the columns were fixed width.
stream_ << '[';
- if (g_log_process_id)
- stream_ << CurrentProcessId() << ':';
- if (g_log_thread_id)
- stream_ << base::PlatformThread::CurrentId() << ':';
if (g_log_timestamp) {
time_t t = time(nullptr);
struct tm local_time = {0};
@@ -673,8 +208,6 @@
<< std::setw(2) << tm_time->tm_sec
<< ':';
}
- if (g_log_tickcount)
- stream_ << TickCount() << ':';
if (severity_ >= 0)
stream_ << log_severity_name(severity_);
else
@@ -685,82 +218,6 @@
message_start_ = stream_.str().length();
}
-#if defined(OS_WIN)
-// This has already been defined in the header, but defining it again as DWORD
-// ensures that the type used in the header is equivalent to DWORD. If not,
-// the redefinition is a compile error.
-typedef DWORD SystemErrorCode;
-#endif
-
-SystemErrorCode GetLastSystemErrorCode() {
-#if defined(OS_WIN)
- return ::GetLastError();
-#elif defined(OS_POSIX)
- return errno;
-#else
-#error Not implemented
-#endif
-}
-
-#if defined(OS_WIN)
-BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) {
- const int kErrorMessageBufferSize = 256;
- char msgbuf[kErrorMessageBufferSize];
- DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
- DWORD len = FormatMessageA(flags, nullptr, error_code, 0, msgbuf,
- arraysize(msgbuf), nullptr);
- if (len) {
- // Messages returned by system end with line breaks.
- return base::CollapseWhitespaceASCII(msgbuf, true) +
- base::StringPrintf(" (0x%X)", error_code);
- }
- return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)",
- GetLastError(), error_code);
-}
-#elif defined(OS_POSIX)
-BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) {
- return base::safe_strerror(error_code);
-}
-#else
-#error Not implemented
-#endif // defined(OS_WIN)
-
-
-#if defined(OS_WIN)
-Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file,
- int line,
- LogSeverity severity,
- SystemErrorCode err)
- : err_(err),
- log_message_(file, line, severity) {
-}
-
-Win32ErrorLogMessage::~Win32ErrorLogMessage() {
- stream() << ": " << SystemErrorCodeToString(err_);
- // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
- // field) and use Alias in hopes that it makes it into crash dumps.
- DWORD last_error = err_;
- base::debug::Alias(&last_error);
-}
-#elif defined(OS_POSIX)
-ErrnoLogMessage::ErrnoLogMessage(const char* file,
- int line,
- LogSeverity severity,
- SystemErrorCode err)
- : err_(err),
- log_message_(file, line, severity) {
-}
-
-ErrnoLogMessage::~ErrnoLogMessage() {
- stream() << ": " << SystemErrorCodeToString(err_);
-}
-#endif // defined(OS_WIN)
-
-void CloseLogFile() {
- LoggingLock logging_lock;
- CloseLogFileUnlocked();
-}
-
void RawLog(int level, const char* message) {
if (level >= g_min_log_level) {
size_t bytes_written = 0;
@@ -789,27 +246,15 @@
}
if (level == LOG_FATAL)
- base::debug::BreakDebugger();
+ abort();
}
// This was defined at the beginning of this file.
#undef write
-#if defined(OS_WIN)
-std::wstring GetLogFileFullPath() {
- if (g_log_file_name)
- return *g_log_file_name;
- return std::wstring();
-}
-#endif
-
BASE_EXPORT void LogErrorNotReached(const char* file, int line) {
LogMessage(file, line, LOG_ERROR).stream()
<< "NOTREACHED() hit.";
}
} // namespace logging
-
-std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) {
- return out << base::WideToUTF8(wstr);
-}
diff --git a/libweave/external/base/logging.h b/libweave/external/base/logging.h
index ea096d1..34846fc 100644
--- a/libweave/external/base/logging.h
+++ b/libweave/external/base/logging.h
@@ -12,8 +12,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "base/debug/debugger.h"
-#include "build/build_config.h"
+#include "base/build/build_config.h"
//
// Optional message capabilities
@@ -114,18 +113,6 @@
//
// We also override the standard 'assert' to use 'DLOG_ASSERT'.
//
-// Lastly, there is:
-//
-// PLOG(ERROR) << "Couldn't do foo";
-// DPLOG(ERROR) << "Couldn't do foo";
-// PLOG_IF(ERROR, cond) << "Couldn't do foo";
-// DPLOG_IF(ERROR, cond) << "Couldn't do foo";
-// PCHECK(condition) << "Couldn't do foo";
-// DPCHECK(condition) << "Couldn't do foo";
-//
-// which append the last system error to the message in string form (taken from
-// GetLastError() on Windows and errno on POSIX).
-//
// The supported severity levels for macros that allow you to specify one
// are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.
//
@@ -137,61 +124,24 @@
namespace logging {
-// TODO(avi): do we want to do a unification of character types here?
-#if defined(OS_WIN)
-typedef wchar_t PathChar;
-#else
-typedef char PathChar;
-#endif
-
// Where to record logging output? A flat file and/or system debug log
// via OutputDebugString.
enum LoggingDestination {
LOG_NONE = 0,
- LOG_TO_FILE = 1 << 0,
LOG_TO_SYSTEM_DEBUG_LOG = 1 << 1,
- LOG_TO_ALL = LOG_TO_FILE | LOG_TO_SYSTEM_DEBUG_LOG,
+ LOG_TO_ALL = LOG_TO_SYSTEM_DEBUG_LOG,
- // On Windows, use a file next to the exe; on POSIX platforms, where
- // it may not even be possible to locate the executable on disk, use
- // stderr.
-#if defined(OS_WIN)
- LOG_DEFAULT = LOG_TO_FILE,
-#elif defined(OS_POSIX)
LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG,
-#endif
};
-// Indicates that the log file should be locked when being written to.
-// Unless there is only one single-threaded process that is logging to
-// the log file, the file should be locked during writes to make each
-// log output atomic. Other writers will block.
-//
-// All processes writing to the log file must have their locking set for it to
-// work properly. Defaults to LOCK_LOG_FILE.
-enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE };
-
-// On startup, should we delete or append to an existing log file (if any)?
-// Defaults to APPEND_TO_OLD_LOG_FILE.
-enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE };
-
struct BASE_EXPORT LoggingSettings {
// The defaults values are:
//
// logging_dest: LOG_DEFAULT
- // log_file: NULL
- // lock_log: LOCK_LOG_FILE
- // delete_old: APPEND_TO_OLD_LOG_FILE
LoggingSettings();
LoggingDestination logging_dest;
-
- // The three settings below have an effect only when LOG_TO_FILE is
- // set in |logging_dest|.
- const PathChar* log_file;
- LogLockingState lock_log;
- OldFileDeletionState delete_old;
};
// Define different names for the BaseInitLoggingImpl() function depending on
@@ -322,20 +272,6 @@
#define COMPACT_GOOGLE_LOG_DFATAL \
COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)
-#if defined(OS_WIN)
-// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
-// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
-// to keep using this syntax, we define this macro to do the same thing
-// as COMPACT_GOOGLE_LOG_ERROR, and also define ERROR the same way that
-// the Windows SDK does for consistency.
-#define ERROR 0
-#define COMPACT_GOOGLE_LOG_EX_0(ClassName, ...) \
- COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
-#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
-// Needed for LOG_IS_ON(ERROR).
-const LogSeverity LOG_0 = LOG_ERROR;
-#endif
-
// As special cases, we can assume that LOG_IS_ON(FATAL) always holds. Also,
// LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will
// always fire if they fail.
@@ -382,46 +318,11 @@
LAZY_STREAM(VLOG_STREAM(verbose_level), \
VLOG_IS_ON(verbose_level) && (condition))
-#if defined (OS_WIN)
-#define VPLOG_STREAM(verbose_level) \
- logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \
- ::logging::GetLastSystemErrorCode()).stream()
-#elif defined(OS_POSIX)
-#define VPLOG_STREAM(verbose_level) \
- logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \
- ::logging::GetLastSystemErrorCode()).stream()
-#endif
-
-#define VPLOG(verbose_level) \
- LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
-
-#define VPLOG_IF(verbose_level, condition) \
- LAZY_STREAM(VPLOG_STREAM(verbose_level), \
- VLOG_IS_ON(verbose_level) && (condition))
-
-// TODO(akalin): Add more VLOG variants, e.g. VPLOG.
-
#define LOG_ASSERT(condition) \
LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
#define SYSLOG_ASSERT(condition) \
SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
-#if defined(OS_WIN)
-#define PLOG_STREAM(severity) \
- COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
- ::logging::GetLastSystemErrorCode()).stream()
-#elif defined(OS_POSIX)
-#define PLOG_STREAM(severity) \
- COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \
- ::logging::GetLastSystemErrorCode()).stream()
-#endif
-
-#define PLOG(severity) \
- LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))
-
-#define PLOG_IF(severity, condition) \
- LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
-
// The actual stream used isn't important.
#define EAT_STREAM_PARAMETERS \
true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL)
@@ -450,36 +351,10 @@
#else
-#if defined(_PREFAST_) && defined(OS_WIN)
-// Use __analysis_assume to tell the VC++ static analysis engine that
-// assert conditions are true, to suppress warnings. The LAZY_STREAM
-// parameter doesn't reference 'condition' in /analyze builds because
-// this evaluation confuses /analyze. The !! before condition is because
-// __analysis_assume gets confused on some conditions:
-// http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugly-part-5/
-
-#define CHECK(condition) \
- __analysis_assume(!!(condition)), \
- LAZY_STREAM(LOG_STREAM(FATAL), false) \
- << "Check failed: " #condition ". "
-
-#define PCHECK(condition) \
- __analysis_assume(!!(condition)), \
- LAZY_STREAM(PLOG_STREAM(FATAL), false) \
- << "Check failed: " #condition ". "
-
-#else // _PREFAST_
-
#define CHECK(condition) \
LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \
<< "Check failed: " #condition ". "
-#define PCHECK(condition) \
- LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \
- << "Check failed: " #condition ". "
-
-#endif // _PREFAST_
-
// Helper macro for binary operators.
// Don't use this macro directly in your code, use CHECK_EQ et al below.
//
@@ -572,9 +447,7 @@
#define DLOG_IS_ON(severity) LOG_IS_ON(severity)
#define DLOG_IF(severity, condition) LOG_IF(severity, condition)
#define DLOG_ASSERT(condition) LOG_ASSERT(condition)
-#define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
#define DVLOG_IF(verboselevel, condition) VLOG_IF(verboselevel, condition)
-#define DVPLOG_IF(verboselevel, condition) VPLOG_IF(verboselevel, condition)
#else // ENABLE_DLOG
@@ -586,9 +459,7 @@
#define DLOG_IS_ON(severity) false
#define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
#define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS
-#define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
#define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS
-#define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS
#endif // ENABLE_DLOG
@@ -607,13 +478,8 @@
#define DLOG(severity) \
LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))
-#define DPLOG(severity) \
- LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
-
#define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
-#define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
-
// Definitions for DCHECK et al.
#if DCHECK_IS_ON()
@@ -638,31 +504,10 @@
// variable warnings if the only use of a variable is in a DCHECK.
// This behavior is different from DLOG_IF et al.
-#if defined(_PREFAST_) && defined(OS_WIN)
-// See comments on the previous use of __analysis_assume.
-
-#define DCHECK(condition) \
- __analysis_assume(!!(condition)), \
- LAZY_STREAM(LOG_STREAM(DCHECK), false) \
- << "Check failed: " #condition ". "
-
-#define DPCHECK(condition) \
- __analysis_assume(!!(condition)), \
- LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
- << "Check failed: " #condition ". "
-
-#else // _PREFAST_
-
#define DCHECK(condition) \
LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
<< "Check failed: " #condition ". "
-#define DPCHECK(condition) \
- LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
- << "Check failed: " #condition ". "
-
-#endif // _PREFAST_
-
// Helper macro for binary operators.
// Don't use this macro directly in your code, use DCHECK_EQ et al below.
#define DCHECK_OP(name, op, val1, val2) \
@@ -699,16 +544,7 @@
#define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2)
#define DCHECK_IMPLIES(val1, val2) DCHECK(!(val1) || (val2))
-#if !DCHECK_IS_ON() && defined(OS_CHROMEOS)
-// Implement logging of NOTREACHED() as a dedicated function to get function
-// call overhead down to a minimum.
-void LogErrorNotReached(const char* file, int line);
-#define NOTREACHED() \
- true ? ::logging::LogErrorNotReached(__FILE__, __LINE__) \
- : EAT_STREAM_PARAMETERS
-#else
#define NOTREACHED() DCHECK(false)
-#endif
// Redefine the standard assert to use our nice log files
#undef assert
@@ -750,26 +586,6 @@
const char* file_;
const int line_;
-#if defined(OS_WIN)
- // Stores the current value of GetLastError in the constructor and restores
- // it in the destructor by calling SetLastError.
- // This is useful since the LogMessage class uses a lot of Win32 calls
- // that will lose the value of GLE and the code that called the log function
- // will have lost the thread error value when the log call returns.
- class SaveLastError {
- public:
- SaveLastError();
- ~SaveLastError();
-
- unsigned long get_error() const { return last_error_; }
-
- protected:
- unsigned long last_error_;
- };
-
- SaveLastError last_error_;
-#endif
-
DISALLOW_COPY_AND_ASSIGN(LogMessage);
};
@@ -790,65 +606,6 @@
void operator&(std::ostream&) { }
};
-#if defined(OS_WIN)
-typedef unsigned long SystemErrorCode;
-#elif defined(OS_POSIX)
-typedef int SystemErrorCode;
-#endif
-
-// Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
-// pull in windows.h just for GetLastError() and DWORD.
-BASE_EXPORT SystemErrorCode GetLastSystemErrorCode();
-BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code);
-
-#if defined(OS_WIN)
-// Appends a formatted system message of the GetLastError() type.
-class BASE_EXPORT Win32ErrorLogMessage {
- public:
- Win32ErrorLogMessage(const char* file,
- int line,
- LogSeverity severity,
- SystemErrorCode err);
-
- // Appends the error message before destructing the encapsulated class.
- ~Win32ErrorLogMessage();
-
- std::ostream& stream() { return log_message_.stream(); }
-
- private:
- SystemErrorCode err_;
- LogMessage log_message_;
-
- DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
-};
-#elif defined(OS_POSIX)
-// Appends a formatted system message of the errno type
-class BASE_EXPORT ErrnoLogMessage {
- public:
- ErrnoLogMessage(const char* file,
- int line,
- LogSeverity severity,
- SystemErrorCode err);
-
- // Appends the error message before destructing the encapsulated class.
- ~ErrnoLogMessage();
-
- std::ostream& stream() { return log_message_.stream(); }
-
- private:
- SystemErrorCode err_;
- LogMessage log_message_;
-
- DISALLOW_COPY_AND_ASSIGN(ErrnoLogMessage);
-};
-#endif // OS_WIN
-
-// Closes the log file explicitly if open.
-// NOTE: Since the log file is opened as necessary by the action of logging
-// statements, there's no guarantee that it will stay closed
-// after this call.
-BASE_EXPORT void CloseLogFile();
-
// Async signal safe logging mechanism.
BASE_EXPORT void RawLog(int level, const char* message);
@@ -860,34 +617,9 @@
logging::RawLog(logging::LOG_FATAL, "Check failed: " #condition "\n"); \
} while (0)
-#if defined(OS_WIN)
-// Returns the default log file path.
-BASE_EXPORT std::wstring GetLogFileFullPath();
-#endif
} // namespace logging
-// Note that "The behavior of a C++ program is undefined if it adds declarations
-// or definitions to namespace std or to a namespace within namespace std unless
-// otherwise specified." --C++11[namespace.std]
-//
-// We've checked that this particular definition has the intended behavior on
-// our implementations, but it's prone to breaking in the future, and please
-// don't imitate this in your own definitions without checking with some
-// standard library experts.
-namespace std {
-// These functions are provided as a convenience for logging, which is where we
-// use streams (it is against Google style to use streams in other places). It
-// is designed to allow you to emit non-ASCII Unicode strings to the log file,
-// which is normally ASCII. It is relatively slow, so try not to use it for
-// common cases. Non-ASCII characters will be converted to UTF-8 by these
-// operators.
-BASE_EXPORT std::ostream& operator<<(std::ostream& out, const wchar_t* wstr);
-inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
- return out << wstr.c_str();
-}
-} // namespace std
-
// The NOTIMPLEMENTED() macro annotates codepaths which have
// not been implemented yet.
//
@@ -900,13 +632,9 @@
// 5 -- LOG(ERROR) at runtime, only once per call-site
#ifndef NOTIMPLEMENTED_POLICY
-#if defined(OS_ANDROID) && defined(OFFICIAL_BUILD)
-#define NOTIMPLEMENTED_POLICY 0
-#else
// Select default policy: LOG(ERROR)
#define NOTIMPLEMENTED_POLICY 4
#endif
-#endif
#if defined(COMPILER_GCC)
// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
diff --git a/libweave/external/base/logging_unittest.cc b/libweave/external/base/logging_unittest.cc
index 8b9701a..d51015d 100644
--- a/libweave/external/base/logging_unittest.cc
+++ b/libweave/external/base/logging_unittest.cc
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
#include "base/logging.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
namespace logging {
@@ -54,7 +55,7 @@
TEST_F(LoggingTest, BasicLogging) {
MockLogSource mock_log_source;
- EXPECT_CALL(mock_log_source, Log()).Times(DEBUG_MODE ? 16 : 8).
+ EXPECT_CALL(mock_log_source, Log()).
WillRepeatedly(Return("log message"));
SetMinLogLevel(LOG_INFO);
@@ -68,21 +69,13 @@
LOG(INFO) << mock_log_source.Log();
LOG_IF(INFO, true) << mock_log_source.Log();
- PLOG(INFO) << mock_log_source.Log();
- PLOG_IF(INFO, true) << mock_log_source.Log();
VLOG(0) << mock_log_source.Log();
VLOG_IF(0, true) << mock_log_source.Log();
- VPLOG(0) << mock_log_source.Log();
- VPLOG_IF(0, true) << mock_log_source.Log();
DLOG(INFO) << mock_log_source.Log();
DLOG_IF(INFO, true) << mock_log_source.Log();
- DPLOG(INFO) << mock_log_source.Log();
- DPLOG_IF(INFO, true) << mock_log_source.Log();
DVLOG(0) << mock_log_source.Log();
DVLOG_IF(0, true) << mock_log_source.Log();
- DVPLOG(0) << mock_log_source.Log();
- DVPLOG_IF(0, true) << mock_log_source.Log();
}
TEST_F(LoggingTest, LogIsOn) {
@@ -134,21 +127,13 @@
LOG(INFO) << mock_log_source.Log();
LOG_IF(INFO, false) << mock_log_source.Log();
- PLOG(INFO) << mock_log_source.Log();
- PLOG_IF(INFO, false) << mock_log_source.Log();
VLOG(1) << mock_log_source.Log();
VLOG_IF(1, true) << mock_log_source.Log();
- VPLOG(1) << mock_log_source.Log();
- VPLOG_IF(1, true) << mock_log_source.Log();
DLOG(INFO) << mock_log_source.Log();
DLOG_IF(INFO, true) << mock_log_source.Log();
- DPLOG(INFO) << mock_log_source.Log();
- DPLOG_IF(INFO, true) << mock_log_source.Log();
DVLOG(1) << mock_log_source.Log();
DVLOG_IF(1, true) << mock_log_source.Log();
- DVPLOG(1) << mock_log_source.Log();
- DVPLOG_IF(1, true) << mock_log_source.Log();
}
// Official builds have CHECKs directly call BreakDebugger.
@@ -156,14 +141,13 @@
TEST_F(LoggingTest, CheckStreamsAreLazy) {
MockLogSource mock_log_source, uncalled_mock_log_source;
- EXPECT_CALL(mock_log_source, Log()).Times(8).
+ EXPECT_CALL(mock_log_source, Log()).
WillRepeatedly(Return("check message"));
EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0);
SetLogAssertHandler(&LogSink);
CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
- PCHECK(!mock_log_source.Log()) << mock_log_source.Log();
CHECK_EQ(mock_log_source.Log(), mock_log_source.Log())
<< uncalled_mock_log_source.Log();
CHECK_NE(mock_log_source.Log(), mock_log_source.Log())
@@ -180,7 +164,6 @@
// in release mode.
DLOG_IF(INFO, debug_only_variable) << "test";
DLOG_ASSERT(debug_only_variable) << "test";
- DPLOG_IF(INFO, debug_only_variable) << "test";
DVLOG_IF(1, debug_only_variable) << "test";
}
@@ -219,10 +202,8 @@
EXPECT_EQ(0, log_sink_call_count);
DCHECK(false);
EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
- DPCHECK(false);
- EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
DCHECK_EQ(0, 1);
- EXPECT_EQ(DCHECK_IS_ON() ? 3 : 0, log_sink_call_count);
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
}
TEST_F(LoggingTest, DcheckReleaseBehavior) {
@@ -230,29 +211,9 @@
// These should still reference |some_variable| so we don't get
// unused variable warnings.
DCHECK(some_variable) << "test";
- DPCHECK(some_variable) << "test";
DCHECK_EQ(some_variable, 1) << "test";
}
-// Test that defining an operator<< for a type in a namespace doesn't prevent
-// other code in that namespace from calling the operator<<(ostream, wstring)
-// defined by logging.h. This can fail if operator<<(ostream, wstring) can't be
-// found by ADL, since defining another operator<< prevents name lookup from
-// looking in the global namespace.
-namespace nested_test {
- class Streamable {};
- ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out,
- const Streamable&) {
- return out << "Streamable";
- }
- TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) {
- std::wstring wstr = L"Hello World";
- std::ostringstream ostr;
- ostr << wstr;
- EXPECT_EQ("Hello World", ostr.str());
- }
-} // namespace nested_test
-
} // namespace
} // namespace logging
diff --git a/libweave/external/base/memory/ref_counted.cc b/libweave/external/base/memory/ref_counted.cc
index f5924d0..4a20cb6 100644
--- a/libweave/external/base/memory/ref_counted.cc
+++ b/libweave/external/base/memory/ref_counted.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_collision_warner.h"
namespace base {
diff --git a/libweave/external/base/memory/ref_counted.h b/libweave/external/base/memory/ref_counted.h
index 5f94b4c..ee5f58b 100644
--- a/libweave/external/base/memory/ref_counted.h
+++ b/libweave/external/base/memory/ref_counted.h
@@ -10,13 +10,10 @@
#include "base/atomic_ref_count.h"
#include "base/base_export.h"
+#include "base/build/build_config.h"
#include "base/compiler_specific.h"
-#ifndef NDEBUG
#include "base/logging.h"
-#endif
#include "base/move.h"
-#include "base/threading/thread_collision_warner.h"
-#include "build/build_config.h"
namespace base {
@@ -43,10 +40,6 @@
void AddRef() const {
- // TODO(maruel): Add back once it doesn't assert 500 times/sec.
- // Current thread books the critical section "AddRelease"
- // without release it.
- // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
@@ -55,10 +48,6 @@
// Returns true if the object should self-delete.
bool Release() const {
- // TODO(maruel): Add back once it doesn't assert 500 times/sec.
- // Current thread books the critical section "AddRelease"
- // without release it.
- // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
@@ -77,8 +66,6 @@
mutable bool in_dtor_;
#endif
- DFAKE_MUTEX(add_release_);
-
DISALLOW_COPY_AND_ASSIGN(RefCountedBase);
};
diff --git a/libweave/external/base/memory/ref_counted_unittest.cc b/libweave/external/base/memory/ref_counted_unittest.cc
index 6f8e599..9eda813 100644
--- a/libweave/external/base/memory/ref_counted_unittest.cc
+++ b/libweave/external/base/memory/ref_counted_unittest.cc
@@ -4,8 +4,7 @@
#include "base/memory/ref_counted.h"
-#include "base/test/opaque_ref_counted.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include <gtest/gtest.h>
namespace {
@@ -139,16 +138,6 @@
EXPECT_TRUE(ScopedRefPtrToSelf::was_destroyed());
}
-TEST(RefCountedUnitTest, ScopedRefPtrToOpaque) {
- scoped_refptr<base::OpaqueRefCounted> p = base::MakeOpaqueRefCounted();
- base::TestOpaqueRefCounted(p);
-
- scoped_refptr<base::OpaqueRefCounted> q;
- q = p;
- base::TestOpaqueRefCounted(p);
- base::TestOpaqueRefCounted(q);
-}
-
TEST(RefCountedUnitTest, BooleanTesting) {
scoped_refptr<SelfAssign> p;
EXPECT_FALSE(p);
diff --git a/libweave/external/base/memory/scoped_ptr.h b/libweave/external/base/memory/scoped_ptr.h
index 987ccfa..2aa1b32 100644
--- a/libweave/external/base/memory/scoped_ptr.h
+++ b/libweave/external/base/memory/scoped_ptr.h
@@ -120,7 +120,7 @@
// cannot convert to T*.
enum { T_must_be_complete = sizeof(T) };
enum { U_must_be_complete = sizeof(U) };
- COMPILE_ASSERT((base::is_convertible<U*, T*>::value),
+ COMPILE_ASSERT((std::is_convertible<U*, T*>::value),
U_ptr_must_implicitly_convert_to_T_ptr);
}
inline void operator()(T* ptr) const {
@@ -169,8 +169,8 @@
template <typename T> struct IsNotRefCounted {
enum {
- value = !base::is_convertible<T*, base::subtle::RefCountedBase*>::value &&
- !base::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>::
+ value = !std::is_convertible<T*, base::subtle::RefCountedBase*>::value &&
+ !std::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>::
value
};
};
@@ -345,7 +345,7 @@
template <typename U, typename V>
scoped_ptr(scoped_ptr<U, V>&& other)
: impl_(&other.impl_) {
- COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array);
+ COMPILE_ASSERT(!std::is_array<U>::value, U_cannot_be_an_array);
}
// operator=. Allows assignment from a scoped_ptr rvalue for a convertible
@@ -360,7 +360,7 @@
// scoped_ptr.
template <typename U, typename V>
scoped_ptr& operator=(scoped_ptr<U, V>&& rhs) {
- COMPILE_ASSERT(!base::is_array<U>::value, U_cannot_be_an_array);
+ COMPILE_ASSERT(!std::is_array<U>::value, U_cannot_be_an_array);
impl_.TakeState(&rhs.impl_);
return *this;
}
diff --git a/libweave/external/base/memory/scoped_ptr_unittest.cc b/libweave/external/base/memory/scoped_ptr_unittest.cc
index 766f444..d4ff410 100644
--- a/libweave/external/base/memory/scoped_ptr_unittest.cc
+++ b/libweave/external/base/memory/scoped_ptr_unittest.cc
@@ -6,10 +6,11 @@
#include <sstream>
+#include <gtest/gtest.h>
+
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace {
diff --git a/libweave/external/base/memory/weak_ptr.cc b/libweave/external/base/memory/weak_ptr.cc
index d9ce86a..0f91ef3 100644
--- a/libweave/external/base/memory/weak_ptr.cc
+++ b/libweave/external/base/memory/weak_ptr.cc
@@ -8,23 +8,13 @@
namespace internal {
WeakReference::Flag::Flag() : is_valid_(true) {
- // Flags only become bound when checked for validity, or invalidated,
- // so that we can check that later validity/invalidation operations on
- // the same Flag take place on the same sequenced thread.
- sequence_checker_.DetachFromSequence();
}
void WeakReference::Flag::Invalidate() {
- // The flag being invalidated with a single ref implies that there are no
- // weak pointers in existence. Allow deletion on other thread in this case.
- DCHECK(sequence_checker_.CalledOnValidSequencedThread() || HasOneRef())
- << "WeakPtrs must be invalidated on the same sequenced thread.";
is_valid_ = false;
}
bool WeakReference::Flag::IsValid() const {
- DCHECK(sequence_checker_.CalledOnValidSequencedThread())
- << "WeakPtrs must be checked on the same sequenced thread.";
return is_valid_;
}
diff --git a/libweave/external/base/memory/weak_ptr.h b/libweave/external/base/memory/weak_ptr.h
index 8a43392..4c1fd4a 100644
--- a/libweave/external/base/memory/weak_ptr.h
+++ b/libweave/external/base/memory/weak_ptr.h
@@ -68,8 +68,6 @@
#include "base/base_export.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/sequence_checker.h"
-#include "base/template_util.h"
namespace base {
@@ -96,7 +94,6 @@
~Flag();
- SequenceChecker sequence_checker_;
bool is_valid_;
};
@@ -153,8 +150,8 @@
// function that makes calling this easier.
template<typename Derived>
static WeakPtr<Derived> StaticAsWeakPtr(Derived* t) {
- typedef
- is_convertible<Derived, internal::SupportsWeakPtrBase&> convertible;
+ typedef std::is_convertible<Derived*, internal::SupportsWeakPtrBase*>
+ convertible;
COMPILE_ASSERT(convertible::value,
AsWeakPtr_argument_inherits_from_SupportsWeakPtr);
return AsWeakPtrImpl<Derived>(t, *t);
diff --git a/libweave/external/base/memory/weak_ptr_unittest.cc b/libweave/external/base/memory/weak_ptr_unittest.cc
index 20e5c7b..8d4057c 100644
--- a/libweave/external/base/memory/weak_ptr_unittest.cc
+++ b/libweave/external/base/memory/weak_ptr_unittest.cc
@@ -6,38 +6,15 @@
#include <string>
+#include <gtest/gtest.h>
+
#include "base/bind.h"
-#include "base/debug/leak_annotations.h"
#include "base/location.h"
#include "base/memory/scoped_ptr.h"
-#include "base/single_thread_task_runner.h"
-#include "base/synchronization/waitable_event.h"
-#include "base/threading/thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
-template <class T>
-class OffThreadObjectCreator {
- public:
- static T* NewObject() {
- T* result;
- {
- Thread creator_thread("creator_thread");
- creator_thread.Start();
- creator_thread.task_runner()->PostTask(
- FROM_HERE, base::Bind(OffThreadObjectCreator::CreateObject, &result));
- }
- DCHECK(result); // We synchronized on thread destruction above.
- return result;
- }
- private:
- static void CreateObject(T** result) {
- *result = new T;
- }
-};
-
struct Base {
std::string member;
};
@@ -56,125 +33,6 @@
WeakPtrFactory<Target> factory;
};
-// Helper class to create and destroy weak pointer copies
-// and delete objects on a background thread.
-class BackgroundThread : public Thread {
- public:
- BackgroundThread() : Thread("owner_thread") {}
-
- ~BackgroundThread() override { Stop(); }
-
- void CreateArrowFromTarget(Arrow** arrow, Target* target) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE, base::Bind(&BackgroundThread::DoCreateArrowFromTarget, arrow,
- target, &completion));
- completion.Wait();
- }
-
- void CreateArrowFromArrow(Arrow** arrow, const Arrow* other) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE, base::Bind(&BackgroundThread::DoCreateArrowFromArrow, arrow,
- other, &completion));
- completion.Wait();
- }
-
- void DeleteTarget(Target* object) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&BackgroundThread::DoDeleteTarget, object, &completion));
- completion.Wait();
- }
-
- void CopyAndAssignArrow(Arrow* object) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE, base::Bind(&BackgroundThread::DoCopyAndAssignArrow, object,
- &completion));
- completion.Wait();
- }
-
- void CopyAndAssignArrowBase(Arrow* object) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE, base::Bind(&BackgroundThread::DoCopyAndAssignArrowBase,
- object, &completion));
- completion.Wait();
- }
-
- void DeleteArrow(Arrow* object) {
- WaitableEvent completion(true, false);
- task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&BackgroundThread::DoDeleteArrow, object, &completion));
- completion.Wait();
- }
-
- Target* DeRef(const Arrow* arrow) {
- WaitableEvent completion(true, false);
- Target* result = NULL;
- task_runner()->PostTask(FROM_HERE, base::Bind(&BackgroundThread::DoDeRef,
- arrow, &result, &completion));
- completion.Wait();
- return result;
- }
-
- protected:
- static void DoCreateArrowFromArrow(Arrow** arrow,
- const Arrow* other,
- WaitableEvent* completion) {
- *arrow = new Arrow;
- **arrow = *other;
- completion->Signal();
- }
-
- static void DoCreateArrowFromTarget(Arrow** arrow,
- Target* target,
- WaitableEvent* completion) {
- *arrow = new Arrow;
- (*arrow)->target = target->AsWeakPtr();
- completion->Signal();
- }
-
- static void DoDeRef(const Arrow* arrow,
- Target** result,
- WaitableEvent* completion) {
- *result = arrow->target.get();
- completion->Signal();
- }
-
- static void DoDeleteTarget(Target* object, WaitableEvent* completion) {
- delete object;
- completion->Signal();
- }
-
- static void DoCopyAndAssignArrow(Arrow* object, WaitableEvent* completion) {
- // Copy constructor.
- Arrow a = *object;
- // Assignment operator.
- *object = a;
- completion->Signal();
- }
-
- static void DoCopyAndAssignArrowBase(
- Arrow* object,
- WaitableEvent* completion) {
- // Copy constructor.
- WeakPtr<TargetBase> b = object->target;
- // Assignment operator.
- WeakPtr<TargetBase> c;
- c = object->target;
- completion->Signal();
- }
-
- static void DoDeleteArrow(Arrow* object, WaitableEvent* completion) {
- delete object;
- completion->Signal();
- }
-};
-
} // namespace
TEST(WeakPtrFactoryTest, Basic) {
@@ -292,320 +150,4 @@
EXPECT_FALSE(factory.HasWeakPtrs());
}
-TEST(WeakPtrTest, ObjectAndWeakPtrOnDifferentThreads) {
- // Test that it is OK to create an object that supports WeakPtr on one thread,
- // but use it on another. This tests that we do not trip runtime checks that
- // ensure that a WeakPtr is not used by multiple threads.
- scoped_ptr<Target> target(OffThreadObjectCreator<Target>::NewObject());
- WeakPtr<Target> weak_ptr = target->AsWeakPtr();
- EXPECT_EQ(target.get(), weak_ptr.get());
-}
-
-TEST(WeakPtrTest, WeakPtrInitiateAndUseOnDifferentThreads) {
- // Test that it is OK to create an object that has a WeakPtr member on one
- // thread, but use it on another. This tests that we do not trip runtime
- // checks that ensure that a WeakPtr is not used by multiple threads.
- scoped_ptr<Arrow> arrow(OffThreadObjectCreator<Arrow>::NewObject());
- Target target;
- arrow->target = target.AsWeakPtr();
- EXPECT_EQ(&target, arrow->target.get());
-}
-
-TEST(WeakPtrTest, MoveOwnershipImplicitly) {
- // Move object ownership to another thread by releasing all weak pointers
- // on the original thread first, and then establish WeakPtr on a different
- // thread.
- BackgroundThread background;
- background.Start();
-
- Target* target = new Target();
- {
- WeakPtr<Target> weak_ptr = target->AsWeakPtr();
- // Main thread deletes the WeakPtr, then the thread ownership of the
- // object can be implicitly moved.
- }
- Arrow* arrow;
-
- // Background thread creates WeakPtr(and implicitly owns the object).
- background.CreateArrowFromTarget(&arrow, target);
- EXPECT_EQ(background.DeRef(arrow), target);
-
- {
- // Main thread creates another WeakPtr, but this does not trigger implicitly
- // thread ownership move.
- Arrow arrow;
- arrow.target = target->AsWeakPtr();
-
- // The new WeakPtr is owned by background thread.
- EXPECT_EQ(target, background.DeRef(&arrow));
- }
-
- // Target can only be deleted on background thread.
- background.DeleteTarget(target);
- background.DeleteArrow(arrow);
-}
-
-TEST(WeakPtrTest, MoveOwnershipOfUnreferencedObject) {
- BackgroundThread background;
- background.Start();
-
- Arrow* arrow;
- {
- Target target;
- // Background thread creates WeakPtr.
- background.CreateArrowFromTarget(&arrow, &target);
-
- // Bind to background thread.
- EXPECT_EQ(&target, background.DeRef(arrow));
-
- // Release the only WeakPtr.
- arrow->target.reset();
-
- // Now we should be able to create a new reference from this thread.
- arrow->target = target.AsWeakPtr();
-
- // Re-bind to main thread.
- EXPECT_EQ(&target, arrow->target.get());
-
- // And the main thread can now delete the target.
- }
-
- delete arrow;
-}
-
-TEST(WeakPtrTest, MoveOwnershipAfterInvalidate) {
- BackgroundThread background;
- background.Start();
-
- Arrow arrow;
- scoped_ptr<TargetWithFactory> target(new TargetWithFactory);
-
- // Bind to main thread.
- arrow.target = target->factory.GetWeakPtr();
- EXPECT_EQ(target.get(), arrow.target.get());
-
- target->factory.InvalidateWeakPtrs();
- EXPECT_EQ(NULL, arrow.target.get());
-
- arrow.target = target->factory.GetWeakPtr();
- // Re-bind to background thread.
- EXPECT_EQ(target.get(), background.DeRef(&arrow));
-
- // And the background thread can now delete the target.
- background.DeleteTarget(target.release());
-}
-
-TEST(WeakPtrTest, MainThreadRefOutlivesBackgroundThreadRef) {
- // Originating thread has a WeakPtr that outlives others.
- // - Main thread creates a WeakPtr
- // - Background thread creates a WeakPtr copy from the one in main thread
- // - Destruct the WeakPtr on background thread
- // - Destruct the WeakPtr on main thread
- BackgroundThread background;
- background.Start();
-
- Target target;
- Arrow arrow;
- arrow.target = target.AsWeakPtr();
-
- Arrow* arrow_copy;
- background.CreateArrowFromArrow(&arrow_copy, &arrow);
- EXPECT_EQ(arrow_copy->target.get(), &target);
- background.DeleteArrow(arrow_copy);
-}
-
-TEST(WeakPtrTest, BackgroundThreadRefOutlivesMainThreadRef) {
- // Originating thread drops all references before another thread.
- // - Main thread creates a WeakPtr and passes copy to background thread
- // - Destruct the pointer on main thread
- // - Destruct the pointer on background thread
- BackgroundThread background;
- background.Start();
-
- Target target;
- Arrow* arrow_copy;
- {
- Arrow arrow;
- arrow.target = target.AsWeakPtr();
- background.CreateArrowFromArrow(&arrow_copy, &arrow);
- }
- EXPECT_EQ(arrow_copy->target.get(), &target);
- background.DeleteArrow(arrow_copy);
-}
-
-TEST(WeakPtrTest, OwnerThreadDeletesObject) {
- // Originating thread invalidates WeakPtrs while its held by other thread.
- // - Main thread creates WeakPtr and passes Copy to background thread
- // - Object gets destroyed on main thread
- // (invalidates WeakPtr on background thread)
- // - WeakPtr gets destroyed on Thread B
- BackgroundThread background;
- background.Start();
- Arrow* arrow_copy;
- {
- Target target;
- Arrow arrow;
- arrow.target = target.AsWeakPtr();
- background.CreateArrowFromArrow(&arrow_copy, &arrow);
- }
- EXPECT_EQ(NULL, arrow_copy->target.get());
- background.DeleteArrow(arrow_copy);
-}
-
-TEST(WeakPtrTest, NonOwnerThreadCanCopyAndAssignWeakPtr) {
- // Main thread creates a Target object.
- Target target;
- // Main thread creates an arrow referencing the Target.
- Arrow *arrow = new Arrow();
- arrow->target = target.AsWeakPtr();
-
- // Background can copy and assign arrow (as well as the WeakPtr inside).
- BackgroundThread background;
- background.Start();
- background.CopyAndAssignArrow(arrow);
- background.DeleteArrow(arrow);
-}
-
-TEST(WeakPtrTest, NonOwnerThreadCanCopyAndAssignWeakPtrBase) {
- // Main thread creates a Target object.
- Target target;
- // Main thread creates an arrow referencing the Target.
- Arrow *arrow = new Arrow();
- arrow->target = target.AsWeakPtr();
-
- // Background can copy and assign arrow's WeakPtr to a base class WeakPtr.
- BackgroundThread background;
- background.Start();
- background.CopyAndAssignArrowBase(arrow);
- background.DeleteArrow(arrow);
-}
-
-TEST(WeakPtrTest, NonOwnerThreadCanDeleteWeakPtr) {
- // Main thread creates a Target object.
- Target target;
- // Main thread creates an arrow referencing the Target.
- Arrow* arrow = new Arrow();
- arrow->target = target.AsWeakPtr();
-
- // Background can delete arrow (as well as the WeakPtr inside).
- BackgroundThread background;
- background.Start();
- background.DeleteArrow(arrow);
-}
-
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST
-
-TEST(WeakPtrDeathTest, WeakPtrCopyDoesNotChangeThreadBinding) {
- // The default style "fast" does not support multi-threaded tests
- // (introduces deadlock on Linux).
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-
- BackgroundThread background;
- background.Start();
-
- // Main thread creates a Target object.
- Target target;
- // Main thread creates an arrow referencing the Target.
- Arrow arrow;
- arrow.target = target.AsWeakPtr();
-
- // Background copies the WeakPtr.
- Arrow* arrow_copy;
- background.CreateArrowFromArrow(&arrow_copy, &arrow);
-
- // The copy is still bound to main thread so I can deref.
- EXPECT_EQ(arrow.target.get(), arrow_copy->target.get());
-
- // Although background thread created the copy, it can not deref the copied
- // WeakPtr.
- ASSERT_DEATH(background.DeRef(arrow_copy), "");
-
- background.DeleteArrow(arrow_copy);
-}
-
-TEST(WeakPtrDeathTest, NonOwnerThreadDereferencesWeakPtrAfterReference) {
- // The default style "fast" does not support multi-threaded tests
- // (introduces deadlock on Linux).
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-
- // Main thread creates a Target object.
- Target target;
-
- // Main thread creates an arrow referencing the Target (so target's
- // thread ownership can not be implicitly moved).
- Arrow arrow;
- arrow.target = target.AsWeakPtr();
- arrow.target.get();
-
- // Background thread tries to deref target, which violates thread ownership.
- BackgroundThread background;
- background.Start();
- ASSERT_DEATH(background.DeRef(&arrow), "");
-}
-
-TEST(WeakPtrDeathTest, NonOwnerThreadDeletesWeakPtrAfterReference) {
- // The default style "fast" does not support multi-threaded tests
- // (introduces deadlock on Linux).
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-
- scoped_ptr<Target> target(new Target());
-
- // Main thread creates an arrow referencing the Target.
- Arrow arrow;
- arrow.target = target->AsWeakPtr();
-
- // Background thread tries to deref target, binding it to the thread.
- BackgroundThread background;
- background.Start();
- background.DeRef(&arrow);
-
- // Main thread deletes Target, violating thread binding.
- ASSERT_DEATH(target.reset(), "");
-
- // |target.reset()| died so |target| still holds the object, so we
- // must pass it to the background thread to teardown.
- background.DeleteTarget(target.release());
-}
-
-TEST(WeakPtrDeathTest, NonOwnerThreadDeletesObjectAfterReference) {
- // The default style "fast" does not support multi-threaded tests
- // (introduces deadlock on Linux).
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-
- scoped_ptr<Target> target(new Target());
-
- // Main thread creates an arrow referencing the Target, and references it, so
- // that it becomes bound to the thread.
- Arrow arrow;
- arrow.target = target->AsWeakPtr();
- arrow.target.get();
-
- // Background thread tries to delete target, volating thread binding.
- BackgroundThread background;
- background.Start();
- ASSERT_DEATH(background.DeleteTarget(target.release()), "");
-}
-
-TEST(WeakPtrDeathTest, NonOwnerThreadReferencesObjectAfterDeletion) {
- // The default style "fast" does not support multi-threaded tests
- // (introduces deadlock on Linux).
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
-
- scoped_ptr<Target> target(new Target());
-
- // Main thread creates an arrow referencing the Target.
- Arrow arrow;
- arrow.target = target->AsWeakPtr();
-
- // Background thread tries to delete target, binding the object to the thread.
- BackgroundThread background;
- background.Start();
- background.DeleteTarget(target.release());
-
- // Main thread attempts to dereference the target, violating thread binding.
- ASSERT_DEATH(arrow.target.get(), "");
-}
-
-#endif
-
} // namespace base
diff --git a/libweave/external/base/move_unittest.cc b/libweave/external/base/move_unittest.cc
index 1f4ce84..bebcfd8 100644
--- a/libweave/external/base/move_unittest.cc
+++ b/libweave/external/base/move_unittest.cc
@@ -4,7 +4,7 @@
#include "base/move.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include <gtest/gtest.h>
namespace {
diff --git a/libweave/external/base/numerics/safe_conversions_impl.h b/libweave/external/base/numerics/safe_conversions_impl.h
index 4157067..d07221e 100644
--- a/libweave/external/base/numerics/safe_conversions_impl.h
+++ b/libweave/external/base/numerics/safe_conversions_impl.h
@@ -7,8 +7,6 @@
#include <limits>
-#include "base/template_util.h"
-
namespace base {
namespace internal {
diff --git a/libweave/external/base/numerics/safe_math.h b/libweave/external/base/numerics/safe_math.h
index 1fab032..a596d4b 100644
--- a/libweave/external/base/numerics/safe_math.h
+++ b/libweave/external/base/numerics/safe_math.h
@@ -173,15 +173,15 @@
template <typename Src>
static CheckedNumeric<T> cast(
Src u,
- typename enable_if<std::numeric_limits<Src>::is_specialized, int>::type =
- 0) {
+ typename std::enable_if<std::numeric_limits<Src>::is_specialized,
+ int>::type = 0) {
return u;
}
template <typename Src>
static CheckedNumeric<T> cast(
const CheckedNumeric<Src>& u,
- typename enable_if<!is_same<Src, T>::value, int>::type = 0) {
+ typename std::enable_if<!std::is_same<Src, T>::value, int>::type = 0) {
return u;
}
diff --git a/libweave/external/base/numerics/safe_math_impl.h b/libweave/external/base/numerics/safe_math_impl.h
index 08f2e88..0ae1dfe 100644
--- a/libweave/external/base/numerics/safe_math_impl.h
+++ b/libweave/external/base/numerics/safe_math_impl.h
@@ -12,7 +12,6 @@
#include <limits>
#include "base/numerics/safe_conversions.h"
-#include "base/template_util.h"
namespace base {
namespace internal {
@@ -63,21 +62,21 @@
template <typename Integer>
struct UnsignedIntegerForSize {
- typedef typename enable_if<
+ typedef typename std::enable_if<
std::numeric_limits<Integer>::is_integer,
typename IntegerForSizeAndSign<sizeof(Integer), false>::type>::type type;
};
template <typename Integer>
struct SignedIntegerForSize {
- typedef typename enable_if<
+ typedef typename std::enable_if<
std::numeric_limits<Integer>::is_integer,
typename IntegerForSizeAndSign<sizeof(Integer), true>::type>::type type;
};
template <typename Integer>
struct TwiceWiderInteger {
- typedef typename enable_if<
+ typedef typename std::enable_if<
std::numeric_limits<Integer>::is_integer,
typename IntegerForSizeAndSign<
sizeof(Integer) * 2,
@@ -86,7 +85,7 @@
template <typename Integer>
struct PositionOfSignBit {
- static const typename enable_if<std::numeric_limits<Integer>::is_integer,
+ static const typename std::enable_if<std::numeric_limits<Integer>::is_integer,
size_t>::type value = 8 * sizeof(Integer) - 1;
};
@@ -110,7 +109,7 @@
// way to coalesce things into the CheckedNumericState specializations below.
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_integer, T>::type
+typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type
CheckedAdd(T x, T y, RangeConstraint* validity) {
// Since the value of x+y is undefined if we have a signed type, we compute
// it using the unsigned type of the same size.
@@ -133,7 +132,7 @@
}
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_integer, T>::type
+typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type
CheckedSub(T x, T y, RangeConstraint* validity) {
// Since the value of x+y is undefined if we have a signed type, we compute
// it using the unsigned type of the same size.
@@ -160,7 +159,7 @@
// slow case we need to manually check that the result won't be truncated by
// checking with division against the appropriate bound.
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer && sizeof(T) * 2 <= sizeof(uintmax_t),
T>::type
CheckedMul(T x, T y, RangeConstraint* validity) {
@@ -172,9 +171,10 @@
}
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_integer&& std::numeric_limits<
- T>::is_signed&&(sizeof(T) * 2 > sizeof(uintmax_t)),
- T>::type
+typename std::enable_if<std::numeric_limits<T>::is_integer &&
+ std::numeric_limits<T>::is_signed &&
+ (sizeof(T) * 2 > sizeof(uintmax_t)),
+ T>::type
CheckedMul(T x, T y, RangeConstraint* validity) {
// If either side is zero then the result will be zero.
if (!x || !y) {
@@ -201,7 +201,7 @@
}
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_integer &&
+typename std::enable_if<std::numeric_limits<T>::is_integer &&
!std::numeric_limits<T>::is_signed &&
(sizeof(T) * 2 > sizeof(uintmax_t)),
T>::type
@@ -214,11 +214,11 @@
// Division just requires a check for an invalid negation on signed min/-1.
template <typename T>
-T CheckedDiv(
- T x,
- T y,
- RangeConstraint* validity,
- typename enable_if<std::numeric_limits<T>::is_integer, int>::type = 0) {
+T CheckedDiv(T x,
+ T y,
+ RangeConstraint* validity,
+ typename std::enable_if<std::numeric_limits<T>::is_integer,
+ int>::type = 0) {
if (std::numeric_limits<T>::is_signed && x == std::numeric_limits<T>::min() &&
y == static_cast<T>(-1)) {
*validity = RANGE_OVERFLOW;
@@ -230,7 +230,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer&& std::numeric_limits<T>::is_signed,
T>::type
CheckedMod(T x, T y, RangeConstraint* validity) {
@@ -239,7 +239,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed,
T>::type
CheckedMod(T x, T y, RangeConstraint* validity) {
@@ -248,7 +248,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer&& std::numeric_limits<T>::is_signed,
T>::type
CheckedNeg(T value, RangeConstraint* validity) {
@@ -259,7 +259,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed,
T>::type
CheckedNeg(T value, RangeConstraint* validity) {
@@ -270,7 +270,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer&& std::numeric_limits<T>::is_signed,
T>::type
CheckedAbs(T value, RangeConstraint* validity) {
@@ -280,7 +280,7 @@
}
template <typename T>
-typename enable_if<
+typename std::enable_if<
std::numeric_limits<T>::is_integer && !std::numeric_limits<T>::is_signed,
T>::type
CheckedAbs(T value, RangeConstraint* validity) {
@@ -293,7 +293,7 @@
// negation operation is ever called.
#define BASE_FLOAT_ARITHMETIC_STUBS(NAME) \
template <typename T> \
- typename enable_if<std::numeric_limits<T>::is_iec559, T>::type \
+ typename std::enable_if<std::numeric_limits<T>::is_iec559, T>::type \
Checked##NAME(T, T, RangeConstraint*) { \
NOTREACHED(); \
return 0; \
@@ -308,14 +308,14 @@
#undef BASE_FLOAT_ARITHMETIC_STUBS
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_iec559, T>::type CheckedNeg(
+typename std::enable_if<std::numeric_limits<T>::is_iec559, T>::type CheckedNeg(
T value,
RangeConstraint*) {
return -value;
}
template <typename T>
-typename enable_if<std::numeric_limits<T>::is_iec559, T>::type CheckedAbs(
+typename std::enable_if<std::numeric_limits<T>::is_iec559, T>::type CheckedAbs(
T value,
RangeConstraint*) {
return std::abs(value);
@@ -375,8 +375,8 @@
template <typename Src>
explicit CheckedNumericState(
Src value,
- typename enable_if<std::numeric_limits<Src>::is_specialized, int>::type =
- 0)
+ typename std::enable_if<std::numeric_limits<Src>::is_specialized,
+ int>::type = 0)
: value_(static_cast<T>(value)),
validity_(DstRangeRelationToSrcRange<T>(value)) {}
@@ -400,7 +400,8 @@
CheckedNumericState(
Src value,
RangeConstraint validity,
- typename enable_if<std::numeric_limits<Src>::is_integer, int>::type = 0) {
+ typename std::enable_if<std::numeric_limits<Src>::is_integer, int>::type =
+ 0) {
switch (DstRangeRelationToSrcRange<T>(value)) {
case RANGE_VALID:
value_ = static_cast<T>(value);
@@ -426,8 +427,8 @@
template <typename Src>
explicit CheckedNumericState(
Src value,
- typename enable_if<std::numeric_limits<Src>::is_specialized, int>::type =
- 0)
+ typename std::enable_if<std::numeric_limits<Src>::is_specialized,
+ int>::type = 0)
: value_(static_cast<T>(value)) {}
// Copy constructor.
diff --git a/libweave/external/base/numerics/safe_numerics_unittest.cc b/libweave/external/base/numerics/safe_numerics_unittest.cc
index 6f9a966..96b579a 100644
--- a/libweave/external/base/numerics/safe_numerics_unittest.cc
+++ b/libweave/external/base/numerics/safe_numerics_unittest.cc
@@ -9,11 +9,12 @@
#include <limits>
+#include <gtest/gtest.h>
+
#include "base/compiler_specific.h"
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
#include "base/template_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
using std::numeric_limits;
using base::CheckedNumeric;
@@ -27,7 +28,7 @@
using base::internal::RANGE_INVALID;
using base::internal::RANGE_OVERFLOW;
using base::internal::RANGE_UNDERFLOW;
-using base::enable_if;
+using std::enable_if;
// These tests deliberately cause arithmetic overflows. If the compiler is
// aggressive enough, it can const fold these overflows. Disable warnings about
diff --git a/libweave/external/base/observer_list.h b/libweave/external/base/observer_list.h
index a454430..3baf910 100644
--- a/libweave/external/base/observer_list.h
+++ b/libweave/external/base/observer_list.h
@@ -59,9 +59,6 @@
namespace base {
-template <typename ObserverType>
-class ObserverListThreadSafe;
-
template <class ObserverType>
class ObserverListBase
: public SupportsWeakPtr<ObserverListBase<ObserverType>> {
@@ -113,8 +110,6 @@
void Compact();
private:
- friend class ObserverListThreadSafe<ObserverType>;
-
typedef std::vector<ObserverType*> ListType;
ListType observers_;
diff --git a/libweave/external/base/observer_list_unittest.cc b/libweave/external/base/observer_list_unittest.cc
index 2e51e45..8af999a 100644
--- a/libweave/external/base/observer_list_unittest.cc
+++ b/libweave/external/base/observer_list_unittest.cc
@@ -3,17 +3,14 @@
// found in the LICENSE file.
#include "base/observer_list.h"
-#include "base/observer_list_threadsafe.h"
#include <vector>
+#include <gtest/gtest.h>
+
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
-#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/platform_thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
@@ -49,20 +46,6 @@
Foo* doomed_;
};
-class ThreadSafeDisrupter : public Foo {
- public:
- ThreadSafeDisrupter(ObserverListThreadSafe<Foo>* list, Foo* doomed)
- : list_(list),
- doomed_(doomed) {
- }
- ~ThreadSafeDisrupter() override {}
- void Observe(int x) override { list_->RemoveObserver(doomed_); }
-
- private:
- ObserverListThreadSafe<Foo>* list_;
- Foo* doomed_;
-};
-
template <typename ObserverListType>
class AddInObserve : public Foo {
public:
@@ -85,97 +68,6 @@
};
-static const int kThreadRunTime = 2000; // ms to run the multi-threaded test.
-
-// A thread for use in the ThreadSafeObserver test
-// which will add and remove itself from the notification
-// list repeatedly.
-class AddRemoveThread : public PlatformThread::Delegate,
- public Foo {
- public:
- AddRemoveThread(ObserverListThreadSafe<Foo>* list, bool notify)
- : list_(list),
- loop_(nullptr),
- in_list_(false),
- start_(Time::Now()),
- count_observes_(0),
- count_addtask_(0),
- do_notifies_(notify),
- weak_factory_(this) {
- }
-
- ~AddRemoveThread() override {}
-
- void ThreadMain() override {
- loop_ = new MessageLoop(); // Fire up a message loop.
- loop_->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr()));
- loop_->Run();
- //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " <<
- // count_observes_ << ", " << count_addtask_;
- delete loop_;
- loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef);
- delete this;
- }
-
- // This task just keeps posting to itself in an attempt
- // to race with the notifier.
- void AddTask() {
- count_addtask_++;
-
- if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) {
- VLOG(1) << "DONE!";
- return;
- }
-
- if (!in_list_) {
- list_->AddObserver(this);
- in_list_ = true;
- }
-
- if (do_notifies_) {
- list_->Notify(FROM_HERE, &Foo::Observe, 10);
- }
-
- loop_->task_runner()->PostTask(
- FROM_HERE,
- base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr()));
- }
-
- void Quit() {
- loop_->task_runner()->PostTask(FROM_HERE,
- MessageLoop::QuitWhenIdleClosure());
- }
-
- void Observe(int x) override {
- count_observes_++;
-
- // If we're getting called after we removed ourselves from
- // the list, that is very bad!
- DCHECK(in_list_);
-
- // This callback should fire on the appropriate thread
- EXPECT_EQ(loop_, MessageLoop::current());
-
- list_->RemoveObserver(this);
- in_list_ = false;
- }
-
- private:
- ObserverListThreadSafe<Foo>* list_;
- MessageLoop* loop_;
- bool in_list_; // Are we currently registered for notifications.
- // in_list_ is only used on |this| thread.
- Time start_; // The time we started the test.
-
- int count_observes_; // Number of times we observed.
- int count_addtask_; // Number of times thread AddTask was called
- bool do_notifies_; // Whether these threads should do notifications.
-
- base::WeakPtrFactory<AddRemoveThread> weak_factory_;
-};
-
TEST(ObserverListTest, BasicTest) {
ObserverList<Foo> observer_list;
Adder a(1), b(-1), c(1), d(-1), e(-1);
@@ -205,230 +97,6 @@
EXPECT_EQ(0, e.total);
}
-TEST(ObserverListThreadSafeTest, BasicTest) {
- MessageLoop loop;
-
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
- Adder a(1);
- Adder b(-1);
- Adder c(1);
- Adder d(-1);
- ThreadSafeDisrupter evil(observer_list.get(), &c);
-
- observer_list->AddObserver(&a);
- observer_list->AddObserver(&b);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
- RunLoop().RunUntilIdle();
-
- observer_list->AddObserver(&evil);
- observer_list->AddObserver(&c);
- observer_list->AddObserver(&d);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(20, a.total);
- EXPECT_EQ(-20, b.total);
- EXPECT_EQ(0, c.total);
- EXPECT_EQ(-10, d.total);
-}
-
-TEST(ObserverListThreadSafeTest, RemoveObserver) {
- MessageLoop loop;
-
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
- Adder a(1), b(1);
-
- // A workaround for the compiler bug. See http://crbug.com/121960.
- EXPECT_NE(&a, &b);
-
- // Should do nothing.
- observer_list->RemoveObserver(&a);
- observer_list->RemoveObserver(&b);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(0, a.total);
- EXPECT_EQ(0, b.total);
-
- observer_list->AddObserver(&a);
-
- // Should also do nothing.
- observer_list->RemoveObserver(&b);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(10, a.total);
- EXPECT_EQ(0, b.total);
-}
-
-TEST(ObserverListThreadSafeTest, WithoutMessageLoop) {
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
-
- Adder a(1), b(1), c(1);
-
- // No MessageLoop, so these should not be added.
- observer_list->AddObserver(&a);
- observer_list->AddObserver(&b);
-
- {
- // Add c when there's a loop.
- MessageLoop loop;
- observer_list->AddObserver(&c);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(0, a.total);
- EXPECT_EQ(0, b.total);
- EXPECT_EQ(10, c.total);
-
- // Now add a when there's a loop.
- observer_list->AddObserver(&a);
-
- // Remove c when there's a loop.
- observer_list->RemoveObserver(&c);
-
- // Notify again.
- observer_list->Notify(FROM_HERE, &Foo::Observe, 20);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(20, a.total);
- EXPECT_EQ(0, b.total);
- EXPECT_EQ(10, c.total);
- }
-
- // Removing should always succeed with or without a loop.
- observer_list->RemoveObserver(&a);
-
- // Notifying should not fail but should also be a no-op.
- MessageLoop loop;
- observer_list->AddObserver(&b);
- observer_list->Notify(FROM_HERE, &Foo::Observe, 30);
- RunLoop().RunUntilIdle();
-
- EXPECT_EQ(20, a.total);
- EXPECT_EQ(30, b.total);
- EXPECT_EQ(10, c.total);
-}
-
-class FooRemover : public Foo {
- public:
- explicit FooRemover(ObserverListThreadSafe<Foo>* list) : list_(list) {}
- ~FooRemover() override {}
-
- void AddFooToRemove(Foo* foo) {
- foos_.push_back(foo);
- }
-
- void Observe(int x) override {
- std::vector<Foo*> tmp;
- tmp.swap(foos_);
- for (std::vector<Foo*>::iterator it = tmp.begin();
- it != tmp.end(); ++it) {
- list_->RemoveObserver(*it);
- }
- }
-
- private:
- const scoped_refptr<ObserverListThreadSafe<Foo> > list_;
- std::vector<Foo*> foos_;
-};
-
-TEST(ObserverListThreadSafeTest, RemoveMultipleObservers) {
- MessageLoop loop;
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
-
- FooRemover a(observer_list.get());
- Adder b(1);
-
- observer_list->AddObserver(&a);
- observer_list->AddObserver(&b);
-
- a.AddFooToRemove(&a);
- a.AddFooToRemove(&b);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 1);
- RunLoop().RunUntilIdle();
-}
-
-// A test driver for a multi-threaded notification loop. Runs a number
-// of observer threads, each of which constantly adds/removes itself
-// from the observer list. Optionally, if cross_thread_notifies is set
-// to true, the observer threads will also trigger notifications to
-// all observers.
-static void ThreadSafeObserverHarness(int num_threads,
- bool cross_thread_notifies) {
- MessageLoop loop;
-
- const int kMaxThreads = 15;
- num_threads = num_threads > kMaxThreads ? kMaxThreads : num_threads;
-
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
- Adder a(1);
- Adder b(-1);
- Adder c(1);
- Adder d(-1);
-
- observer_list->AddObserver(&a);
- observer_list->AddObserver(&b);
-
- AddRemoveThread* threaded_observer[kMaxThreads];
- base::PlatformThreadHandle threads[kMaxThreads];
- for (int index = 0; index < num_threads; index++) {
- threaded_observer[index] = new AddRemoveThread(observer_list.get(), false);
- EXPECT_TRUE(PlatformThread::Create(0,
- threaded_observer[index], &threads[index]));
- }
-
- Time start = Time::Now();
- while (true) {
- if ((Time::Now() - start).InMilliseconds() > kThreadRunTime)
- break;
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 10);
-
- RunLoop().RunUntilIdle();
- }
-
- for (int index = 0; index < num_threads; index++) {
- threaded_observer[index]->Quit();
- PlatformThread::Join(threads[index]);
- }
-}
-
-TEST(ObserverListThreadSafeTest, CrossThreadObserver) {
- // Use 7 observer threads. Notifications only come from
- // the main thread.
- ThreadSafeObserverHarness(7, false);
-}
-
-TEST(ObserverListThreadSafeTest, CrossThreadNotifications) {
- // Use 3 observer threads. Notifications will fire from
- // the main thread and all 3 observer threads.
- ThreadSafeObserverHarness(3, true);
-}
-
-TEST(ObserverListThreadSafeTest, OutlivesMessageLoop) {
- MessageLoop* loop = new MessageLoop;
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>);
-
- Adder a(1);
- observer_list->AddObserver(&a);
- delete loop;
- // Test passes if we don't crash here.
- observer_list->Notify(FROM_HERE, &Foo::Observe, 1);
-}
-
TEST(ObserverListTest, Existing) {
ObserverList<Foo> observer_list(ObserverList<Foo>::NOTIFY_EXISTING_ONLY);
Adder a(1);
@@ -449,31 +117,6 @@
EXPECT_EQ(1, b.adder.total);
}
-// Same as above, but for ObserverListThreadSafe
-TEST(ObserverListThreadSafeTest, Existing) {
- MessageLoop loop;
- scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
- new ObserverListThreadSafe<Foo>(ObserverList<Foo>::NOTIFY_EXISTING_ONLY));
- Adder a(1);
- AddInObserve<ObserverListThreadSafe<Foo> > b(observer_list.get());
-
- observer_list->AddObserver(&a);
- observer_list->AddObserver(&b);
-
- observer_list->Notify(FROM_HERE, &Foo::Observe, 1);
- RunLoop().RunUntilIdle();
-
- EXPECT_TRUE(b.added);
- // B's adder should not have been notified because it was added during
- // notification.
- EXPECT_EQ(0, b.adder.total);
-
- // Notify again to make sure b's adder is notified.
- observer_list->Notify(FROM_HERE, &Foo::Observe, 1);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(1, b.adder.total);
-}
-
class AddInClearObserve : public Foo {
public:
explicit AddInClearObserve(ObserverList<Foo>* list)
diff --git a/libweave/external/base/posix/eintr_wrapper.h b/libweave/external/base/posix/eintr_wrapper.h
index 5a5dc75..27de8fc 100644
--- a/libweave/external/base/posix/eintr_wrapper.h
+++ b/libweave/external/base/posix/eintr_wrapper.h
@@ -16,7 +16,7 @@
#ifndef BASE_POSIX_EINTR_WRAPPER_H_
#define BASE_POSIX_EINTR_WRAPPER_H_
-#include "build/build_config.h"
+#include "base/build/build_config.h"
#if defined(OS_POSIX)
diff --git a/libweave/external/base/rand_util.cc b/libweave/external/base/rand_util.cc
index 931eb4e..a55cdbd 100644
--- a/libweave/external/base/rand_util.cc
+++ b/libweave/external/base/rand_util.cc
@@ -64,8 +64,8 @@
std::string RandBytesAsString(size_t length) {
DCHECK_GT(length, 0u);
- std::string result;
- RandBytes(WriteInto(&result, length + 1), length);
+ std::string result(length, ' ');
+ RandBytes(&result[0], length);
return result;
}
diff --git a/libweave/external/base/rand_util.h b/libweave/external/base/rand_util.h
index 6130c12..e3d4888 100644
--- a/libweave/external/base/rand_util.h
+++ b/libweave/external/base/rand_util.h
@@ -50,10 +50,6 @@
// See crypto/ for cryptographically secure random number generation APIs.
BASE_EXPORT std::string RandBytesAsString(size_t length);
-#if defined(OS_POSIX)
-BASE_EXPORT int GetUrandomFD();
-#endif
-
} // namespace base
#endif // BASE_RAND_UTIL_H_
diff --git a/libweave/external/base/rand_util_posix.cc b/libweave/external/base/rand_util_posix.cc
index fe73b96..76a5dab 100644
--- a/libweave/external/base/rand_util_posix.cc
+++ b/libweave/external/base/rand_util_posix.cc
@@ -8,16 +8,11 @@
#include <fcntl.h>
#include <unistd.h>
-#include "base/files/file_util.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/posix/eintr_wrapper.h"
namespace {
-// We keep the file descriptor for /dev/urandom around so we don't need to
-// reopen it (which is expensive), and since we may not even be able to reopen
-// it if we are later put in a sandbox. This class wraps the file descriptor so
-// we can use LazyInstance to handle opening it on the first access.
class URandomFd {
public:
URandomFd() : fd_(open("/dev/urandom", O_RDONLY)) {
@@ -32,7 +27,17 @@
const int fd_;
};
-base::LazyInstance<URandomFd>::Leaky g_urandom_fd = LAZY_INSTANCE_INITIALIZER;
+bool ReadFromFD(int fd, char* buffer, size_t bytes) {
+ size_t total_read = 0;
+ while (total_read < bytes) {
+ ssize_t bytes_read =
+ HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read));
+ if (bytes_read <= 0)
+ break;
+ total_read += bytes_read;
+ }
+ return total_read == bytes;
+}
} // namespace
@@ -46,14 +51,10 @@
}
void RandBytes(void* output, size_t output_length) {
- const int urandom_fd = g_urandom_fd.Pointer()->fd();
+ URandomFd urandom_fd;
const bool success =
- ReadFromFD(urandom_fd, static_cast<char*>(output), output_length);
+ ReadFromFD(urandom_fd.fd(), static_cast<char*>(output), output_length);
CHECK(success);
}
-int GetUrandomFD(void) {
- return g_urandom_fd.Pointer()->fd();
-}
-
} // namespace base
diff --git a/libweave/external/base/rand_util_unittest.cc b/libweave/external/base/rand_util_unittest.cc
index 90690ec..384125b 100644
--- a/libweave/external/base/rand_util_unittest.cc
+++ b/libweave/external/base/rand_util_unittest.cc
@@ -7,10 +7,11 @@
#include <algorithm>
#include <limits>
+#include <gtest/gtest.h>
+
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -123,22 +124,3 @@
FAIL() << "Didn't achieve all bit values in maximum number of tries.";
}
-
-// Benchmark test for RandBytes(). Disabled since it's intentionally slow and
-// does not test anything that isn't already tested by the existing RandBytes()
-// tests.
-TEST(RandUtilTest, DISABLED_RandBytesPerf) {
- // Benchmark the performance of |kTestIterations| of RandBytes() using a
- // buffer size of |kTestBufferSize|.
- const int kTestIterations = 10;
- const size_t kTestBufferSize = 1 * 1024 * 1024;
-
- scoped_ptr<uint8[]> buffer(new uint8[kTestBufferSize]);
- const base::TimeTicks now = base::TimeTicks::Now();
- for (int i = 0; i < kTestIterations; ++i)
- base::RandBytes(buffer.get(), kTestBufferSize);
- const base::TimeTicks end = base::TimeTicks::Now();
-
- LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: "
- << (end - now).InMicroseconds() << "µs";
-}
diff --git a/libweave/external/base/scoped_clear_errno_unittest.cc b/libweave/external/base/scoped_clear_errno_unittest.cc
index 8afb33e..1666d7a 100644
--- a/libweave/external/base/scoped_clear_errno_unittest.cc
+++ b/libweave/external/base/scoped_clear_errno_unittest.cc
@@ -4,8 +4,9 @@
#include <errno.h>
+#include <gtest/gtest.h>
+
#include "base/scoped_clear_errno.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
diff --git a/libweave/external/base/strings/string_number_conversions.cc b/libweave/external/base/strings/string_number_conversions.cc
index 642d24e..b5463fb 100644
--- a/libweave/external/base/strings/string_number_conversions.cc
+++ b/libweave/external/base/strings/string_number_conversions.cc
@@ -13,7 +13,6 @@
#include "base/logging.h"
#include "base/scoped_clear_errno.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/third_party/dmg_fp/dmg_fp.h"
namespace base {
@@ -145,13 +144,6 @@
}
};
-template<> class WhitespaceHelper<char16> {
- public:
- static bool Invoke(char16 c) {
- return 0 != iswspace(c);
- }
-};
-
template<typename CHAR> bool LocalIsWhitespace(CHAR c) {
return WhitespaceHelper<CHAR>::Invoke(c);
}
@@ -352,19 +344,6 @@
input.begin(), input.end(), output);
}
-template <typename VALUE, int BASE>
-class StringPiece16ToNumberTraits
- : public BaseIteratorRangeToNumberTraits<StringPiece16::const_iterator,
- VALUE,
- BASE> {
-};
-
-template <typename VALUE>
-bool String16ToIntImpl(const StringPiece16& input, VALUE* output) {
- return IteratorRangeToNumber<StringPiece16ToNumberTraits<VALUE, 10> >::Invoke(
- input.begin(), input.end(), output);
-}
-
} // namespace
std::string IntToString(int value) {
@@ -372,45 +351,23 @@
IntToString(value);
}
-string16 IntToString16(int value) {
- return IntToStringT<string16, int, unsigned int, true>::
- IntToString(value);
-}
-
std::string UintToString(unsigned int value) {
return IntToStringT<std::string, unsigned int, unsigned int, false>::
IntToString(value);
}
-string16 UintToString16(unsigned int value) {
- return IntToStringT<string16, unsigned int, unsigned int, false>::
- IntToString(value);
-}
-
std::string Int64ToString(int64 value) {
return IntToStringT<std::string, int64, uint64, true>::IntToString(value);
}
-string16 Int64ToString16(int64 value) {
- return IntToStringT<string16, int64, uint64, true>::IntToString(value);
-}
-
std::string Uint64ToString(uint64 value) {
return IntToStringT<std::string, uint64, uint64, false>::IntToString(value);
}
-string16 Uint64ToString16(uint64 value) {
- return IntToStringT<string16, uint64, uint64, false>::IntToString(value);
-}
-
std::string SizeTToString(size_t value) {
return IntToStringT<std::string, size_t, size_t, false>::IntToString(value);
}
-string16 SizeTToString16(size_t value) {
- return IntToStringT<string16, size_t, size_t, false>::IntToString(value);
-}
-
std::string DoubleToString(double value) {
// According to g_fmt.cc, it is sufficient to declare a buffer of size 32.
char buffer[32];
@@ -422,42 +379,22 @@
return StringToIntImpl(input, output);
}
-bool StringToInt(const StringPiece16& input, int* output) {
- return String16ToIntImpl(input, output);
-}
-
bool StringToUint(const StringPiece& input, unsigned* output) {
return StringToIntImpl(input, output);
}
-bool StringToUint(const StringPiece16& input, unsigned* output) {
- return String16ToIntImpl(input, output);
-}
-
bool StringToInt64(const StringPiece& input, int64* output) {
return StringToIntImpl(input, output);
}
-bool StringToInt64(const StringPiece16& input, int64* output) {
- return String16ToIntImpl(input, output);
-}
-
bool StringToUint64(const StringPiece& input, uint64* output) {
return StringToIntImpl(input, output);
}
-bool StringToUint64(const StringPiece16& input, uint64* output) {
- return String16ToIntImpl(input, output);
-}
-
bool StringToSizeT(const StringPiece& input, size_t* output) {
return StringToIntImpl(input, output);
}
-bool StringToSizeT(const StringPiece16& input, size_t* output) {
- return String16ToIntImpl(input, output);
-}
-
bool StringToDouble(const std::string& input, double* output) {
// Thread-safe? It is on at least Mac, Linux, and Windows.
ScopedClearErrno clear_errno;
diff --git a/libweave/external/base/strings/string_number_conversions.h b/libweave/external/base/strings/string_number_conversions.h
index 050e627..78059ed 100644
--- a/libweave/external/base/strings/string_number_conversions.h
+++ b/libweave/external/base/strings/string_number_conversions.h
@@ -10,7 +10,6 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
// ----------------------------------------------------------------------------
@@ -30,19 +29,14 @@
// Number -> string conversions ------------------------------------------------
BASE_EXPORT std::string IntToString(int value);
-BASE_EXPORT string16 IntToString16(int value);
BASE_EXPORT std::string UintToString(unsigned value);
-BASE_EXPORT string16 UintToString16(unsigned value);
BASE_EXPORT std::string Int64ToString(int64 value);
-BASE_EXPORT string16 Int64ToString16(int64 value);
BASE_EXPORT std::string Uint64ToString(uint64 value);
-BASE_EXPORT string16 Uint64ToString16(uint64 value);
BASE_EXPORT std::string SizeTToString(size_t value);
-BASE_EXPORT string16 SizeTToString16(size_t value);
// DoubleToString converts the double to a string format that ignores the
// locale. If you want to use locale specific formatting, use ICU.
@@ -65,19 +59,14 @@
// |*output| will be set to 0.
// - Empty string. |*output| will be set to 0.
BASE_EXPORT bool StringToInt(const StringPiece& input, int* output);
-BASE_EXPORT bool StringToInt(const StringPiece16& input, int* output);
BASE_EXPORT bool StringToUint(const StringPiece& input, unsigned* output);
-BASE_EXPORT bool StringToUint(const StringPiece16& input, unsigned* output);
BASE_EXPORT bool StringToInt64(const StringPiece& input, int64* output);
-BASE_EXPORT bool StringToInt64(const StringPiece16& input, int64* output);
BASE_EXPORT bool StringToUint64(const StringPiece& input, uint64* output);
-BASE_EXPORT bool StringToUint64(const StringPiece16& input, uint64* output);
BASE_EXPORT bool StringToSizeT(const StringPiece& input, size_t* output);
-BASE_EXPORT bool StringToSizeT(const StringPiece16& input, size_t* output);
// For floating-point conversions, only conversions of input strings in decimal
// form are defined to work. Behavior with strings representing floating-point
diff --git a/libweave/external/base/strings/string_number_conversions_unittest.cc b/libweave/external/base/strings/string_number_conversions_unittest.cc
index 0bc72f1..80d1471 100644
--- a/libweave/external/base/strings/string_number_conversions_unittest.cc
+++ b/libweave/external/base/strings/string_number_conversions_unittest.cc
@@ -11,10 +11,10 @@
#include <cmath>
#include <limits>
-#include "base/format_macros.h"
+#include <gtest/gtest.h>
+
#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/strings/utf_string_conversion_utils.h"
namespace base {
@@ -50,16 +50,12 @@
for (size_t i = 0; i < arraysize(int_tests); ++i) {
const IntToStringTest<int>* test = &int_tests[i];
EXPECT_EQ(IntToString(test->num), test->sexpected);
- EXPECT_EQ(IntToString16(test->num), UTF8ToUTF16(test->sexpected));
EXPECT_EQ(UintToString(test->num), test->uexpected);
- EXPECT_EQ(UintToString16(test->num), UTF8ToUTF16(test->uexpected));
}
for (size_t i = 0; i < arraysize(int64_tests); ++i) {
const IntToStringTest<int64>* test = &int64_tests[i];
EXPECT_EQ(Int64ToString(test->num), test->sexpected);
- EXPECT_EQ(Int64ToString16(test->num), UTF8ToUTF16(test->sexpected));
EXPECT_EQ(Uint64ToString(test->num), test->uexpected);
- EXPECT_EQ(Uint64ToString16(test->num), UTF8ToUTF16(test->uexpected));
}
}
@@ -80,7 +76,7 @@
TEST(StringNumberConversionsTest, SizeTToString) {
size_t size_t_max = std::numeric_limits<size_t>::max();
- std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max);
+ std::string size_t_max_string = std::to_string(size_t_max);
static const struct {
size_t input;
@@ -137,11 +133,6 @@
int output = 0;
EXPECT_EQ(cases[i].success, StringToInt(cases[i].input, &output));
EXPECT_EQ(cases[i].output, output);
-
- string16 utf16_input = UTF8ToUTF16(cases[i].input);
- output = 0;
- EXPECT_EQ(cases[i].success, StringToInt(utf16_input, &output));
- EXPECT_EQ(cases[i].output, output);
}
// One additional test to verify that conversion of numbers in strings with
@@ -152,16 +143,6 @@
int output;
EXPECT_FALSE(StringToInt(input_string, &output));
EXPECT_EQ(6, output);
-
- string16 utf16_input = UTF8ToUTF16(input_string);
- output = 0;
- EXPECT_FALSE(StringToInt(utf16_input, &output));
- EXPECT_EQ(6, output);
-
- output = 0;
- const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0};
- EXPECT_FALSE(StringToInt(string16(negative_wide_input), &output));
- EXPECT_EQ(0, output);
}
TEST(StringNumberConversionsTest, StringToUint) {
@@ -201,11 +182,6 @@
unsigned output = 0;
EXPECT_EQ(cases[i].success, StringToUint(cases[i].input, &output));
EXPECT_EQ(cases[i].output, output);
-
- string16 utf16_input = UTF8ToUTF16(cases[i].input);
- output = 0;
- EXPECT_EQ(cases[i].success, StringToUint(utf16_input, &output));
- EXPECT_EQ(cases[i].output, output);
}
// One additional test to verify that conversion of numbers in strings with
@@ -216,16 +192,6 @@
unsigned output;
EXPECT_FALSE(StringToUint(input_string, &output));
EXPECT_EQ(6U, output);
-
- string16 utf16_input = UTF8ToUTF16(input_string);
- output = 0;
- EXPECT_FALSE(StringToUint(utf16_input, &output));
- EXPECT_EQ(6U, output);
-
- output = 0;
- const char16 negative_wide_input[] = { 0xFF4D, '4', '2', 0};
- EXPECT_FALSE(StringToUint(string16(negative_wide_input), &output));
- EXPECT_EQ(0U, output);
}
TEST(StringNumberConversionsTest, StringToInt64) {
@@ -271,11 +237,6 @@
int64 output = 0;
EXPECT_EQ(cases[i].success, StringToInt64(cases[i].input, &output));
EXPECT_EQ(cases[i].output, output);
-
- string16 utf16_input = UTF8ToUTF16(cases[i].input);
- output = 0;
- EXPECT_EQ(cases[i].success, StringToInt64(utf16_input, &output));
- EXPECT_EQ(cases[i].output, output);
}
// One additional test to verify that conversion of numbers in strings with
@@ -286,11 +247,6 @@
int64 output;
EXPECT_FALSE(StringToInt64(input_string, &output));
EXPECT_EQ(6, output);
-
- string16 utf16_input = UTF8ToUTF16(input_string);
- output = 0;
- EXPECT_FALSE(StringToInt64(utf16_input, &output));
- EXPECT_EQ(6, output);
}
TEST(StringNumberConversionsTest, StringToUint64) {
@@ -338,11 +294,6 @@
uint64 output = 0;
EXPECT_EQ(cases[i].success, StringToUint64(cases[i].input, &output));
EXPECT_EQ(cases[i].output, output);
-
- string16 utf16_input = UTF8ToUTF16(cases[i].input);
- output = 0;
- EXPECT_EQ(cases[i].success, StringToUint64(utf16_input, &output));
- EXPECT_EQ(cases[i].output, output);
}
// One additional test to verify that conversion of numbers in strings with
@@ -353,16 +304,11 @@
uint64 output;
EXPECT_FALSE(StringToUint64(input_string, &output));
EXPECT_EQ(6U, output);
-
- string16 utf16_input = UTF8ToUTF16(input_string);
- output = 0;
- EXPECT_FALSE(StringToUint64(utf16_input, &output));
- EXPECT_EQ(6U, output);
}
TEST(StringNumberConversionsTest, StringToSizeT) {
size_t size_t_max = std::numeric_limits<size_t>::max();
- std::string size_t_max_string = StringPrintf("%" PRIuS, size_t_max);
+ std::string size_t_max_string = std::to_string(size_t_max);
static const struct {
std::string input;
@@ -407,11 +353,6 @@
size_t output = 0;
EXPECT_EQ(cases[i].success, StringToSizeT(cases[i].input, &output));
EXPECT_EQ(cases[i].output, output);
-
- string16 utf16_input = UTF8ToUTF16(cases[i].input);
- output = 0;
- EXPECT_EQ(cases[i].success, StringToSizeT(utf16_input, &output));
- EXPECT_EQ(cases[i].output, output);
}
// One additional test to verify that conversion of numbers in strings with
@@ -422,11 +363,6 @@
size_t output;
EXPECT_FALSE(StringToSizeT(input_string, &output));
EXPECT_EQ(6U, output);
-
- string16 utf16_input = UTF8ToUTF16(input_string);
- output = 0;
- EXPECT_FALSE(StringToSizeT(utf16_input, &output));
- EXPECT_EQ(6U, output);
}
TEST(StringNumberConversionsTest, HexStringToInt) {
diff --git a/libweave/external/base/strings/string_piece.cc b/libweave/external/base/strings/string_piece.cc
index 4c7f112..aa0695d 100644
--- a/libweave/external/base/strings/string_piece.cc
+++ b/libweave/external/base/strings/string_piece.cc
@@ -33,7 +33,6 @@
// MSVC doesn't like complex extern templates and DLLs.
#if !defined(COMPILER_MSVC)
template class BasicStringPiece<std::string>;
-template class BasicStringPiece<string16>;
#endif
bool operator==(const StringPiece& x, const StringPiece& y) {
@@ -62,10 +61,6 @@
CopyToStringT(self, target);
}
-void CopyToString(const StringPiece16& self, string16* target) {
- CopyToStringT(self, target);
-}
-
template<typename STR>
void AppendToStringT(const BasicStringPiece<STR>& self, STR* target) {
if (!self.empty())
@@ -76,10 +71,6 @@
AppendToStringT(self, target);
}
-void AppendToString(const StringPiece16& self, string16* target) {
- AppendToStringT(self, target);
-}
-
template<typename STR>
size_t copyT(const BasicStringPiece<STR>& self,
typename STR::value_type* buf,
@@ -94,10 +85,6 @@
return copyT(self, buf, n, pos);
}
-size_t copy(const StringPiece16& self, char16* buf, size_t n, size_t pos) {
- return copyT(self, buf, n, pos);
-}
-
template<typename STR>
size_t findT(const BasicStringPiece<STR>& self,
const BasicStringPiece<STR>& s,
@@ -116,10 +103,6 @@
return findT(self, s, pos);
}
-size_t find(const StringPiece16& self, const StringPiece16& s, size_t pos) {
- return findT(self, s, pos);
-}
-
template<typename STR>
size_t findT(const BasicStringPiece<STR>& self,
typename STR::value_type c,
@@ -137,10 +120,6 @@
return findT(self, c, pos);
}
-size_t find(const StringPiece16& self, char16 c, size_t pos) {
- return findT(self, c, pos);
-}
-
template<typename STR>
size_t rfindT(const BasicStringPiece<STR>& self,
const BasicStringPiece<STR>& s,
@@ -163,10 +142,6 @@
return rfindT(self, s, pos);
}
-size_t rfind(const StringPiece16& self, const StringPiece16& s, size_t pos) {
- return rfindT(self, s, pos);
-}
-
template<typename STR>
size_t rfindT(const BasicStringPiece<STR>& self,
typename STR::value_type c,
@@ -188,10 +163,6 @@
return rfindT(self, c, pos);
}
-size_t rfind(const StringPiece16& self, char16 c, size_t pos) {
- return rfindT(self, c, pos);
-}
-
// 8-bit version using lookup table.
size_t find_first_of(const StringPiece& self,
const StringPiece& s,
@@ -213,17 +184,6 @@
return StringPiece::npos;
}
-// 16-bit brute force version.
-size_t find_first_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos) {
- StringPiece16::const_iterator found =
- std::find_first_of(self.begin() + pos, self.end(), s.begin(), s.end());
- if (found == self.end())
- return StringPiece16::npos;
- return found - self.begin();
-}
-
// 8-bit version using lookup table.
size_t find_first_not_of(const StringPiece& self,
const StringPiece& s,
@@ -248,27 +208,6 @@
return StringPiece::npos;
}
-// 16-bit brute-force version.
-BASE_EXPORT size_t find_first_not_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos) {
- if (self.size() == 0)
- return StringPiece16::npos;
-
- for (size_t self_i = pos; self_i < self.size(); ++self_i) {
- bool found = false;
- for (size_t s_i = 0; s_i < s.size(); ++s_i) {
- if (self[self_i] == s[s_i]) {
- found = true;
- break;
- }
- }
- if (!found)
- return self_i;
- }
- return StringPiece16::npos;
-}
-
template<typename STR>
size_t find_first_not_ofT(const BasicStringPiece<STR>& self,
typename STR::value_type c,
@@ -290,12 +229,6 @@
return find_first_not_ofT(self, c, pos);
}
-size_t find_first_not_of(const StringPiece16& self,
- char16 c,
- size_t pos) {
- return find_first_not_ofT(self, c, pos);
-}
-
// 8-bit version using lookup table.
size_t find_last_of(const StringPiece& self, const StringPiece& s, size_t pos) {
if (self.size() == 0 || s.size() == 0)
@@ -316,25 +249,6 @@
return StringPiece::npos;
}
-// 16-bit brute-force version.
-size_t find_last_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos) {
- if (self.size() == 0)
- return StringPiece16::npos;
-
- for (size_t self_i = std::min(pos, self.size() - 1); ;
- --self_i) {
- for (size_t s_i = 0; s_i < s.size(); s_i++) {
- if (self.data()[self_i] == s[s_i])
- return self_i;
- }
- if (self_i == 0)
- break;
- }
- return StringPiece16::npos;
-}
-
// 8-bit version using lookup table.
size_t find_last_not_of(const StringPiece& self,
const StringPiece& s,
@@ -361,29 +275,6 @@
return StringPiece::npos;
}
-// 16-bit brute-force version.
-size_t find_last_not_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos) {
- if (self.size() == 0)
- return StringPiece::npos;
-
- for (size_t self_i = std::min(pos, self.size() - 1); ; --self_i) {
- bool found = false;
- for (size_t s_i = 0; s_i < s.size(); s_i++) {
- if (self.data()[self_i] == s[s_i]) {
- found = true;
- break;
- }
- }
- if (!found)
- return self_i;
- if (self_i == 0)
- break;
- }
- return StringPiece16::npos;
-}
-
template<typename STR>
size_t find_last_not_ofT(const BasicStringPiece<STR>& self,
typename STR::value_type c,
@@ -406,12 +297,6 @@
return find_last_not_ofT(self, c, pos);
}
-size_t find_last_not_of(const StringPiece16& self,
- char16 c,
- size_t pos) {
- return find_last_not_ofT(self, c, pos);
-}
-
template<typename STR>
BasicStringPiece<STR> substrT(const BasicStringPiece<STR>& self,
size_t pos,
@@ -427,11 +312,5 @@
return substrT(self, pos, n);
}
-StringPiece16 substr(const StringPiece16& self,
- size_t pos,
- size_t n) {
- return substrT(self, pos, n);
-}
-
} // namespace internal
} // namespace base
diff --git a/libweave/external/base/strings/string_piece.h b/libweave/external/base/strings/string_piece.h
index a83b7d8..c3ce222 100644
--- a/libweave/external/base/strings/string_piece.h
+++ b/libweave/external/base/strings/string_piece.h
@@ -29,14 +29,11 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "base/containers/hash_tables.h"
-#include "base/strings/string16.h"
namespace base {
template <typename STRING_TYPE> class BasicStringPiece;
typedef BasicStringPiece<std::string> StringPiece;
-typedef BasicStringPiece<string16> StringPiece16;
// internal --------------------------------------------------------------------
@@ -50,88 +47,49 @@
namespace internal {
BASE_EXPORT void CopyToString(const StringPiece& self, std::string* target);
-BASE_EXPORT void CopyToString(const StringPiece16& self, string16* target);
BASE_EXPORT void AppendToString(const StringPiece& self, std::string* target);
-BASE_EXPORT void AppendToString(const StringPiece16& self, string16* target);
BASE_EXPORT size_t copy(const StringPiece& self,
char* buf,
size_t n,
size_t pos);
-BASE_EXPORT size_t copy(const StringPiece16& self,
- char16* buf,
- size_t n,
- size_t pos);
BASE_EXPORT size_t find(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t find(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
BASE_EXPORT size_t find(const StringPiece& self,
char c,
size_t pos);
-BASE_EXPORT size_t find(const StringPiece16& self,
- char16 c,
- size_t pos);
BASE_EXPORT size_t rfind(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t rfind(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
BASE_EXPORT size_t rfind(const StringPiece& self,
char c,
size_t pos);
-BASE_EXPORT size_t rfind(const StringPiece16& self,
- char16 c,
- size_t pos);
BASE_EXPORT size_t find_first_of(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t find_first_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
BASE_EXPORT size_t find_first_not_of(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t find_first_not_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
BASE_EXPORT size_t find_first_not_of(const StringPiece& self,
char c,
size_t pos);
-BASE_EXPORT size_t find_first_not_of(const StringPiece16& self,
- char16 c,
- size_t pos);
BASE_EXPORT size_t find_last_of(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t find_last_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
BASE_EXPORT size_t find_last_of(const StringPiece& self,
char c,
size_t pos);
-BASE_EXPORT size_t find_last_of(const StringPiece16& self,
- char16 c,
- size_t pos);
BASE_EXPORT size_t find_last_not_of(const StringPiece& self,
const StringPiece& s,
size_t pos);
-BASE_EXPORT size_t find_last_not_of(const StringPiece16& self,
- const StringPiece16& s,
- size_t pos);
-BASE_EXPORT size_t find_last_not_of(const StringPiece16& self,
- char16 c,
- size_t pos);
BASE_EXPORT size_t find_last_not_of(const StringPiece& self,
char c,
size_t pos);
@@ -139,9 +97,6 @@
BASE_EXPORT StringPiece substr(const StringPiece& self,
size_t pos,
size_t n);
-BASE_EXPORT StringPiece16 substr(const StringPiece16& self,
- size_t pos,
- size_t n);
} // namespace internal
@@ -352,7 +307,6 @@
// MSVC doesn't like complex extern templates and DLLs.
#if !defined(COMPILER_MSVC)
extern template class BASE_EXPORT BasicStringPiece<std::string>;
-extern template class BASE_EXPORT BasicStringPiece<string16>;
#endif
// StingPiece operators --------------------------------------------------------
@@ -381,72 +335,9 @@
return !(x < y);
}
-// StringPiece16 operators -----------------------------------------------------
-
-inline bool operator==(const StringPiece16& x, const StringPiece16& y) {
- if (x.size() != y.size())
- return false;
-
- return StringPiece16::wordmemcmp(x.data(), y.data(), x.size()) == 0;
-}
-
-inline bool operator!=(const StringPiece16& x, const StringPiece16& y) {
- return !(x == y);
-}
-
-inline bool operator<(const StringPiece16& x, const StringPiece16& y) {
- const int r = StringPiece16::wordmemcmp(
- x.data(), y.data(), (x.size() < y.size() ? x.size() : y.size()));
- return ((r < 0) || ((r == 0) && (x.size() < y.size())));
-}
-
-inline bool operator>(const StringPiece16& x, const StringPiece16& y) {
- return y < x;
-}
-
-inline bool operator<=(const StringPiece16& x, const StringPiece16& y) {
- return !(x > y);
-}
-
-inline bool operator>=(const StringPiece16& x, const StringPiece16& y) {
- return !(x < y);
-}
-
BASE_EXPORT std::ostream& operator<<(std::ostream& o,
const StringPiece& piece);
} // namespace base
-// Hashing ---------------------------------------------------------------------
-
-// We provide appropriate hash functions so StringPiece and StringPiece16 can
-// be used as keys in hash sets and maps.
-
-// This hash function is copied from base/containers/hash_tables.h. We don't
-// use the ones already defined for string and string16 directly because it
-// would require the string constructors to be called, which we don't want.
-#define HASH_STRING_PIECE(StringPieceType, string_piece) \
- std::size_t result = 0; \
- for (StringPieceType::const_iterator i = string_piece.begin(); \
- i != string_piece.end(); ++i) \
- result = (result * 131) + *i; \
- return result; \
-
-namespace BASE_HASH_NAMESPACE {
-
-template<>
-struct hash<base::StringPiece> {
- std::size_t operator()(const base::StringPiece& sp) const {
- HASH_STRING_PIECE(base::StringPiece, sp);
- }
-};
-template<>
-struct hash<base::StringPiece16> {
- std::size_t operator()(const base::StringPiece16& sp16) const {
- HASH_STRING_PIECE(base::StringPiece16, sp16);
- }
-};
-
-} // namespace BASE_HASH_NAMESPACE
-
#endif // BASE_STRINGS_STRING_PIECE_H_
diff --git a/libweave/external/base/strings/string_piece_unittest.cc b/libweave/external/base/strings/string_piece_unittest.cc
index 5336603..2c2b0a6 100644
--- a/libweave/external/base/strings/string_piece_unittest.cc
+++ b/libweave/external/base/strings/string_piece_unittest.cc
@@ -4,10 +4,10 @@
#include <string>
-#include "base/strings/string16.h"
+#include <gtest/gtest.h>
+
#include "base/strings/string_piece.h"
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/strings/utf_string_conversion_utils.h"
namespace base {
@@ -22,18 +22,7 @@
}
};
-template <>
-class CommonStringPieceTest<string16> : public ::testing::Test {
- public:
- static const string16 as_string(const char* input) {
- return ASCIIToUTF16(input);
- }
- static const string16 as_string(const std::string& input) {
- return ASCIIToUTF16(input);
- }
-};
-
-typedef ::testing::Types<std::string, string16> SupportedStringTypes;
+typedef ::testing::Types<std::string> SupportedStringTypes;
TYPED_TEST_CASE(CommonStringPieceTest, SupportedStringTypes);
@@ -640,32 +629,6 @@
ASSERT_TRUE(hello.c_str() == BasicStringPiece<TypeParam>(hello));
}
-// string16-specific stuff
-TEST(StringPiece16Test, CheckSTL) {
- // Check some non-ascii characters.
- string16 fifth(ASCIIToUTF16("123"));
- fifth.push_back(0x0000);
- fifth.push_back(0xd8c5);
- fifth.push_back(0xdffe);
- StringPiece16 f(fifth);
-
- ASSERT_EQ(f[3], '\0');
- ASSERT_EQ(f[5], static_cast<char16>(0xdffe));
-
- ASSERT_EQ(f.size(), 6U);
-}
-
-
-
-TEST(StringPiece16Test, CheckConversion) {
- // Make sure that we can convert from UTF8 to UTF16 and back. We use a two
- // byte character (G clef) to test this.
- ASSERT_EQ(
- UTF16ToUTF8(
- StringPiece16(UTF8ToUTF16("\xf0\x9d\x84\x9e")).as_string()),
- "\xf0\x9d\x84\x9e");
-}
-
TYPED_TEST(CommonStringPieceTest, CheckConstructors) {
TypeParam str(TestFixture::as_string("hello world"));
TypeParam empty;
diff --git a/libweave/external/base/strings/string_util.cc b/libweave/external/base/strings/string_util.cc
index 738d32e..4042b39 100644
--- a/libweave/external/base/strings/string_util.cc
+++ b/libweave/external/base/strings/string_util.cc
@@ -4,69 +4,11 @@
#include "base/strings/string_util.h"
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <wchar.h>
-#include <wctype.h>
-
-#include <algorithm>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/memory/singleton.h"
-#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversion_utils.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/third_party/icu/icu_utf.h"
-#include "build/build_config.h"
-
-// Remove when this entire file is in the base namespace.
-using base::char16;
-using base::string16;
namespace {
-// Force the singleton used by EmptyString[16] to be a unique type. This
-// prevents other code that might accidentally use Singleton<string> from
-// getting our internal one.
-struct EmptyStrings {
- EmptyStrings() {}
- const std::string s;
- const string16 s16;
-
- static EmptyStrings* GetInstance() {
- return Singleton<EmptyStrings>::get();
- }
-};
-
-// Used by ReplaceStringPlaceholders to track the position in the string of
-// replaced parameters.
-struct ReplacementOffset {
- ReplacementOffset(uintptr_t parameter, size_t offset)
- : parameter(parameter),
- offset(offset) {}
-
- // Index of the parameter.
- uintptr_t parameter;
-
- // Starting position in the string.
- size_t offset;
-};
-
-static bool CompareParameter(const ReplacementOffset& elem1,
- const ReplacementOffset& elem2) {
- return elem1.parameter < elem2.parameter;
-}
-
-// Assuming that a pointer is the size of a "machine word", then
-// uintptr_t is an integer type that is also a machine word.
typedef uintptr_t MachineWord;
const uintptr_t kMachineWordAlignmentMask = sizeof(MachineWord) - 1;
@@ -80,74 +22,17 @@
}
template<size_t size, typename CharacterType> struct NonASCIIMask;
-template<> struct NonASCIIMask<4, base::char16> {
- static inline uint32_t value() { return 0xFF80FF80U; }
-};
template<> struct NonASCIIMask<4, char> {
static inline uint32_t value() { return 0x80808080U; }
};
-template<> struct NonASCIIMask<8, base::char16> {
- static inline uint64_t value() { return 0xFF80FF80FF80FF80ULL; }
-};
template<> struct NonASCIIMask<8, char> {
static inline uint64_t value() { return 0x8080808080808080ULL; }
};
-#if defined(WCHAR_T_IS_UTF32)
-template<> struct NonASCIIMask<4, wchar_t> {
- static inline uint32_t value() { return 0xFFFFFF80U; }
-};
-template<> struct NonASCIIMask<8, wchar_t> {
- static inline uint64_t value() { return 0xFFFFFF80FFFFFF80ULL; }
-};
-#endif // WCHAR_T_IS_UTF32
} // namespace
namespace base {
-bool IsWprintfFormatPortable(const wchar_t* format) {
- for (const wchar_t* position = format; *position != '\0'; ++position) {
- if (*position == '%') {
- bool in_specification = true;
- bool modifier_l = false;
- while (in_specification) {
- // Eat up characters until reaching a known specifier.
- if (*++position == '\0') {
- // The format string ended in the middle of a specification. Call
- // it portable because no unportable specifications were found. The
- // string is equally broken on all platforms.
- return true;
- }
-
- if (*position == 'l') {
- // 'l' is the only thing that can save the 's' and 'c' specifiers.
- modifier_l = true;
- } else if (((*position == 's' || *position == 'c') && !modifier_l) ||
- *position == 'S' || *position == 'C' || *position == 'F' ||
- *position == 'D' || *position == 'O' || *position == 'U') {
- // Not portable.
- return false;
- }
-
- if (wcschr(L"diouxXeEfgGaAcspn%", *position)) {
- // Portable, keep scanning the rest of the format string.
- in_specification = false;
- }
- }
- }
- }
-
- return true;
-}
-
-const std::string& EmptyString() {
- return EmptyStrings::GetInstance()->s;
-}
-
-const string16& EmptyString16() {
- return EmptyStrings::GetInstance()->s16;
-}
-
template<typename STR>
bool ReplaceCharsT(const STR& input,
const STR& replace_chars,
@@ -168,13 +53,6 @@
return removed;
}
-bool ReplaceChars(const string16& input,
- const base::StringPiece16& replace_chars,
- const string16& replace_with,
- string16* output) {
- return ReplaceCharsT(input, replace_chars.as_string(), replace_with, output);
-}
-
bool ReplaceChars(const std::string& input,
const base::StringPiece& replace_chars,
const std::string& replace_with,
@@ -182,18 +60,6 @@
return ReplaceCharsT(input, replace_chars.as_string(), replace_with, output);
}
-bool RemoveChars(const string16& input,
- const base::StringPiece16& remove_chars,
- string16* output) {
- return ReplaceChars(input, remove_chars.as_string(), string16(), output);
-}
-
-bool RemoveChars(const std::string& input,
- const base::StringPiece& remove_chars,
- std::string* output) {
- return ReplaceChars(input, remove_chars.as_string(), std::string(), output);
-}
-
template<typename Str>
TrimPositions TrimStringT(const Str& input,
BasicStringPiece<Str> trim_chars,
@@ -230,12 +96,6 @@
((last_good_char == last_char) ? TRIM_NONE : TRIM_TRAILING));
}
-bool TrimString(const string16& input,
- base::StringPiece16 trim_chars,
- string16* output) {
- return TrimStringT(input, trim_chars, TRIM_ALL, output) != TRIM_NONE;
-}
-
bool TrimString(const std::string& input,
base::StringPiece trim_chars,
std::string* output) {
@@ -253,136 +113,18 @@
return input.substr(begin, end - begin);
}
-StringPiece16 TrimString(StringPiece16 input,
- const base::StringPiece16& trim_chars,
- TrimPositions positions) {
- return TrimStringPieceT(input, trim_chars, positions);
-}
-
StringPiece TrimString(StringPiece input,
const base::StringPiece& trim_chars,
TrimPositions positions) {
return TrimStringPieceT(input, trim_chars, positions);
}
-void TruncateUTF8ToByteSize(const std::string& input,
- const size_t byte_size,
- std::string* output) {
- DCHECK(output);
- if (byte_size > input.length()) {
- *output = input;
- return;
- }
- DCHECK_LE(byte_size, static_cast<uint32>(kint32max));
- // Note: This cast is necessary because CBU8_NEXT uses int32s.
- int32 truncation_length = static_cast<int32>(byte_size);
- int32 char_index = truncation_length - 1;
- const char* data = input.data();
-
- // Using CBU8, we will move backwards from the truncation point
- // to the beginning of the string looking for a valid UTF8
- // character. Once a full UTF8 character is found, we will
- // truncate the string to the end of that character.
- while (char_index >= 0) {
- int32 prev = char_index;
- base_icu::UChar32 code_point = 0;
- CBU8_NEXT(data, char_index, truncation_length, code_point);
- if (!IsValidCharacter(code_point) ||
- !IsValidCodepoint(code_point)) {
- char_index = prev - 1;
- } else {
- break;
- }
- }
-
- if (char_index >= 0 )
- *output = input.substr(0, char_index);
- else
- output->clear();
-}
-
-TrimPositions TrimWhitespace(const string16& input,
- TrimPositions positions,
- string16* output) {
- return TrimStringT(input, StringPiece16(kWhitespaceUTF16), positions, output);
-}
-
TrimPositions TrimWhitespaceASCII(const std::string& input,
TrimPositions positions,
std::string* output) {
return TrimStringT(input, StringPiece(kWhitespaceASCII), positions, output);
}
-// This function is only for backward-compatibility.
-// To be removed when all callers are updated.
-TrimPositions TrimWhitespace(const std::string& input,
- TrimPositions positions,
- std::string* output) {
- return TrimWhitespaceASCII(input, positions, output);
-}
-
-template<typename STR>
-STR CollapseWhitespaceT(const STR& text,
- bool trim_sequences_with_line_breaks) {
- STR result;
- result.resize(text.size());
-
- // Set flags to pretend we're already in a trimmed whitespace sequence, so we
- // will trim any leading whitespace.
- bool in_whitespace = true;
- bool already_trimmed = true;
-
- int chars_written = 0;
- for (typename STR::const_iterator i(text.begin()); i != text.end(); ++i) {
- if (IsWhitespace(*i)) {
- if (!in_whitespace) {
- // Reduce all whitespace sequences to a single space.
- in_whitespace = true;
- result[chars_written++] = L' ';
- }
- if (trim_sequences_with_line_breaks && !already_trimmed &&
- ((*i == '\n') || (*i == '\r'))) {
- // Whitespace sequences containing CR or LF are eliminated entirely.
- already_trimmed = true;
- --chars_written;
- }
- } else {
- // Non-whitespace chracters are copied straight across.
- in_whitespace = false;
- already_trimmed = false;
- result[chars_written++] = *i;
- }
- }
-
- if (in_whitespace && !already_trimmed) {
- // Any trailing whitespace is eliminated.
- --chars_written;
- }
-
- result.resize(chars_written);
- return result;
-}
-
-string16 CollapseWhitespace(const string16& text,
- bool trim_sequences_with_line_breaks) {
- return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
-}
-
-std::string CollapseWhitespaceASCII(const std::string& text,
- bool trim_sequences_with_line_breaks) {
- return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
-}
-
-bool ContainsOnlyChars(const StringPiece& input,
- const StringPiece& characters) {
- return input.find_first_not_of(characters) == StringPiece::npos;
-}
-
-bool ContainsOnlyChars(const StringPiece16& input,
- const StringPiece16& characters) {
- return input.find_first_not_of(characters) == StringPiece16::npos;
-}
-
template <class Char>
inline bool DoIsStringASCII(const Char* characters, size_t length) {
MachineWord all_char_bits = 0;
@@ -417,20 +159,6 @@
return DoIsStringASCII(str.data(), str.length());
}
-bool IsStringASCII(const StringPiece16& str) {
- return DoIsStringASCII(str.data(), str.length());
-}
-
-bool IsStringASCII(const string16& str) {
- return DoIsStringASCII(str.data(), str.length());
-}
-
-#if defined(WCHAR_T_IS_UTF32)
-bool IsStringASCII(const std::wstring& str) {
- return DoIsStringASCII(str.data(), str.length());
-}
-#endif
-
bool IsStringUTF8(const StringPiece& str) {
const char *src = str.data();
int32 src_len = static_cast<int32>(str.length());
@@ -445,606 +173,4 @@
return true;
}
-template<typename Iter>
-static inline bool DoLowerCaseEqualsASCII(Iter a_begin,
- Iter a_end,
- const char* b) {
- for (Iter it = a_begin; it != a_end; ++it, ++b) {
- if (!*b || ToLowerASCII(*it) != *b)
- return false;
- }
- return *b == 0;
-}
-
-// Front-ends for LowerCaseEqualsASCII.
-bool LowerCaseEqualsASCII(const std::string& a, const char* b) {
- return DoLowerCaseEqualsASCII(a.begin(), a.end(), b);
-}
-
-bool LowerCaseEqualsASCII(const string16& a, const char* b) {
- return DoLowerCaseEqualsASCII(a.begin(), a.end(), b);
-}
-
-bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
- std::string::const_iterator a_end,
- const char* b) {
- return DoLowerCaseEqualsASCII(a_begin, a_end, b);
-}
-
-bool LowerCaseEqualsASCII(string16::const_iterator a_begin,
- string16::const_iterator a_end,
- const char* b) {
- return DoLowerCaseEqualsASCII(a_begin, a_end, b);
-}
-
-bool LowerCaseEqualsASCII(const char* a_begin,
- const char* a_end,
- const char* b) {
- return DoLowerCaseEqualsASCII(a_begin, a_end, b);
-}
-
-bool LowerCaseEqualsASCII(const char* a_begin,
- const char* a_end,
- const char* b_begin,
- const char* b_end) {
- while (a_begin != a_end && b_begin != b_end &&
- ToLowerASCII(*a_begin) == *b_begin) {
- a_begin++;
- b_begin++;
- }
- return a_begin == a_end && b_begin == b_end;
-}
-
-bool LowerCaseEqualsASCII(const char16* a_begin,
- const char16* a_end,
- const char* b) {
- return DoLowerCaseEqualsASCII(a_begin, a_end, b);
-}
-
-bool EqualsASCII(const string16& a, const StringPiece& b) {
- if (a.length() != b.length())
- return false;
- return std::equal(b.begin(), b.end(), a.begin());
-}
-
-bool StartsWithASCII(const std::string& str,
- const std::string& search,
- bool case_sensitive) {
- if (case_sensitive)
- return str.compare(0, search.length(), search) == 0;
- else
- return base::strncasecmp(str.c_str(), search.c_str(), search.length()) == 0;
-}
-
-bool StartsWith(const string16& str,
- const string16& search,
- bool case_sensitive) {
- if (case_sensitive) {
- return str.compare(0, search.length(), search) == 0;
- }
- if (search.size() > str.size())
- return false;
- return std::equal(search.begin(), search.end(), str.begin(),
- CaseInsensitiveCompare<char16>());
-}
-
-template <typename STR>
-bool EndsWithT(const STR& str, const STR& search, bool case_sensitive) {
- size_t str_length = str.length();
- size_t search_length = search.length();
- if (search_length > str_length)
- return false;
- if (case_sensitive)
- return str.compare(str_length - search_length, search_length, search) == 0;
- return std::equal(search.begin(), search.end(),
- str.begin() + (str_length - search_length),
- base::CaseInsensitiveCompare<typename STR::value_type>());
-}
-
-bool EndsWith(const std::string& str, const std::string& search,
- bool case_sensitive) {
- return EndsWithT(str, search, case_sensitive);
-}
-
-bool EndsWith(const string16& str, const string16& search,
- bool case_sensitive) {
- return EndsWithT(str, search, case_sensitive);
-}
-
} // namespace base
-
-static const char* const kByteStringsUnlocalized[] = {
- " B",
- " kB",
- " MB",
- " GB",
- " TB",
- " PB"
-};
-
-string16 FormatBytesUnlocalized(int64 bytes) {
- double unit_amount = static_cast<double>(bytes);
- size_t dimension = 0;
- const int kKilo = 1024;
- while (unit_amount >= kKilo &&
- dimension < arraysize(kByteStringsUnlocalized) - 1) {
- unit_amount /= kKilo;
- dimension++;
- }
-
- char buf[64];
- if (bytes != 0 && dimension > 0 && unit_amount < 100) {
- base::snprintf(buf, arraysize(buf), "%.1lf%s", unit_amount,
- kByteStringsUnlocalized[dimension]);
- } else {
- base::snprintf(buf, arraysize(buf), "%.0lf%s", unit_amount,
- kByteStringsUnlocalized[dimension]);
- }
-
- return base::ASCIIToUTF16(buf);
-}
-
-// Runs in O(n) time in the length of |str|.
-template<class StringType>
-void DoReplaceSubstringsAfterOffset(StringType* str,
- size_t offset,
- const StringType& find_this,
- const StringType& replace_with,
- bool replace_all) {
- DCHECK(!find_this.empty());
-
- // If the find string doesn't appear, there's nothing to do.
- offset = str->find(find_this, offset);
- if (offset == StringType::npos)
- return;
-
- // If we're only replacing one instance, there's no need to do anything
- // complicated.
- size_t find_length = find_this.length();
- if (!replace_all) {
- str->replace(offset, find_length, replace_with);
- return;
- }
-
- // If the find and replace strings are the same length, we can simply use
- // replace() on each instance, and finish the entire operation in O(n) time.
- size_t replace_length = replace_with.length();
- if (find_length == replace_length) {
- do {
- str->replace(offset, find_length, replace_with);
- offset = str->find(find_this, offset + replace_length);
- } while (offset != StringType::npos);
- return;
- }
-
- // Since the find and replace strings aren't the same length, a loop like the
- // one above would be O(n^2) in the worst case, as replace() will shift the
- // entire remaining string each time. We need to be more clever to keep
- // things O(n).
- //
- // If we're shortening the string, we can alternate replacements with shifting
- // forward the intervening characters using memmove().
- size_t str_length = str->length();
- if (find_length > replace_length) {
- size_t write_offset = offset;
- do {
- if (replace_length) {
- str->replace(write_offset, replace_length, replace_with);
- write_offset += replace_length;
- }
- size_t read_offset = offset + find_length;
- offset = std::min(str->find(find_this, read_offset), str_length);
- size_t length = offset - read_offset;
- if (length) {
- memmove(&(*str)[write_offset], &(*str)[read_offset],
- length * sizeof(typename StringType::value_type));
- write_offset += length;
- }
- } while (offset < str_length);
- str->resize(write_offset);
- return;
- }
-
- // We're lengthening the string. We can use alternating replacements and
- // memmove() calls like above, but we need to precalculate the final string
- // length and then expand from back-to-front to avoid overwriting the string
- // as we're reading it, needing to shift, or having to copy to a second string
- // temporarily.
- size_t first_match = offset;
-
- // First, calculate the final length and resize the string.
- size_t final_length = str_length;
- size_t expansion = replace_length - find_length;
- size_t current_match;
- do {
- final_length += expansion;
- // Minor optimization: save this offset into |current_match|, so that on
- // exit from the loop, |current_match| will point at the last instance of
- // the find string, and we won't need to find() it again immediately.
- current_match = offset;
- offset = str->find(find_this, offset + find_length);
- } while (offset != StringType::npos);
- str->resize(final_length);
-
- // Now do the replacement loop, working backwards through the string.
- for (size_t prev_match = str_length, write_offset = final_length; ;
- current_match = str->rfind(find_this, current_match - 1)) {
- size_t read_offset = current_match + find_length;
- size_t length = prev_match - read_offset;
- if (length) {
- write_offset -= length;
- memmove(&(*str)[write_offset], &(*str)[read_offset],
- length * sizeof(typename StringType::value_type));
- }
- write_offset -= replace_length;
- str->replace(write_offset, replace_length, replace_with);
- if (current_match == first_match)
- return;
- prev_match = current_match;
- }
-}
-
-void ReplaceFirstSubstringAfterOffset(string16* str,
- size_t start_offset,
- const string16& find_this,
- const string16& replace_with) {
- DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
- false); // replace first instance
-}
-
-void ReplaceFirstSubstringAfterOffset(std::string* str,
- size_t start_offset,
- const std::string& find_this,
- const std::string& replace_with) {
- DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
- false); // replace first instance
-}
-
-void ReplaceSubstringsAfterOffset(string16* str,
- size_t start_offset,
- const string16& find_this,
- const string16& replace_with) {
- DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
- true); // replace all instances
-}
-
-void ReplaceSubstringsAfterOffset(std::string* str,
- size_t start_offset,
- const std::string& find_this,
- const std::string& replace_with) {
- DoReplaceSubstringsAfterOffset(str, start_offset, find_this, replace_with,
- true); // replace all instances
-}
-
-size_t Tokenize(const base::string16& str,
- const base::string16& delimiters,
- std::vector<base::string16>* tokens) {
- *tokens = base::SplitString(
- str, delimiters, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
- return tokens->size();
-}
-
-size_t Tokenize(const std::string& str,
- const std::string& delimiters,
- std::vector<std::string>* tokens) {
- *tokens = base::SplitString(
- str, delimiters, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
- return tokens->size();
-}
-
-size_t Tokenize(const base::StringPiece& str,
- const base::StringPiece& delimiters,
- std::vector<base::StringPiece>* tokens) {
- *tokens = base::SplitStringPiece(
- str, delimiters, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
- return tokens->size();
-}
-
-template<typename STR>
-static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) {
- if (parts.empty())
- return STR();
-
- STR result(parts[0]);
- typename std::vector<STR>::const_iterator iter = parts.begin();
- ++iter;
-
- for (; iter != parts.end(); ++iter) {
- result += sep;
- result += *iter;
- }
-
- return result;
-}
-
-std::string JoinString(const std::vector<std::string>& parts, char sep) {
- return JoinStringT(parts, std::string(1, sep));
-}
-
-string16 JoinString(const std::vector<string16>& parts, char16 sep) {
- return JoinStringT(parts, string16(1, sep));
-}
-
-std::string JoinString(const std::vector<std::string>& parts,
- const std::string& separator) {
- return JoinStringT(parts, separator);
-}
-
-string16 JoinString(const std::vector<string16>& parts,
- const string16& separator) {
- return JoinStringT(parts, separator);
-}
-
-template<class FormatStringType, class OutStringType>
-OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string,
- const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) {
- size_t substitutions = subst.size();
-
- size_t sub_length = 0;
- for (typename std::vector<OutStringType>::const_iterator iter = subst.begin();
- iter != subst.end(); ++iter) {
- sub_length += iter->length();
- }
-
- OutStringType formatted;
- formatted.reserve(format_string.length() + sub_length);
-
- std::vector<ReplacementOffset> r_offsets;
- for (typename FormatStringType::const_iterator i = format_string.begin();
- i != format_string.end(); ++i) {
- if ('$' == *i) {
- if (i + 1 != format_string.end()) {
- ++i;
- DCHECK('$' == *i || '1' <= *i) << "Invalid placeholder: " << *i;
- if ('$' == *i) {
- while (i != format_string.end() && '$' == *i) {
- formatted.push_back('$');
- ++i;
- }
- --i;
- } else {
- uintptr_t index = 0;
- while (i != format_string.end() && '0' <= *i && *i <= '9') {
- index *= 10;
- index += *i - '0';
- ++i;
- }
- --i;
- index -= 1;
- if (offsets) {
- ReplacementOffset r_offset(index,
- static_cast<int>(formatted.size()));
- r_offsets.insert(std::lower_bound(r_offsets.begin(),
- r_offsets.end(),
- r_offset,
- &CompareParameter),
- r_offset);
- }
- if (index < substitutions)
- formatted.append(subst.at(index));
- }
- }
- } else {
- formatted.push_back(*i);
- }
- }
- if (offsets) {
- for (std::vector<ReplacementOffset>::const_iterator i = r_offsets.begin();
- i != r_offsets.end(); ++i) {
- offsets->push_back(i->offset);
- }
- }
- return formatted;
-}
-
-string16 ReplaceStringPlaceholders(const string16& format_string,
- const std::vector<string16>& subst,
- std::vector<size_t>* offsets) {
- return DoReplaceStringPlaceholders(format_string, subst, offsets);
-}
-
-std::string ReplaceStringPlaceholders(const base::StringPiece& format_string,
- const std::vector<std::string>& subst,
- std::vector<size_t>* offsets) {
- return DoReplaceStringPlaceholders(format_string, subst, offsets);
-}
-
-string16 ReplaceStringPlaceholders(const string16& format_string,
- const string16& a,
- size_t* offset) {
- std::vector<size_t> offsets;
- std::vector<string16> subst;
- subst.push_back(a);
- string16 result = ReplaceStringPlaceholders(format_string, subst, &offsets);
-
- DCHECK_EQ(1U, offsets.size());
- if (offset)
- *offset = offsets[0];
- return result;
-}
-
-static bool IsWildcard(base_icu::UChar32 character) {
- return character == '*' || character == '?';
-}
-
-// Move the strings pointers to the point where they start to differ.
-template <typename CHAR, typename NEXT>
-static void EatSameChars(const CHAR** pattern, const CHAR* pattern_end,
- const CHAR** string, const CHAR* string_end,
- NEXT next) {
- const CHAR* escape = NULL;
- while (*pattern != pattern_end && *string != string_end) {
- if (!escape && IsWildcard(**pattern)) {
- // We don't want to match wildcard here, except if it's escaped.
- return;
- }
-
- // Check if the escapement char is found. If so, skip it and move to the
- // next character.
- if (!escape && **pattern == '\\') {
- escape = *pattern;
- next(pattern, pattern_end);
- continue;
- }
-
- // Check if the chars match, if so, increment the ptrs.
- const CHAR* pattern_next = *pattern;
- const CHAR* string_next = *string;
- base_icu::UChar32 pattern_char = next(&pattern_next, pattern_end);
- if (pattern_char == next(&string_next, string_end) &&
- pattern_char != CBU_SENTINEL) {
- *pattern = pattern_next;
- *string = string_next;
- } else {
- // Uh oh, it did not match, we are done. If the last char was an
- // escapement, that means that it was an error to advance the ptr here,
- // let's put it back where it was. This also mean that the MatchPattern
- // function will return false because if we can't match an escape char
- // here, then no one will.
- if (escape) {
- *pattern = escape;
- }
- return;
- }
-
- escape = NULL;
- }
-}
-
-template <typename CHAR, typename NEXT>
-static void EatWildcard(const CHAR** pattern, const CHAR* end, NEXT next) {
- while (*pattern != end) {
- if (!IsWildcard(**pattern))
- return;
- next(pattern, end);
- }
-}
-
-template <typename CHAR, typename NEXT>
-static bool MatchPatternT(const CHAR* eval, const CHAR* eval_end,
- const CHAR* pattern, const CHAR* pattern_end,
- int depth,
- NEXT next) {
- const int kMaxDepth = 16;
- if (depth > kMaxDepth)
- return false;
-
- // Eat all the matching chars.
- EatSameChars(&pattern, pattern_end, &eval, eval_end, next);
-
- // If the string is empty, then the pattern must be empty too, or contains
- // only wildcards.
- if (eval == eval_end) {
- EatWildcard(&pattern, pattern_end, next);
- return pattern == pattern_end;
- }
-
- // Pattern is empty but not string, this is not a match.
- if (pattern == pattern_end)
- return false;
-
- // If this is a question mark, then we need to compare the rest with
- // the current string or the string with one character eaten.
- const CHAR* next_pattern = pattern;
- next(&next_pattern, pattern_end);
- if (pattern[0] == '?') {
- if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
- depth + 1, next))
- return true;
- const CHAR* next_eval = eval;
- next(&next_eval, eval_end);
- if (MatchPatternT(next_eval, eval_end, next_pattern, pattern_end,
- depth + 1, next))
- return true;
- }
-
- // This is a *, try to match all the possible substrings with the remainder
- // of the pattern.
- if (pattern[0] == '*') {
- // Collapse duplicate wild cards (********** into *) so that the
- // method does not recurse unnecessarily. http://crbug.com/52839
- EatWildcard(&next_pattern, pattern_end, next);
-
- while (eval != eval_end) {
- if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
- depth + 1, next))
- return true;
- eval++;
- }
-
- // We reached the end of the string, let see if the pattern contains only
- // wildcards.
- if (eval == eval_end) {
- EatWildcard(&pattern, pattern_end, next);
- if (pattern != pattern_end)
- return false;
- return true;
- }
- }
-
- return false;
-}
-
-struct NextCharUTF8 {
- base_icu::UChar32 operator()(const char** p, const char* end) {
- base_icu::UChar32 c;
- int offset = 0;
- CBU8_NEXT(*p, offset, end - *p, c);
- *p += offset;
- return c;
- }
-};
-
-struct NextCharUTF16 {
- base_icu::UChar32 operator()(const char16** p, const char16* end) {
- base_icu::UChar32 c;
- int offset = 0;
- CBU16_NEXT(*p, offset, end - *p, c);
- *p += offset;
- return c;
- }
-};
-
-bool MatchPattern(const base::StringPiece& eval,
- const base::StringPiece& pattern) {
- return MatchPatternT(eval.data(), eval.data() + eval.size(),
- pattern.data(), pattern.data() + pattern.size(),
- 0, NextCharUTF8());
-}
-
-bool MatchPattern(const string16& eval, const string16& pattern) {
- return MatchPatternT(eval.c_str(), eval.c_str() + eval.size(),
- pattern.c_str(), pattern.c_str() + pattern.size(),
- 0, NextCharUTF16());
-}
-
-// The following code is compatible with the OpenBSD lcpy interface. See:
-// http://www.gratisoft.us/todd/papers/strlcpy.html
-// ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c
-
-namespace {
-
-template <typename CHAR>
-size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) {
- for (size_t i = 0; i < dst_size; ++i) {
- if ((dst[i] = src[i]) == 0) // We hit and copied the terminating NULL.
- return i;
- }
-
- // We were left off at dst_size. We over copied 1 byte. Null terminate.
- if (dst_size != 0)
- dst[dst_size - 1] = 0;
-
- // Count the rest of the |src|, and return it's length in characters.
- while (src[dst_size]) ++dst_size;
- return dst_size;
-}
-
-} // namespace
-
-size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
- return lcpyT<char>(dst, src, dst_size);
-}
-size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
- return lcpyT<wchar_t>(dst, src, dst_size);
-}
diff --git a/libweave/external/base/strings/string_util.h b/libweave/external/base/strings/string_util.h
index 027c6b6..b5b013a 100644
--- a/libweave/external/base/strings/string_util.h
+++ b/libweave/external/base/strings/string_util.h
@@ -16,7 +16,6 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/strings/string16.h"
#include "base/strings/string_piece.h" // For implicit conversions.
// On Android, bionic's stdio.h defines an snprintf macro when being built with
@@ -30,19 +29,6 @@
// are listed below. These functions are then implemented as inline calls
// to the platform-specific equivalents in the platform-specific headers.
-// Compares the two strings s1 and s2 without regard to case using
-// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
-// s2 > s1 according to a lexicographic comparison.
-int strcasecmp(const char* s1, const char* s2);
-
-// Compares up to count characters of s1 and s2 without regard to case using
-// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
-// s2 > s1 according to a lexicographic comparison.
-int strncasecmp(const char* s1, const char* s2, size_t count);
-
-// Same as strncmp but for char16 strings.
-int strncmp16(const char16* s1, const char16* s2, size_t count);
-
// Wrapper for vsnprintf that always null-terminates and always returns the
// number of characters that would be in an untruncated formatted
// string, even when truncation occurs.
@@ -63,114 +49,16 @@
return result;
}
-// BSD-style safe and consistent string copy functions.
-// Copies |src| to |dst|, where |dst_size| is the total allocated size of |dst|.
-// Copies at most |dst_size|-1 characters, and always NULL terminates |dst|, as
-// long as |dst_size| is not 0. Returns the length of |src| in characters.
-// If the return value is >= dst_size, then the output was truncated.
-// NOTE: All sizes are in number of characters, NOT in bytes.
-BASE_EXPORT size_t strlcpy(char* dst, const char* src, size_t dst_size);
-BASE_EXPORT size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size);
-
-// Scan a wprintf format string to determine whether it's portable across a
-// variety of systems. This function only checks that the conversion
-// specifiers used by the format string are supported and have the same meaning
-// on a variety of systems. It doesn't check for other errors that might occur
-// within a format string.
-//
-// Nonportable conversion specifiers for wprintf are:
-// - 's' and 'c' without an 'l' length modifier. %s and %c operate on char
-// data on all systems except Windows, which treat them as wchar_t data.
-// Use %ls and %lc for wchar_t data instead.
-// - 'S' and 'C', which operate on wchar_t data on all systems except Windows,
-// which treat them as char data. Use %ls and %lc for wchar_t data
-// instead.
-// - 'F', which is not identified by Windows wprintf documentation.
-// - 'D', 'O', and 'U', which are deprecated and not available on all systems.
-// Use %ld, %lo, and %lu instead.
-//
-// Note that there is no portable conversion specifier for char data when
-// working with wprintf.
-//
-// This function is intended to be called from base::vswprintf.
-BASE_EXPORT bool IsWprintfFormatPortable(const wchar_t* format);
-
-// ASCII-specific tolower. The standard library's tolower is locale sensitive,
-// so we don't want to use it here.
-template <class Char> inline Char ToLowerASCII(Char c) {
- return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
-}
-
-// ASCII-specific toupper. The standard library's toupper is locale sensitive,
-// so we don't want to use it here.
-template <class Char> inline Char ToUpperASCII(Char c) {
- return (c >= 'a' && c <= 'z') ? (c + ('A' - 'a')) : c;
-}
-
-// Function objects to aid in comparing/searching strings.
-
-template<typename Char> struct CaseInsensitiveCompare {
- public:
- bool operator()(Char x, Char y) const {
- // TODO(darin): Do we really want to do locale sensitive comparisons here?
- // See http://crbug.com/24917
- return tolower(x) == tolower(y);
- }
-};
-
-template<typename Char> struct CaseInsensitiveCompareASCII {
- public:
- bool operator()(Char x, Char y) const {
- return ToLowerASCII(x) == ToLowerASCII(y);
- }
-};
-
-// These threadsafe functions return references to globally unique empty
-// strings.
-//
-// It is likely faster to construct a new empty string object (just a few
-// instructions to set the length to 0) than to get the empty string singleton
-// returned by these functions (which requires threadsafe singleton access).
-//
-// Therefore, DO NOT USE THESE AS A GENERAL-PURPOSE SUBSTITUTE FOR DEFAULT
-// CONSTRUCTORS. There is only one case where you should use these: functions
-// which need to return a string by reference (e.g. as a class member
-// accessor), and don't have an empty string to use (e.g. in an error case).
-// These should not be used as initializers, function arguments, or return
-// values for functions which return by value or outparam.
-BASE_EXPORT const std::string& EmptyString();
-BASE_EXPORT const string16& EmptyString16();
-
// Contains the set of characters representing whitespace in the corresponding
// encoding. Null-terminated. The ASCII versions are the whitespaces as defined
// by HTML5, and don't include control characters.
-BASE_EXPORT extern const wchar_t kWhitespaceWide[]; // Includes Unicode.
-BASE_EXPORT extern const char16 kWhitespaceUTF16[]; // Includes Unicode.
BASE_EXPORT extern const char kWhitespaceASCII[];
-BASE_EXPORT extern const char16 kWhitespaceASCIIAs16[]; // No unicode.
-
-// Null-terminated string representing the UTF-8 byte order mark.
-BASE_EXPORT extern const char kUtf8ByteOrderMark[];
-
-// Removes characters in |remove_chars| from anywhere in |input|. Returns true
-// if any characters were removed. |remove_chars| must be null-terminated.
-// NOTE: Safe to use the same variable for both |input| and |output|.
-BASE_EXPORT bool RemoveChars(const string16& input,
- const base::StringPiece16& remove_chars,
- string16* output);
-BASE_EXPORT bool RemoveChars(const std::string& input,
- const base::StringPiece& remove_chars,
- std::string* output);
// Replaces characters in |replace_chars| from anywhere in |input| with
// |replace_with|. Each character in |replace_chars| will be replaced with
// the |replace_with| string. Returns true if any characters were replaced.
// |replace_chars| must be null-terminated.
// NOTE: Safe to use the same variable for both |input| and |output|.
-BASE_EXPORT bool ReplaceChars(const string16& input,
- const base::StringPiece16& replace_chars,
- const string16& replace_with,
- string16* output);
BASE_EXPORT bool ReplaceChars(const std::string& input,
const base::StringPiece& replace_chars,
const std::string& replace_with,
@@ -188,28 +76,16 @@
//
// It is safe to use the same variable for both |input| and |output| (this is
// the normal usage to trim in-place).
-BASE_EXPORT bool TrimString(const string16& input,
- base::StringPiece16 trim_chars,
- string16* output);
BASE_EXPORT bool TrimString(const std::string& input,
base::StringPiece trim_chars,
std::string* output);
// StringPiece versions of the above. The returned pieces refer to the original
// buffer.
-BASE_EXPORT StringPiece16 TrimString(StringPiece16 input,
- const base::StringPiece16& trim_chars,
- TrimPositions positions);
BASE_EXPORT StringPiece TrimString(StringPiece input,
const base::StringPiece& trim_chars,
TrimPositions positions);
-// Truncates a string to the nearest UTF-8 character that will leave
-// the string less than or equal to the specified byte size.
-BASE_EXPORT void TruncateUTF8ToByteSize(const std::string& input,
- const size_t byte_size,
- std::string* output);
-
// Trims any whitespace from either end of the input string. Returns where
// whitespace was found.
// The non-wide version has two functions:
@@ -217,9 +93,6 @@
// This function is for ASCII strings and only looks for ASCII whitespace;
// Please choose the best one according to your usage.
// NOTE: Safe to use the same variable for both input and output.
-BASE_EXPORT TrimPositions TrimWhitespace(const string16& input,
- TrimPositions positions,
- base::string16* output);
BASE_EXPORT TrimPositions TrimWhitespaceASCII(const std::string& input,
TrimPositions positions,
std::string* output);
@@ -230,28 +103,6 @@
TrimPositions positions,
std::string* output);
-// Searches for CR or LF characters. Removes all contiguous whitespace
-// strings that contain them. This is useful when trying to deal with text
-// copied from terminals.
-// Returns |text|, with the following three transformations:
-// (1) Leading and trailing whitespace is trimmed.
-// (2) If |trim_sequences_with_line_breaks| is true, any other whitespace
-// sequences containing a CR or LF are trimmed.
-// (3) All other whitespace sequences are converted to single spaces.
-BASE_EXPORT string16 CollapseWhitespace(
- const string16& text,
- bool trim_sequences_with_line_breaks);
-BASE_EXPORT std::string CollapseWhitespaceASCII(
- const std::string& text,
- bool trim_sequences_with_line_breaks);
-
-// Returns true if |input| is empty or contains only characters found in
-// |characters|.
-BASE_EXPORT bool ContainsOnlyChars(const StringPiece& input,
- const StringPiece& characters);
-BASE_EXPORT bool ContainsOnlyChars(const StringPiece16& input,
- const StringPiece16& characters);
-
// Returns true if the specified string matches the criteria. How can a wide
// string be 8-bit or UTF8? It contains only characters that are < 256 (in the
// first case) or characters that use only 8-bits and whose 8-bit
@@ -268,90 +119,6 @@
// if it is not the case.
BASE_EXPORT bool IsStringUTF8(const StringPiece& str);
BASE_EXPORT bool IsStringASCII(const StringPiece& str);
-BASE_EXPORT bool IsStringASCII(const StringPiece16& str);
-// A convenience adaptor for WebStrings, as they don't convert into
-// StringPieces directly.
-BASE_EXPORT bool IsStringASCII(const string16& str);
-#if defined(WCHAR_T_IS_UTF32)
-BASE_EXPORT bool IsStringASCII(const std::wstring& str);
-#endif
-
-// Converts the elements of the given string. This version uses a pointer to
-// clearly differentiate it from the non-pointer variant.
-template <class str> inline void StringToLowerASCII(str* s) {
- for (typename str::iterator i = s->begin(); i != s->end(); ++i)
- *i = ToLowerASCII(*i);
-}
-
-template <class str> inline str StringToLowerASCII(const str& s) {
- // for std::string and std::wstring
- str output(s);
- StringToLowerASCII(&output);
- return output;
-}
-
-// Converts the elements of the given string. This version uses a pointer to
-// clearly differentiate it from the non-pointer variant.
-template <class str> inline void StringToUpperASCII(str* s) {
- for (typename str::iterator i = s->begin(); i != s->end(); ++i)
- *i = ToUpperASCII(*i);
-}
-
-template <class str> inline str StringToUpperASCII(const str& s) {
- // for std::string and std::wstring
- str output(s);
- StringToUpperASCII(&output);
- return output;
-}
-//
-// Compare the lower-case form of the given string against the given ASCII
-// string. This is useful for doing checking if an input string matches some
-// token, and it is optimized to avoid intermediate string copies. This API is
-// borrowed from the equivalent APIs in Mozilla.
-BASE_EXPORT bool LowerCaseEqualsASCII(const std::string& a, const char* b);
-BASE_EXPORT bool LowerCaseEqualsASCII(const string16& a, const char* b);
-
-// Same thing, but with string iterators instead.
-BASE_EXPORT bool LowerCaseEqualsASCII(std::string::const_iterator a_begin,
- std::string::const_iterator a_end,
- const char* b);
-BASE_EXPORT bool LowerCaseEqualsASCII(string16::const_iterator a_begin,
- string16::const_iterator a_end,
- const char* b);
-BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
- const char* a_end,
- const char* b);
-BASE_EXPORT bool LowerCaseEqualsASCII(const char* a_begin,
- const char* a_end,
- const char* b_begin,
- const char* b_end);
-BASE_EXPORT bool LowerCaseEqualsASCII(const char16* a_begin,
- const char16* a_end,
- const char* b);
-
-// Performs a case-sensitive string compare. The behavior is undefined if both
-// strings are not ASCII.
-BASE_EXPORT bool EqualsASCII(const string16& a, const StringPiece& b);
-
-// Returns true if str starts with search, or false otherwise.
-// TODO(brettw) the case sensitive flag makes callsites difficult to read.
-// Consider splitting this out in two variants (few callers want
-// case-insensitive compares) or use an enum that makes this more explicit.
-BASE_EXPORT bool StartsWithASCII(const std::string& str,
- const std::string& search,
- bool case_sensitive);
-BASE_EXPORT bool StartsWith(const base::string16& str,
- const base::string16& search,
- bool case_sensitive);
-
-// Returns true if str ends with search, or false otherwise.
-// TODO(brettw) case sensitive flag confusion, see StartsWith above.
-BASE_EXPORT bool EndsWith(const std::string& str,
- const std::string& search,
- bool case_sensitive);
-BASE_EXPORT bool EndsWith(const base::string16& str,
- const base::string16& search,
- bool case_sensitive);
} // namespace base
@@ -363,169 +130,4 @@
#error Define string operations appropriately for your platform
#endif
-// Determines the type of ASCII character, independent of locale (the C
-// library versions will change based on locale).
-template <typename Char>
-inline bool IsAsciiWhitespace(Char c) {
- return c == ' ' || c == '\r' || c == '\n' || c == '\t';
-}
-template <typename Char>
-inline bool IsAsciiAlpha(Char c) {
- return ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'));
-}
-template <typename Char>
-inline bool IsAsciiDigit(Char c) {
- return c >= '0' && c <= '9';
-}
-
-template <typename Char>
-inline bool IsHexDigit(Char c) {
- return (c >= '0' && c <= '9') ||
- (c >= 'A' && c <= 'F') ||
- (c >= 'a' && c <= 'f');
-}
-
-template <typename Char>
-inline char HexDigitToInt(Char c) {
- DCHECK(IsHexDigit(c));
- if (c >= '0' && c <= '9')
- return static_cast<char>(c - '0');
- if (c >= 'A' && c <= 'F')
- return static_cast<char>(c - 'A' + 10);
- if (c >= 'a' && c <= 'f')
- return static_cast<char>(c - 'a' + 10);
- return 0;
-}
-
-// Returns true if it's a whitespace character.
-inline bool IsWhitespace(wchar_t c) {
- return wcschr(base::kWhitespaceWide, c) != NULL;
-}
-
-// Return a byte string in human-readable format with a unit suffix. Not
-// appropriate for use in any UI; use of FormatBytes and friends in ui/base is
-// highly recommended instead. TODO(avi): Figure out how to get callers to use
-// FormatBytes instead; remove this.
-BASE_EXPORT base::string16 FormatBytesUnlocalized(int64 bytes);
-
-// Starting at |start_offset| (usually 0), replace the first instance of
-// |find_this| with |replace_with|.
-BASE_EXPORT void ReplaceFirstSubstringAfterOffset(
- base::string16* str,
- size_t start_offset,
- const base::string16& find_this,
- const base::string16& replace_with);
-BASE_EXPORT void ReplaceFirstSubstringAfterOffset(
- std::string* str,
- size_t start_offset,
- const std::string& find_this,
- const std::string& replace_with);
-
-// Starting at |start_offset| (usually 0), look through |str| and replace all
-// instances of |find_this| with |replace_with|.
-//
-// This does entire substrings; use std::replace in <algorithm> for single
-// characters, for example:
-// std::replace(str.begin(), str.end(), 'a', 'b');
-BASE_EXPORT void ReplaceSubstringsAfterOffset(
- base::string16* str,
- size_t start_offset,
- const base::string16& find_this,
- const base::string16& replace_with);
-BASE_EXPORT void ReplaceSubstringsAfterOffset(std::string* str,
- size_t start_offset,
- const std::string& find_this,
- const std::string& replace_with);
-
-// Reserves enough memory in |str| to accommodate |length_with_null| characters,
-// sets the size of |str| to |length_with_null - 1| characters, and returns a
-// pointer to the underlying contiguous array of characters. This is typically
-// used when calling a function that writes results into a character array, but
-// the caller wants the data to be managed by a string-like object. It is
-// convenient in that is can be used inline in the call, and fast in that it
-// avoids copying the results of the call from a char* into a string.
-//
-// |length_with_null| must be at least 2, since otherwise the underlying string
-// would have size 0, and trying to access &((*str)[0]) in that case can result
-// in a number of problems.
-//
-// Internally, this takes linear time because the resize() call 0-fills the
-// underlying array for potentially all
-// (|length_with_null - 1| * sizeof(string_type::value_type)) bytes. Ideally we
-// could avoid this aspect of the resize() call, as we expect the caller to
-// immediately write over this memory, but there is no other way to set the size
-// of the string, and not doing that will mean people who access |str| rather
-// than str.c_str() will get back a string of whatever size |str| had on entry
-// to this function (probably 0).
-template <class string_type>
-inline typename string_type::value_type* WriteInto(string_type* str,
- size_t length_with_null) {
- DCHECK_GT(length_with_null, 1u);
- str->reserve(length_with_null);
- str->resize(length_with_null - 1);
- return &((*str)[0]);
-}
-
-//-----------------------------------------------------------------------------
-
-// Splits a string into its fields delimited by any of the characters in
-// |delimiters|. Each field is added to the |tokens| vector. Returns the
-// number of tokens found.
-//
-// DEPRECATED. Use SplitStringUsingSet for new code (these just forward).
-// TODO(brettw) convert callers and delete these forwarders.
-BASE_EXPORT size_t Tokenize(const base::string16& str,
- const base::string16& delimiters,
- std::vector<base::string16>* tokens);
-BASE_EXPORT size_t Tokenize(const std::string& str,
- const std::string& delimiters,
- std::vector<std::string>* tokens);
-BASE_EXPORT size_t Tokenize(const base::StringPiece& str,
- const base::StringPiece& delimiters,
- std::vector<base::StringPiece>* tokens);
-
-// Does the opposite of SplitString().
-BASE_EXPORT base::string16 JoinString(const std::vector<base::string16>& parts,
- base::char16 s);
-BASE_EXPORT std::string JoinString(
- const std::vector<std::string>& parts, char s);
-
-// Join |parts| using |separator|.
-BASE_EXPORT std::string JoinString(
- const std::vector<std::string>& parts,
- const std::string& separator);
-BASE_EXPORT base::string16 JoinString(
- const std::vector<base::string16>& parts,
- const base::string16& separator);
-
-// Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| respectively.
-// Additionally, any number of consecutive '$' characters is replaced by that
-// number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be
-// NULL. This only allows you to use up to nine replacements.
-BASE_EXPORT base::string16 ReplaceStringPlaceholders(
- const base::string16& format_string,
- const std::vector<base::string16>& subst,
- std::vector<size_t>* offsets);
-
-BASE_EXPORT std::string ReplaceStringPlaceholders(
- const base::StringPiece& format_string,
- const std::vector<std::string>& subst,
- std::vector<size_t>* offsets);
-
-// Single-string shortcut for ReplaceStringHolders. |offset| may be NULL.
-BASE_EXPORT base::string16 ReplaceStringPlaceholders(
- const base::string16& format_string,
- const base::string16& a,
- size_t* offset);
-
-// Returns true if the string passed in matches the pattern. The pattern
-// string can contain wildcards like * and ?
-// The backslash character (\) is an escape character for * and ?
-// We limit the patterns to having a max of 16 * or ? characters.
-// ? matches 0 or 1 character, while * matches 0 or more characters.
-BASE_EXPORT bool MatchPattern(const base::StringPiece& string,
- const base::StringPiece& pattern);
-BASE_EXPORT bool MatchPattern(const base::string16& string,
- const base::string16& pattern);
-
#endif // BASE_STRINGS_STRING_UTIL_H_
diff --git a/libweave/external/base/strings/string_util_constants.cc b/libweave/external/base/strings/string_util_constants.cc
index aba1b12..905294c 100644
--- a/libweave/external/base/strings/string_util_constants.cc
+++ b/libweave/external/base/strings/string_util_constants.cc
@@ -34,14 +34,6 @@
0x3000, /* IDEOGRAPHIC SPACE */ \
0
-const wchar_t kWhitespaceWide[] = {
- WHITESPACE_UNICODE
-};
-
-const char16 kWhitespaceUTF16[] = {
- WHITESPACE_UNICODE
-};
-
const char kWhitespaceASCII[] = {
0x09, // CHARACTER TABULATION
0x0A, // LINE FEED (LF)
@@ -52,16 +44,4 @@
0
};
-const char16 kWhitespaceASCIIAs16[] = {
- 0x09, // CHARACTER TABULATION
- 0x0A, // LINE FEED (LF)
- 0x0B, // LINE TABULATION
- 0x0C, // FORM FEED (FF)
- 0x0D, // CARRIAGE RETURN (CR)
- 0x20, // SPACE
- 0
-};
-
-const char kUtf8ByteOrderMark[] = "\xEF\xBB\xBF";
-
} // namespace base
diff --git a/libweave/external/base/strings/string_util_posix.h b/libweave/external/base/strings/string_util_posix.h
index f4009d4..ccfff10 100644
--- a/libweave/external/base/strings/string_util_posix.h
+++ b/libweave/external/base/strings/string_util_posix.h
@@ -14,39 +14,11 @@
namespace base {
-// Chromium code style is to not use malloc'd strings; this is only for use
-// for interaction with APIs that require it.
-inline char* strdup(const char* str) {
- return ::strdup(str);
-}
-
-inline int strcasecmp(const char* string1, const char* string2) {
- return ::strcasecmp(string1, string2);
-}
-
-inline int strncasecmp(const char* string1, const char* string2, size_t count) {
- return ::strncasecmp(string1, string2, count);
-}
-
inline int vsnprintf(char* buffer, size_t size,
const char* format, va_list arguments) {
return ::vsnprintf(buffer, size, format, arguments);
}
-inline int strncmp16(const char16* s1, const char16* s2, size_t count) {
-#if defined(WCHAR_T_IS_UTF16)
- return ::wcsncmp(s1, s2, count);
-#elif defined(WCHAR_T_IS_UTF32)
- return c16memcmp(s1, s2, count);
-#endif
-}
-
-inline int vswprintf(wchar_t* buffer, size_t size,
- const wchar_t* format, va_list arguments) {
- DCHECK(IsWprintfFormatPortable(format));
- return ::vswprintf(buffer, size, format, arguments);
-}
-
} // namespace base
#endif // BASE_STRINGS_STRING_UTIL_POSIX_H_
diff --git a/libweave/external/base/strings/string_util_unittest.cc b/libweave/external/base/strings/string_util_unittest.cc
index fb0bead..1a75218 100644
--- a/libweave/external/base/strings/string_util_unittest.cc
+++ b/libweave/external/base/strings/string_util_unittest.cc
@@ -9,317 +9,16 @@
#include <algorithm>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
#include "base/basictypes.h"
-#include "base/strings/string16.h"
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/strings/utf_string_conversion_utils.h"
using ::testing::ElementsAre;
namespace base {
-static const struct trim_case {
- const wchar_t* input;
- const TrimPositions positions;
- const wchar_t* output;
- const TrimPositions return_value;
-} trim_cases[] = {
- {L" Google Video ", TRIM_LEADING, L"Google Video ", TRIM_LEADING},
- {L" Google Video ", TRIM_TRAILING, L" Google Video", TRIM_TRAILING},
- {L" Google Video ", TRIM_ALL, L"Google Video", TRIM_ALL},
- {L"Google Video", TRIM_ALL, L"Google Video", TRIM_NONE},
- {L"", TRIM_ALL, L"", TRIM_NONE},
- {L" ", TRIM_LEADING, L"", TRIM_LEADING},
- {L" ", TRIM_TRAILING, L"", TRIM_TRAILING},
- {L" ", TRIM_ALL, L"", TRIM_ALL},
- {L"\t\rTest String\n", TRIM_ALL, L"Test String", TRIM_ALL},
- {L"\x2002Test String\x00A0\x3000", TRIM_ALL, L"Test String", TRIM_ALL},
-};
-
-static const struct trim_case_ascii {
- const char* input;
- const TrimPositions positions;
- const char* output;
- const TrimPositions return_value;
-} trim_cases_ascii[] = {
- {" Google Video ", TRIM_LEADING, "Google Video ", TRIM_LEADING},
- {" Google Video ", TRIM_TRAILING, " Google Video", TRIM_TRAILING},
- {" Google Video ", TRIM_ALL, "Google Video", TRIM_ALL},
- {"Google Video", TRIM_ALL, "Google Video", TRIM_NONE},
- {"", TRIM_ALL, "", TRIM_NONE},
- {" ", TRIM_LEADING, "", TRIM_LEADING},
- {" ", TRIM_TRAILING, "", TRIM_TRAILING},
- {" ", TRIM_ALL, "", TRIM_ALL},
- {"\t\rTest String\n", TRIM_ALL, "Test String", TRIM_ALL},
-};
-
-namespace {
-
-// Helper used to test TruncateUTF8ToByteSize.
-bool Truncated(const std::string& input,
- const size_t byte_size,
- std::string* output) {
- size_t prev = input.length();
- TruncateUTF8ToByteSize(input, byte_size, output);
- return prev != output->length();
-}
-
-} // namespace
-
-TEST(StringUtilTest, TruncateUTF8ToByteSize) {
- std::string output;
-
- // Empty strings and invalid byte_size arguments
- EXPECT_FALSE(Truncated(std::string(), 0, &output));
- EXPECT_EQ(output, "");
- EXPECT_TRUE(Truncated("\xe1\x80\xbf", 0, &output));
- EXPECT_EQ(output, "");
- EXPECT_FALSE(Truncated("\xe1\x80\xbf", static_cast<size_t>(-1), &output));
- EXPECT_FALSE(Truncated("\xe1\x80\xbf", 4, &output));
-
- // Testing the truncation of valid UTF8 correctly
- EXPECT_TRUE(Truncated("abc", 2, &output));
- EXPECT_EQ(output, "ab");
- EXPECT_TRUE(Truncated("\xc2\x81\xc2\x81", 2, &output));
- EXPECT_EQ(output.compare("\xc2\x81"), 0);
- EXPECT_TRUE(Truncated("\xc2\x81\xc2\x81", 3, &output));
- EXPECT_EQ(output.compare("\xc2\x81"), 0);
- EXPECT_FALSE(Truncated("\xc2\x81\xc2\x81", 4, &output));
- EXPECT_EQ(output.compare("\xc2\x81\xc2\x81"), 0);
-
- {
- const char array[] = "\x00\x00\xc2\x81\xc2\x81";
- const std::string array_string(array, arraysize(array));
- EXPECT_TRUE(Truncated(array_string, 4, &output));
- EXPECT_EQ(output.compare(std::string("\x00\x00\xc2\x81", 4)), 0);
- }
-
- {
- const char array[] = "\x00\xc2\x81\xc2\x81";
- const std::string array_string(array, arraysize(array));
- EXPECT_TRUE(Truncated(array_string, 4, &output));
- EXPECT_EQ(output.compare(std::string("\x00\xc2\x81", 3)), 0);
- }
-
- // Testing invalid UTF8
- EXPECT_TRUE(Truncated("\xed\xa0\x80\xed\xbf\xbf", 6, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xed\xa0\x8f", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xed\xbf\xbf", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- // Testing invalid UTF8 mixed with valid UTF8
- EXPECT_FALSE(Truncated("\xe1\x80\xbf", 3, &output));
- EXPECT_EQ(output.compare("\xe1\x80\xbf"), 0);
- EXPECT_FALSE(Truncated("\xf1\x80\xa0\xbf", 4, &output));
- EXPECT_EQ(output.compare("\xf1\x80\xa0\xbf"), 0);
- EXPECT_FALSE(Truncated("a\xc2\x81\xe1\x80\xbf\xf1\x80\xa0\xbf",
- 10, &output));
- EXPECT_EQ(output.compare("a\xc2\x81\xe1\x80\xbf\xf1\x80\xa0\xbf"), 0);
- EXPECT_TRUE(Truncated("a\xc2\x81\xe1\x80\xbf\xf1""a""\x80\xa0",
- 10, &output));
- EXPECT_EQ(output.compare("a\xc2\x81\xe1\x80\xbf\xf1""a"), 0);
- EXPECT_FALSE(Truncated("\xef\xbb\xbf" "abc", 6, &output));
- EXPECT_EQ(output.compare("\xef\xbb\xbf" "abc"), 0);
-
- // Overlong sequences
- EXPECT_TRUE(Truncated("\xc0\x80", 2, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xc1\x80\xc1\x81", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xe0\x80\x80", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xe0\x82\x80", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xe0\x9f\xbf", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf0\x80\x80\x8D", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf0\x80\x82\x91", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf0\x80\xa0\x80", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf0\x8f\xbb\xbf", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf8\x80\x80\x80\xbf", 5, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xfc\x80\x80\x80\xa0\xa5", 6, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- // Beyond U+10FFFF (the upper limit of Unicode codespace)
- EXPECT_TRUE(Truncated("\xf4\x90\x80\x80", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf8\xa0\xbf\x80\xbf", 5, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xfc\x9c\xbf\x80\xbf\x80", 6, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- // BOMs in UTF-16(BE|LE) and UTF-32(BE|LE)
- EXPECT_TRUE(Truncated("\xfe\xff", 2, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xff\xfe", 2, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- {
- const char array[] = "\x00\x00\xfe\xff";
- const std::string array_string(array, arraysize(array));
- EXPECT_TRUE(Truncated(array_string, 4, &output));
- EXPECT_EQ(output.compare(std::string("\x00\x00", 2)), 0);
- }
-
- // Variants on the previous test
- {
- const char array[] = "\xff\xfe\x00\x00";
- const std::string array_string(array, 4);
- EXPECT_FALSE(Truncated(array_string, 4, &output));
- EXPECT_EQ(output.compare(std::string("\xff\xfe\x00\x00", 4)), 0);
- }
- {
- const char array[] = "\xff\x00\x00\xfe";
- const std::string array_string(array, arraysize(array));
- EXPECT_TRUE(Truncated(array_string, 4, &output));
- EXPECT_EQ(output.compare(std::string("\xff\x00\x00", 3)), 0);
- }
-
- // Non-characters : U+xxFFF[EF] where xx is 0x00 through 0x10 and <FDD0,FDEF>
- EXPECT_TRUE(Truncated("\xef\xbf\xbe", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf0\x8f\xbf\xbe", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xf3\xbf\xbf\xbf", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xef\xb7\x90", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_TRUE(Truncated("\xef\xb7\xaf", 3, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- // Strings in legacy encodings that are valid in UTF-8, but
- // are invalid as UTF-8 in real data.
- EXPECT_TRUE(Truncated("caf\xe9", 4, &output));
- EXPECT_EQ(output.compare("caf"), 0);
- EXPECT_TRUE(Truncated("\xb0\xa1\xb0\xa2", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
- EXPECT_FALSE(Truncated("\xa7\x41\xa6\x6e", 4, &output));
- EXPECT_EQ(output.compare("\xa7\x41\xa6\x6e"), 0);
- EXPECT_TRUE(Truncated("\xa7\x41\xa6\x6e\xd9\xee\xe4\xee", 7,
- &output));
- EXPECT_EQ(output.compare("\xa7\x41\xa6\x6e"), 0);
-
- // Testing using the same string as input and output.
- EXPECT_FALSE(Truncated(output, 4, &output));
- EXPECT_EQ(output.compare("\xa7\x41\xa6\x6e"), 0);
- EXPECT_TRUE(Truncated(output, 3, &output));
- EXPECT_EQ(output.compare("\xa7\x41"), 0);
-
- // "abc" with U+201[CD] in windows-125[0-8]
- EXPECT_TRUE(Truncated("\x93" "abc\x94", 5, &output));
- EXPECT_EQ(output.compare("\x93" "abc"), 0);
-
- // U+0639 U+064E U+0644 U+064E in ISO-8859-6
- EXPECT_TRUE(Truncated("\xd9\xee\xe4\xee", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
-
- // U+03B3 U+03B5 U+03B9 U+03AC in ISO-8859-7
- EXPECT_TRUE(Truncated("\xe3\xe5\xe9\xdC", 4, &output));
- EXPECT_EQ(output.compare(""), 0);
-}
-
-TEST(StringUtilTest, TrimWhitespace) {
- string16 output; // Allow contents to carry over to next testcase
- for (size_t i = 0; i < arraysize(trim_cases); ++i) {
- const trim_case& value = trim_cases[i];
- EXPECT_EQ(value.return_value,
- TrimWhitespace(WideToUTF16(value.input), value.positions,
- &output));
- EXPECT_EQ(WideToUTF16(value.output), output);
- }
-
- // Test that TrimWhitespace() can take the same string for input and output
- output = ASCIIToUTF16(" This is a test \r\n");
- EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output));
- EXPECT_EQ(ASCIIToUTF16("This is a test"), output);
-
- // Once more, but with a string of whitespace
- output = ASCIIToUTF16(" \r\n");
- EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output));
- EXPECT_EQ(string16(), output);
-
- std::string output_ascii;
- for (size_t i = 0; i < arraysize(trim_cases_ascii); ++i) {
- const trim_case_ascii& value = trim_cases_ascii[i];
- EXPECT_EQ(value.return_value,
- TrimWhitespace(value.input, value.positions, &output_ascii));
- EXPECT_EQ(value.output, output_ascii);
- }
-}
-
-static const struct collapse_case {
- const wchar_t* input;
- const bool trim;
- const wchar_t* output;
-} collapse_cases[] = {
- {L" Google Video ", false, L"Google Video"},
- {L"Google Video", false, L"Google Video"},
- {L"", false, L""},
- {L" ", false, L""},
- {L"\t\rTest String\n", false, L"Test String"},
- {L"\x2002Test String\x00A0\x3000", false, L"Test String"},
- {L" Test \n \t String ", false, L"Test String"},
- {L"\x2002Test\x1680 \x2028 \tString\x00A0\x3000", false, L"Test String"},
- {L" Test String", false, L"Test String"},
- {L"Test String ", false, L"Test String"},
- {L"Test String", false, L"Test String"},
- {L"", true, L""},
- {L"\n", true, L""},
- {L" \r ", true, L""},
- {L"\nFoo", true, L"Foo"},
- {L"\r Foo ", true, L"Foo"},
- {L" Foo bar ", true, L"Foo bar"},
- {L" \tFoo bar \n", true, L"Foo bar"},
- {L" a \r b\n c \r\n d \t\re \t f \n ", true, L"abcde f"},
-};
-
-TEST(StringUtilTest, CollapseWhitespace) {
- for (size_t i = 0; i < arraysize(collapse_cases); ++i) {
- const collapse_case& value = collapse_cases[i];
- EXPECT_EQ(WideToUTF16(value.output),
- CollapseWhitespace(WideToUTF16(value.input), value.trim));
- }
-}
-
-static const struct collapse_case_ascii {
- const char* input;
- const bool trim;
- const char* output;
-} collapse_cases_ascii[] = {
- {" Google Video ", false, "Google Video"},
- {"Google Video", false, "Google Video"},
- {"", false, ""},
- {" ", false, ""},
- {"\t\rTest String\n", false, "Test String"},
- {" Test \n \t String ", false, "Test String"},
- {" Test String", false, "Test String"},
- {"Test String ", false, "Test String"},
- {"Test String", false, "Test String"},
- {"", true, ""},
- {"\n", true, ""},
- {" \r ", true, ""},
- {"\nFoo", true, "Foo"},
- {"\r Foo ", true, "Foo"},
- {" Foo bar ", true, "Foo bar"},
- {" \tFoo bar \n", true, "Foo bar"},
- {" a \r b\n c \r\n d \t\re \t f \n ", true, "abcde f"},
-};
-
-TEST(StringUtilTest, CollapseWhitespaceASCII) {
- for (size_t i = 0; i < arraysize(collapse_cases_ascii); ++i) {
- const collapse_case_ascii& value = collapse_cases_ascii[i];
- EXPECT_EQ(value.output, CollapseWhitespaceASCII(value.input, value.trim));
- }
-}
-
TEST(StringUtilTest, IsStringUTF8) {
EXPECT_TRUE(IsStringUTF8("abc"));
EXPECT_TRUE(IsStringUTF8("\xc2\x81"));
@@ -389,10 +88,6 @@
TEST(StringUtilTest, IsStringASCII) {
static char char_ascii[] =
"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
- static char16 char16_ascii[] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A',
- 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6',
- '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 0 };
static std::wstring wchar_ascii(
L"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF");
@@ -414,725 +109,6 @@
}
}
}
-
- {
- const size_t string_length = arraysize(char16_ascii) - 1;
- for (size_t offset = 0; offset < 4; ++offset) {
- for (size_t len = 0, max_len = string_length - offset; len < max_len;
- ++len) {
- EXPECT_TRUE(IsStringASCII(StringPiece16(char16_ascii + offset, len)));
- for (size_t char_pos = offset; char_pos < len; ++char_pos) {
- char16_ascii[char_pos] |= 0x80;
- EXPECT_FALSE(
- IsStringASCII(StringPiece16(char16_ascii + offset, len)));
- char16_ascii[char_pos] &= ~0x80;
- // Also test when the upper half is non-zero.
- char16_ascii[char_pos] |= 0x100;
- EXPECT_FALSE(
- IsStringASCII(StringPiece16(char16_ascii + offset, len)));
- char16_ascii[char_pos] &= ~0x100;
- }
- }
- }
- }
-
- {
- const size_t string_length = wchar_ascii.length();
- for (size_t len = 0; len < string_length; ++len) {
- EXPECT_TRUE(IsStringASCII(wchar_ascii.substr(0, len)));
- for (size_t char_pos = 0; char_pos < len; ++char_pos) {
- wchar_ascii[char_pos] |= 0x80;
- EXPECT_FALSE(
- IsStringASCII(wchar_ascii.substr(0, len)));
- wchar_ascii[char_pos] &= ~0x80;
- wchar_ascii[char_pos] |= 0x100;
- EXPECT_FALSE(
- IsStringASCII(wchar_ascii.substr(0, len)));
- wchar_ascii[char_pos] &= ~0x100;
-#if defined(WCHAR_T_IS_UTF32)
- wchar_ascii[char_pos] |= 0x10000;
- EXPECT_FALSE(
- IsStringASCII(wchar_ascii.substr(0, len)));
- wchar_ascii[char_pos] &= ~0x10000;
-#endif // WCHAR_T_IS_UTF32
- }
- }
- }
-}
-
-TEST(StringUtilTest, ConvertASCII) {
- static const char* const char_cases[] = {
- "Google Video",
- "Hello, world\n",
- "0123ABCDwxyz \a\b\t\r\n!+,.~"
- };
-
- static const wchar_t* const wchar_cases[] = {
- L"Google Video",
- L"Hello, world\n",
- L"0123ABCDwxyz \a\b\t\r\n!+,.~"
- };
-
- for (size_t i = 0; i < arraysize(char_cases); ++i) {
- EXPECT_TRUE(IsStringASCII(char_cases[i]));
- string16 utf16 = ASCIIToUTF16(char_cases[i]);
- EXPECT_EQ(WideToUTF16(wchar_cases[i]), utf16);
-
- std::string ascii = UTF16ToASCII(WideToUTF16(wchar_cases[i]));
- EXPECT_EQ(char_cases[i], ascii);
- }
-
- EXPECT_FALSE(IsStringASCII("Google \x80Video"));
-
- // Convert empty strings.
- string16 empty16;
- std::string empty;
- EXPECT_EQ(empty, UTF16ToASCII(empty16));
- EXPECT_EQ(empty16, ASCIIToUTF16(empty));
-
- // Convert strings with an embedded NUL character.
- const char chars_with_nul[] = "test\0string";
- const int length_with_nul = arraysize(chars_with_nul) - 1;
- std::string string_with_nul(chars_with_nul, length_with_nul);
- string16 string16_with_nul = ASCIIToUTF16(string_with_nul);
- EXPECT_EQ(static_cast<string16::size_type>(length_with_nul),
- string16_with_nul.length());
- std::string narrow_with_nul = UTF16ToASCII(string16_with_nul);
- EXPECT_EQ(static_cast<std::string::size_type>(length_with_nul),
- narrow_with_nul.length());
- EXPECT_EQ(0, string_with_nul.compare(narrow_with_nul));
-}
-
-TEST(StringUtilTest, ToUpperASCII) {
- EXPECT_EQ('C', ToUpperASCII('C'));
- EXPECT_EQ('C', ToUpperASCII('c'));
- EXPECT_EQ('2', ToUpperASCII('2'));
-
- EXPECT_EQ(L'C', ToUpperASCII(L'C'));
- EXPECT_EQ(L'C', ToUpperASCII(L'c'));
- EXPECT_EQ(L'2', ToUpperASCII(L'2'));
-
- std::string in_place_a("Cc2");
- StringToUpperASCII(&in_place_a);
- EXPECT_EQ("CC2", in_place_a);
-
- std::wstring in_place_w(L"Cc2");
- StringToUpperASCII(&in_place_w);
- EXPECT_EQ(L"CC2", in_place_w);
-
- std::string original_a("Cc2");
- std::string upper_a = StringToUpperASCII(original_a);
- EXPECT_EQ("CC2", upper_a);
-
- std::wstring original_w(L"Cc2");
- std::wstring upper_w = StringToUpperASCII(original_w);
- EXPECT_EQ(L"CC2", upper_w);
-}
-
-TEST(StringUtilTest, LowerCaseEqualsASCII) {
- static const struct {
- const char* src_a;
- const char* dst;
- } lowercase_cases[] = {
- { "FoO", "foo" },
- { "foo", "foo" },
- { "FOO", "foo" },
- };
-
- for (size_t i = 0; i < arraysize(lowercase_cases); ++i) {
- EXPECT_TRUE(LowerCaseEqualsASCII(ASCIIToUTF16(lowercase_cases[i].src_a),
- lowercase_cases[i].dst));
- EXPECT_TRUE(LowerCaseEqualsASCII(lowercase_cases[i].src_a,
- lowercase_cases[i].dst));
- }
-}
-
-TEST(StringUtilTest, FormatBytesUnlocalized) {
- static const struct {
- int64 bytes;
- const char* expected;
- } cases[] = {
- // Expected behavior: we show one post-decimal digit when we have
- // under two pre-decimal digits, except in cases where it makes no
- // sense (zero or bytes).
- // Since we switch units once we cross the 1000 mark, this keeps
- // the display of file sizes or bytes consistently around three
- // digits.
- {0, "0 B"},
- {512, "512 B"},
- {1024*1024, "1.0 MB"},
- {1024*1024*1024, "1.0 GB"},
- {10LL*1024*1024*1024, "10.0 GB"},
- {99LL*1024*1024*1024, "99.0 GB"},
- {105LL*1024*1024*1024, "105 GB"},
- {105LL*1024*1024*1024 + 500LL*1024*1024, "105 GB"},
- {~(1LL << 63), "8192 PB"},
-
- {99*1024 + 103, "99.1 kB"},
- {1024*1024 + 103, "1.0 MB"},
- {1024*1024 + 205 * 1024, "1.2 MB"},
- {1024*1024*1024 + (927 * 1024*1024), "1.9 GB"},
- {10LL*1024*1024*1024, "10.0 GB"},
- {100LL*1024*1024*1024, "100 GB"},
- };
-
- for (size_t i = 0; i < arraysize(cases); ++i) {
- EXPECT_EQ(ASCIIToUTF16(cases[i].expected),
- FormatBytesUnlocalized(cases[i].bytes));
- }
-}
-TEST(StringUtilTest, ReplaceSubstringsAfterOffset) {
- static const struct {
- const char* str;
- string16::size_type start_offset;
- const char* find_this;
- const char* replace_with;
- const char* expected;
- } cases[] = {
- {"aaa", 0, "a", "b", "bbb"},
- {"abb", 0, "ab", "a", "ab"},
- {"Removing some substrings inging", 0, "ing", "", "Remov some substrs "},
- {"Not found", 0, "x", "0", "Not found"},
- {"Not found again", 5, "x", "0", "Not found again"},
- {" Making it much longer ", 0, " ", "Four score and seven years ago",
- "Four score and seven years agoMakingFour score and seven years agoit"
- "Four score and seven years agomuchFour score and seven years agolonger"
- "Four score and seven years ago"},
- {"Invalid offset", 9999, "t", "foobar", "Invalid offset"},
- {"Replace me only me once", 9, "me ", "", "Replace me only once"},
- {"abababab", 2, "ab", "c", "abccc"},
- };
-
- for (size_t i = 0; i < arraysize(cases); i++) {
- string16 str = ASCIIToUTF16(cases[i].str);
- ReplaceSubstringsAfterOffset(&str, cases[i].start_offset,
- ASCIIToUTF16(cases[i].find_this),
- ASCIIToUTF16(cases[i].replace_with));
- EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str);
- }
-}
-
-TEST(StringUtilTest, ReplaceFirstSubstringAfterOffset) {
- static const struct {
- const char* str;
- string16::size_type start_offset;
- const char* find_this;
- const char* replace_with;
- const char* expected;
- } cases[] = {
- {"aaa", 0, "a", "b", "baa"},
- {"abb", 0, "ab", "a", "ab"},
- {"Removing some substrings inging", 0, "ing", "",
- "Remov some substrings inging"},
- {"Not found", 0, "x", "0", "Not found"},
- {"Not found again", 5, "x", "0", "Not found again"},
- {" Making it much longer ", 0, " ", "Four score and seven years ago",
- "Four score and seven years agoMaking it much longer "},
- {"Invalid offset", 9999, "t", "foobar", "Invalid offset"},
- {"Replace me only me once", 4, "me ", "", "Replace only me once"},
- {"abababab", 2, "ab", "c", "abcabab"},
- };
-
- for (size_t i = 0; i < arraysize(cases); i++) {
- string16 str = ASCIIToUTF16(cases[i].str);
- ReplaceFirstSubstringAfterOffset(&str, cases[i].start_offset,
- ASCIIToUTF16(cases[i].find_this),
- ASCIIToUTF16(cases[i].replace_with));
- EXPECT_EQ(ASCIIToUTF16(cases[i].expected), str);
- }
-}
-
-TEST(StringUtilTest, HexDigitToInt) {
- EXPECT_EQ(0, HexDigitToInt('0'));
- EXPECT_EQ(1, HexDigitToInt('1'));
- EXPECT_EQ(2, HexDigitToInt('2'));
- EXPECT_EQ(3, HexDigitToInt('3'));
- EXPECT_EQ(4, HexDigitToInt('4'));
- EXPECT_EQ(5, HexDigitToInt('5'));
- EXPECT_EQ(6, HexDigitToInt('6'));
- EXPECT_EQ(7, HexDigitToInt('7'));
- EXPECT_EQ(8, HexDigitToInt('8'));
- EXPECT_EQ(9, HexDigitToInt('9'));
- EXPECT_EQ(10, HexDigitToInt('A'));
- EXPECT_EQ(11, HexDigitToInt('B'));
- EXPECT_EQ(12, HexDigitToInt('C'));
- EXPECT_EQ(13, HexDigitToInt('D'));
- EXPECT_EQ(14, HexDigitToInt('E'));
- EXPECT_EQ(15, HexDigitToInt('F'));
-
- // Verify the lower case as well.
- EXPECT_EQ(10, HexDigitToInt('a'));
- EXPECT_EQ(11, HexDigitToInt('b'));
- EXPECT_EQ(12, HexDigitToInt('c'));
- EXPECT_EQ(13, HexDigitToInt('d'));
- EXPECT_EQ(14, HexDigitToInt('e'));
- EXPECT_EQ(15, HexDigitToInt('f'));
-}
-
-// Test for Tokenize
-template <typename STR>
-void TokenizeTest() {
- std::vector<STR> r;
- size_t size;
-
- size = Tokenize(STR("This is a string"), STR(" "), &r);
- EXPECT_EQ(4U, size);
- ASSERT_EQ(4U, r.size());
- EXPECT_EQ(r[0], STR("This"));
- EXPECT_EQ(r[1], STR("is"));
- EXPECT_EQ(r[2], STR("a"));
- EXPECT_EQ(r[3], STR("string"));
- r.clear();
-
- size = Tokenize(STR("one,two,three"), STR(","), &r);
- EXPECT_EQ(3U, size);
- ASSERT_EQ(3U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR("two"));
- EXPECT_EQ(r[2], STR("three"));
- r.clear();
-
- size = Tokenize(STR("one,two:three;four"), STR(",:"), &r);
- EXPECT_EQ(3U, size);
- ASSERT_EQ(3U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR("two"));
- EXPECT_EQ(r[2], STR("three;four"));
- r.clear();
-
- size = Tokenize(STR("one,two:three;four"), STR(";,:"), &r);
- EXPECT_EQ(4U, size);
- ASSERT_EQ(4U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR("two"));
- EXPECT_EQ(r[2], STR("three"));
- EXPECT_EQ(r[3], STR("four"));
- r.clear();
-
- size = Tokenize(STR("one, two, three"), STR(","), &r);
- EXPECT_EQ(3U, size);
- ASSERT_EQ(3U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR(" two"));
- EXPECT_EQ(r[2], STR(" three"));
- r.clear();
-
- size = Tokenize(STR("one, two, three, "), STR(","), &r);
- EXPECT_EQ(4U, size);
- ASSERT_EQ(4U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR(" two"));
- EXPECT_EQ(r[2], STR(" three"));
- EXPECT_EQ(r[3], STR(" "));
- r.clear();
-
- size = Tokenize(STR("one, two, three,"), STR(","), &r);
- EXPECT_EQ(3U, size);
- ASSERT_EQ(3U, r.size());
- EXPECT_EQ(r[0], STR("one"));
- EXPECT_EQ(r[1], STR(" two"));
- EXPECT_EQ(r[2], STR(" three"));
- r.clear();
-
- size = Tokenize(STR(), STR(","), &r);
- EXPECT_EQ(0U, size);
- ASSERT_EQ(0U, r.size());
- r.clear();
-
- size = Tokenize(STR(","), STR(","), &r);
- EXPECT_EQ(0U, size);
- ASSERT_EQ(0U, r.size());
- r.clear();
-
- size = Tokenize(STR(",;:."), STR(".:;,"), &r);
- EXPECT_EQ(0U, size);
- ASSERT_EQ(0U, r.size());
- r.clear();
-
- size = Tokenize(STR("\t\ta\t"), STR("\t"), &r);
- EXPECT_EQ(1U, size);
- ASSERT_EQ(1U, r.size());
- EXPECT_EQ(r[0], STR("a"));
- r.clear();
-
- size = Tokenize(STR("\ta\t\nb\tcc"), STR("\n"), &r);
- EXPECT_EQ(2U, size);
- ASSERT_EQ(2U, r.size());
- EXPECT_EQ(r[0], STR("\ta\t"));
- EXPECT_EQ(r[1], STR("b\tcc"));
- r.clear();
-}
-
-TEST(StringUtilTest, TokenizeStdString) {
- TokenizeTest<std::string>();
-}
-
-TEST(StringUtilTest, TokenizeStringPiece) {
- TokenizeTest<StringPiece>();
-}
-
-// Test for JoinString
-TEST(StringUtilTest, JoinString) {
- std::vector<std::string> in;
- EXPECT_EQ("", JoinString(in, ','));
-
- in.push_back("a");
- EXPECT_EQ("a", JoinString(in, ','));
-
- in.push_back("b");
- in.push_back("c");
- EXPECT_EQ("a,b,c", JoinString(in, ','));
-
- in.push_back(std::string());
- EXPECT_EQ("a,b,c,", JoinString(in, ','));
- in.push_back(" ");
- EXPECT_EQ("a|b|c|| ", JoinString(in, '|'));
-}
-
-// Test for JoinString overloaded with std::string separator
-TEST(StringUtilTest, JoinStringWithString) {
- std::string separator(", ");
- std::vector<std::string> parts;
- EXPECT_EQ(std::string(), JoinString(parts, separator));
-
- parts.push_back("a");
- EXPECT_EQ("a", JoinString(parts, separator));
-
- parts.push_back("b");
- parts.push_back("c");
- EXPECT_EQ("a, b, c", JoinString(parts, separator));
-
- parts.push_back(std::string());
- EXPECT_EQ("a, b, c, ", JoinString(parts, separator));
- parts.push_back(" ");
- EXPECT_EQ("a|b|c|| ", JoinString(parts, "|"));
-}
-
-// Test for JoinString overloaded with string16 separator
-TEST(StringUtilTest, JoinStringWithString16) {
- string16 separator = ASCIIToUTF16(", ");
- std::vector<string16> parts;
- EXPECT_EQ(string16(), JoinString(parts, separator));
-
- parts.push_back(ASCIIToUTF16("a"));
- EXPECT_EQ(ASCIIToUTF16("a"), JoinString(parts, separator));
-
- parts.push_back(ASCIIToUTF16("b"));
- parts.push_back(ASCIIToUTF16("c"));
- EXPECT_EQ(ASCIIToUTF16("a, b, c"), JoinString(parts, separator));
-
- parts.push_back(ASCIIToUTF16(""));
- EXPECT_EQ(ASCIIToUTF16("a, b, c, "), JoinString(parts, separator));
- parts.push_back(ASCIIToUTF16(" "));
- EXPECT_EQ(ASCIIToUTF16("a|b|c|| "), JoinString(parts, ASCIIToUTF16("|")));
-}
-
-TEST(StringUtilTest, StartsWith) {
- EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", true));
- EXPECT_FALSE(StartsWithASCII("JavaScript:url", "javascript", true));
- EXPECT_TRUE(StartsWithASCII("javascript:url", "javascript", false));
- EXPECT_TRUE(StartsWithASCII("JavaScript:url", "javascript", false));
- EXPECT_FALSE(StartsWithASCII("java", "javascript", true));
- EXPECT_FALSE(StartsWithASCII("java", "javascript", false));
- EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", false));
- EXPECT_FALSE(StartsWithASCII(std::string(), "javascript", true));
- EXPECT_TRUE(StartsWithASCII("java", std::string(), false));
- EXPECT_TRUE(StartsWithASCII("java", std::string(), true));
-
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
- ASCIIToUTF16("javascript"), true));
- EXPECT_FALSE(StartsWith(ASCIIToUTF16("JavaScript:url"),
- ASCIIToUTF16("javascript"), true));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("javascript:url"),
- ASCIIToUTF16("javascript"), false));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("JavaScript:url"),
- ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"),
- ASCIIToUTF16("javascript"), true));
- EXPECT_FALSE(StartsWith(ASCIIToUTF16("java"),
- ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), false));
- EXPECT_FALSE(StartsWith(string16(), ASCIIToUTF16("javascript"), true));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), false));
- EXPECT_TRUE(StartsWith(ASCIIToUTF16("java"), string16(), true));
-}
-
-TEST(StringUtilTest, EndsWith) {
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.Plugin"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.Plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16(".plug"), ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"),
- ASCIIToUTF16(".plugin"), true));
- EXPECT_FALSE(EndsWith(ASCIIToUTF16("Foo.plugin Bar"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), false));
- EXPECT_FALSE(EndsWith(string16(), ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16("Foo.plugin"), string16(), true));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"),
- ASCIIToUTF16(".plugin"), false));
- EXPECT_TRUE(EndsWith(ASCIIToUTF16(".plugin"), ASCIIToUTF16(".plugin"), true));
- EXPECT_TRUE(EndsWith(string16(), string16(), false));
- EXPECT_TRUE(EndsWith(string16(), string16(), true));
-}
-
-TEST(StringUtilTest, GetStringFWithOffsets) {
- std::vector<string16> subst;
- subst.push_back(ASCIIToUTF16("1"));
- subst.push_back(ASCIIToUTF16("2"));
- std::vector<size_t> offsets;
-
- ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $1. Your number is $2."),
- subst,
- &offsets);
- EXPECT_EQ(2U, offsets.size());
- EXPECT_EQ(7U, offsets[0]);
- EXPECT_EQ(25U, offsets[1]);
- offsets.clear();
-
- ReplaceStringPlaceholders(ASCIIToUTF16("Hello, $2. Your number is $1."),
- subst,
- &offsets);
- EXPECT_EQ(2U, offsets.size());
- EXPECT_EQ(25U, offsets[0]);
- EXPECT_EQ(7U, offsets[1]);
- offsets.clear();
-}
-
-TEST(StringUtilTest, ReplaceStringPlaceholdersTooFew) {
- // Test whether replacestringplaceholders works as expected when there
- // are fewer inputs than outputs.
- std::vector<string16> subst;
- subst.push_back(ASCIIToUTF16("9a"));
- subst.push_back(ASCIIToUTF16("8b"));
- subst.push_back(ASCIIToUTF16("7c"));
-
- string16 formatted =
- ReplaceStringPlaceholders(
- ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$1g,$2h,$3i"), subst, NULL);
-
- EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,d,e,f,9ag,8bh,7ci"));
-}
-
-TEST(StringUtilTest, ReplaceStringPlaceholders) {
- std::vector<string16> subst;
- subst.push_back(ASCIIToUTF16("9a"));
- subst.push_back(ASCIIToUTF16("8b"));
- subst.push_back(ASCIIToUTF16("7c"));
- subst.push_back(ASCIIToUTF16("6d"));
- subst.push_back(ASCIIToUTF16("5e"));
- subst.push_back(ASCIIToUTF16("4f"));
- subst.push_back(ASCIIToUTF16("3g"));
- subst.push_back(ASCIIToUTF16("2h"));
- subst.push_back(ASCIIToUTF16("1i"));
-
- string16 formatted =
- ReplaceStringPlaceholders(
- ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i"), subst, NULL);
-
- EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii"));
-}
-
-TEST(StringUtilTest, ReplaceStringPlaceholdersMoreThan9Replacements) {
- std::vector<string16> subst;
- subst.push_back(ASCIIToUTF16("9a"));
- subst.push_back(ASCIIToUTF16("8b"));
- subst.push_back(ASCIIToUTF16("7c"));
- subst.push_back(ASCIIToUTF16("6d"));
- subst.push_back(ASCIIToUTF16("5e"));
- subst.push_back(ASCIIToUTF16("4f"));
- subst.push_back(ASCIIToUTF16("3g"));
- subst.push_back(ASCIIToUTF16("2h"));
- subst.push_back(ASCIIToUTF16("1i"));
- subst.push_back(ASCIIToUTF16("0j"));
- subst.push_back(ASCIIToUTF16("-1k"));
- subst.push_back(ASCIIToUTF16("-2l"));
- subst.push_back(ASCIIToUTF16("-3m"));
- subst.push_back(ASCIIToUTF16("-4n"));
-
- string16 formatted =
- ReplaceStringPlaceholders(
- ASCIIToUTF16("$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i,"
- "$10j,$11k,$12l,$13m,$14n,$1"), subst, NULL);
-
- EXPECT_EQ(formatted, ASCIIToUTF16("9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,"
- "1ii,0jj,-1kk,-2ll,-3mm,-4nn,9a"));
-}
-
-TEST(StringUtilTest, StdStringReplaceStringPlaceholders) {
- std::vector<std::string> subst;
- subst.push_back("9a");
- subst.push_back("8b");
- subst.push_back("7c");
- subst.push_back("6d");
- subst.push_back("5e");
- subst.push_back("4f");
- subst.push_back("3g");
- subst.push_back("2h");
- subst.push_back("1i");
-
- std::string formatted =
- ReplaceStringPlaceholders(
- "$1a,$2b,$3c,$4d,$5e,$6f,$7g,$8h,$9i", subst, NULL);
-
- EXPECT_EQ(formatted, "9aa,8bb,7cc,6dd,5ee,4ff,3gg,2hh,1ii");
-}
-
-TEST(StringUtilTest, ReplaceStringPlaceholdersConsecutiveDollarSigns) {
- std::vector<std::string> subst;
- subst.push_back("a");
- subst.push_back("b");
- subst.push_back("c");
- EXPECT_EQ(ReplaceStringPlaceholders("$$1 $$$2 $$$$3", subst, NULL),
- "$1 $$2 $$$3");
-}
-
-TEST(StringUtilTest, MatchPatternTest) {
- EXPECT_TRUE(MatchPattern("www.google.com", "*.com"));
- EXPECT_TRUE(MatchPattern("www.google.com", "*"));
- EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org"));
- EXPECT_TRUE(MatchPattern("Hello", "H?l?o"));
- EXPECT_FALSE(MatchPattern("www.google.com", "http://*)"));
- EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM"));
- EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*"));
- EXPECT_FALSE(MatchPattern("", "*.*"));
- EXPECT_TRUE(MatchPattern("", "*"));
- EXPECT_TRUE(MatchPattern("", "?"));
- EXPECT_TRUE(MatchPattern("", ""));
- EXPECT_FALSE(MatchPattern("Hello", ""));
- EXPECT_TRUE(MatchPattern("Hello*", "Hello*"));
- // Stop after a certain recursion depth.
- EXPECT_FALSE(MatchPattern("123456789012345678", "?????????????????*"));
-
- // Test UTF8 matching.
- EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0", "*\xe2\x99\xa0"));
- EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0.", "heart: ?."));
- EXPECT_TRUE(MatchPattern("hearts: \xe2\x99\xa0\xe2\x99\xa0", "*"));
- // Invalid sequences should be handled as a single invalid character.
- EXPECT_TRUE(MatchPattern("invalid: \xef\xbf\xbe", "invalid: ?"));
- // If the pattern has invalid characters, it shouldn't match anything.
- EXPECT_FALSE(MatchPattern("\xf4\x90\x80\x80", "\xf4\x90\x80\x80"));
-
- // Test UTF16 character matching.
- EXPECT_TRUE(MatchPattern(UTF8ToUTF16("www.google.com"),
- UTF8ToUTF16("*.com")));
- EXPECT_TRUE(MatchPattern(UTF8ToUTF16("Hello*1234"),
- UTF8ToUTF16("He??o\\*1*")));
-
- // This test verifies that consecutive wild cards are collapsed into 1
- // wildcard (when this doesn't occur, MatchPattern reaches it's maximum
- // recursion depth).
- EXPECT_TRUE(MatchPattern(UTF8ToUTF16("Hello"),
- UTF8ToUTF16("He********************************o")));
-}
-
-TEST(StringUtilTest, LcpyTest) {
- // Test the normal case where we fit in our buffer.
- {
- char dst[10];
- wchar_t wdst[10];
- EXPECT_EQ(7U, strlcpy(dst, "abcdefg", arraysize(dst)));
- EXPECT_EQ(0, memcmp(dst, "abcdefg", 8));
- EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", arraysize(wdst)));
- EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8));
- }
-
- // Test dst_size == 0, nothing should be written to |dst| and we should
- // have the equivalent of strlen(src).
- {
- char dst[2] = {1, 2};
- wchar_t wdst[2] = {1, 2};
- EXPECT_EQ(7U, strlcpy(dst, "abcdefg", 0));
- EXPECT_EQ(1, dst[0]);
- EXPECT_EQ(2, dst[1]);
- EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", 0));
- EXPECT_EQ(static_cast<wchar_t>(1), wdst[0]);
- EXPECT_EQ(static_cast<wchar_t>(2), wdst[1]);
- }
-
- // Test the case were we _just_ competely fit including the null.
- {
- char dst[8];
- wchar_t wdst[8];
- EXPECT_EQ(7U, strlcpy(dst, "abcdefg", arraysize(dst)));
- EXPECT_EQ(0, memcmp(dst, "abcdefg", 8));
- EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", arraysize(wdst)));
- EXPECT_EQ(0, memcmp(wdst, L"abcdefg", sizeof(wchar_t) * 8));
- }
-
- // Test the case were we we are one smaller, so we can't fit the null.
- {
- char dst[7];
- wchar_t wdst[7];
- EXPECT_EQ(7U, strlcpy(dst, "abcdefg", arraysize(dst)));
- EXPECT_EQ(0, memcmp(dst, "abcdef", 7));
- EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", arraysize(wdst)));
- EXPECT_EQ(0, memcmp(wdst, L"abcdef", sizeof(wchar_t) * 7));
- }
-
- // Test the case were we are just too small.
- {
- char dst[3];
- wchar_t wdst[3];
- EXPECT_EQ(7U, strlcpy(dst, "abcdefg", arraysize(dst)));
- EXPECT_EQ(0, memcmp(dst, "ab", 3));
- EXPECT_EQ(7U, wcslcpy(wdst, L"abcdefg", arraysize(wdst)));
- EXPECT_EQ(0, memcmp(wdst, L"ab", sizeof(wchar_t) * 3));
- }
-}
-
-TEST(StringUtilTest, WprintfFormatPortabilityTest) {
- static const struct {
- const wchar_t* input;
- bool portable;
- } cases[] = {
- { L"%ls", true },
- { L"%s", false },
- { L"%S", false },
- { L"%lS", false },
- { L"Hello, %s", false },
- { L"%lc", true },
- { L"%c", false },
- { L"%C", false },
- { L"%lC", false },
- { L"%ls %s", false },
- { L"%s %ls", false },
- { L"%s %ls %s", false },
- { L"%f", true },
- { L"%f %F", false },
- { L"%d %D", false },
- { L"%o %O", false },
- { L"%u %U", false },
- { L"%f %d %o %u", true },
- { L"%-8d (%02.1f%)", true },
- { L"% 10s", false },
- { L"% 10ls", true }
- };
- for (size_t i = 0; i < arraysize(cases); ++i)
- EXPECT_EQ(cases[i].portable, IsWprintfFormatPortable(cases[i].input));
-}
-
-TEST(StringUtilTest, RemoveChars) {
- const char kRemoveChars[] = "-/+*";
- std::string input = "A-+bc/d!*";
- EXPECT_TRUE(RemoveChars(input, kRemoveChars, &input));
- EXPECT_EQ("Abcd!", input);
-
- // No characters match kRemoveChars.
- EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input));
- EXPECT_EQ("Abcd!", input);
-
- // Empty string.
- input.clear();
- EXPECT_FALSE(RemoveChars(input, kRemoveChars, &input));
- EXPECT_EQ(std::string(), input);
}
TEST(StringUtilTest, ReplaceChars) {
@@ -1169,67 +145,4 @@
}
}
-TEST(StringUtilTest, ContainsOnlyChars) {
- // Providing an empty list of characters should return false but for the empty
- // string.
- EXPECT_TRUE(ContainsOnlyChars(std::string(), std::string()));
- EXPECT_FALSE(ContainsOnlyChars("Hello", std::string()));
-
- EXPECT_TRUE(ContainsOnlyChars(std::string(), "1234"));
- EXPECT_TRUE(ContainsOnlyChars("1", "1234"));
- EXPECT_TRUE(ContainsOnlyChars("1", "4321"));
- EXPECT_TRUE(ContainsOnlyChars("123", "4321"));
- EXPECT_FALSE(ContainsOnlyChars("123a", "4321"));
-
- EXPECT_TRUE(ContainsOnlyChars(std::string(), kWhitespaceASCII));
- EXPECT_TRUE(ContainsOnlyChars(" ", kWhitespaceASCII));
- EXPECT_TRUE(ContainsOnlyChars("\t", kWhitespaceASCII));
- EXPECT_TRUE(ContainsOnlyChars("\t \r \n ", kWhitespaceASCII));
- EXPECT_FALSE(ContainsOnlyChars("a", kWhitespaceASCII));
- EXPECT_FALSE(ContainsOnlyChars("\thello\r \n ", kWhitespaceASCII));
-
- EXPECT_TRUE(ContainsOnlyChars(string16(), kWhitespaceUTF16));
- EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16(" "), kWhitespaceUTF16));
- EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t"), kWhitespaceUTF16));
- EXPECT_TRUE(ContainsOnlyChars(ASCIIToUTF16("\t \r \n "), kWhitespaceUTF16));
- EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("a"), kWhitespaceUTF16));
- EXPECT_FALSE(ContainsOnlyChars(ASCIIToUTF16("\thello\r \n "),
- kWhitespaceUTF16));
-}
-
-class WriteIntoTest : public testing::Test {
- protected:
- static void WritesCorrectly(size_t num_chars) {
- std::string buffer;
- char kOriginal[] = "supercali";
- strncpy(WriteInto(&buffer, num_chars + 1), kOriginal, num_chars);
- // Using std::string(buffer.c_str()) instead of |buffer| truncates the
- // string at the first \0.
- EXPECT_EQ(std::string(kOriginal,
- std::min(num_chars, arraysize(kOriginal) - 1)),
- std::string(buffer.c_str()));
- EXPECT_EQ(num_chars, buffer.size());
- }
-};
-
-TEST_F(WriteIntoTest, WriteInto) {
- // Validate that WriteInto reserves enough space and
- // sizes a string correctly.
- WritesCorrectly(1);
- WritesCorrectly(2);
- WritesCorrectly(5000);
-
- // Validate that WriteInto doesn't modify other strings
- // when using a Copy-on-Write implementation.
- const char kLive[] = "live";
- const char kDead[] = "dead";
- const std::string live = kLive;
- std::string dead = live;
- strncpy(WriteInto(&dead, 5), kDead, 4);
- EXPECT_EQ(kDead, dead);
- EXPECT_EQ(4u, dead.size());
- EXPECT_EQ(kLive, live);
- EXPECT_EQ(4u, live.size());
-}
-
} // namespace base
diff --git a/libweave/external/base/strings/stringprintf.cc b/libweave/external/base/strings/stringprintf.cc
index 537873d..5f1ad9b 100644
--- a/libweave/external/base/strings/stringprintf.cc
+++ b/libweave/external/base/strings/stringprintf.cc
@@ -8,9 +8,9 @@
#include <vector>
+#include "base/logging.h"
#include "base/scoped_clear_errno.h"
#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
namespace base {
@@ -29,15 +29,6 @@
return base::vsnprintf(buffer, buf_size, format, argptr);
}
-#if defined(OS_WIN)
-inline int vsnprintfT(wchar_t* buffer,
- size_t buf_size,
- const wchar_t* format,
- va_list argptr) {
- return base::vswprintf(buffer, buf_size, format, argptr);
-}
-#endif
-
// Templatized backend for StringPrintF/StringAppendF. This does not finalize
// the va_list, the caller is expected to do that.
template <class StringType>
@@ -119,17 +110,6 @@
return result;
}
-#if defined(OS_WIN)
-std::wstring StringPrintf(const wchar_t* format, ...) {
- va_list ap;
- va_start(ap, format);
- std::wstring result;
- StringAppendV(&result, format, ap);
- va_end(ap);
- return result;
-}
-#endif
-
std::string StringPrintV(const char* format, va_list ap) {
std::string result;
StringAppendV(&result, format, ap);
@@ -145,18 +125,6 @@
return *dst;
}
-#if defined(OS_WIN)
-const std::wstring& SStringPrintf(std::wstring* dst,
- const wchar_t* format, ...) {
- va_list ap;
- va_start(ap, format);
- dst->clear();
- StringAppendV(dst, format, ap);
- va_end(ap);
- return *dst;
-}
-#endif
-
void StringAppendF(std::string* dst, const char* format, ...) {
va_list ap;
va_start(ap, format);
@@ -164,23 +132,8 @@
va_end(ap);
}
-#if defined(OS_WIN)
-void StringAppendF(std::wstring* dst, const wchar_t* format, ...) {
- va_list ap;
- va_start(ap, format);
- StringAppendV(dst, format, ap);
- va_end(ap);
-}
-#endif
-
void StringAppendV(std::string* dst, const char* format, va_list ap) {
StringAppendVT(dst, format, ap);
}
-#if defined(OS_WIN)
-void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
- StringAppendVT(dst, format, ap);
-}
-#endif
-
} // namespace base
diff --git a/libweave/external/base/strings/stringprintf.h b/libweave/external/base/strings/stringprintf.h
index 523f7ee..bb4b22d 100644
--- a/libweave/external/base/strings/stringprintf.h
+++ b/libweave/external/base/strings/stringprintf.h
@@ -17,10 +17,6 @@
// Return a C++ string given printf-like input.
BASE_EXPORT std::string StringPrintf(const char* format, ...)
PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
-#if defined(OS_WIN)
-BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...)
- WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
-#endif
// Return a C++ string given vprintf-like input.
BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
@@ -30,29 +26,15 @@
BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
const char* format, ...)
PRINTF_FORMAT(2, 3);
-#if defined(OS_WIN)
-BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
- const wchar_t* format, ...)
- WPRINTF_FORMAT(2, 3);
-#endif
// Append result to a supplied string.
BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
PRINTF_FORMAT(2, 3);
-#if defined(OS_WIN)
-BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
- WPRINTF_FORMAT(2, 3);
-#endif
// Lower-level routine that takes a va_list and appends to a specified
// string. All other routines are just convenience wrappers around it.
BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
PRINTF_FORMAT(2, 0);
-#if defined(OS_WIN)
-BASE_EXPORT void StringAppendV(std::wstring* dst,
- const wchar_t* format, va_list ap)
- WPRINTF_FORMAT(2, 0);
-#endif
} // namespace base
diff --git a/libweave/external/base/strings/stringprintf_unittest.cc b/libweave/external/base/strings/stringprintf_unittest.cc
index c49637c..88a9675 100644
--- a/libweave/external/base/strings/stringprintf_unittest.cc
+++ b/libweave/external/base/strings/stringprintf_unittest.cc
@@ -6,8 +6,9 @@
#include <errno.h>
+#include <gtest/gtest.h>
+
#include "base/basictypes.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -80,10 +81,6 @@
for (size_t i = 0; i < arraysize(src); i++)
src[i] = 'A';
- wchar_t srcw[kSrcLen];
- for (size_t i = 0; i < arraysize(srcw); i++)
- srcw[i] = 'A';
-
for (int i = 1; i < 3; i++) {
src[kSrcLen - i] = 0;
std::string out;
diff --git a/libweave/external/base/strings/utf_string_conversion_utils.cc b/libweave/external/base/strings/utf_string_conversion_utils.cc
index 022c0df..05bd122 100644
--- a/libweave/external/base/strings/utf_string_conversion_utils.cc
+++ b/libweave/external/base/strings/utf_string_conversion_utils.cc
@@ -29,43 +29,6 @@
return IsValidCodepoint(code_point);
}
-bool ReadUnicodeCharacter(const char16* src,
- int32 src_len,
- int32* char_index,
- uint32* code_point) {
- if (CBU16_IS_SURROGATE(src[*char_index])) {
- if (!CBU16_IS_SURROGATE_LEAD(src[*char_index]) ||
- *char_index + 1 >= src_len ||
- !CBU16_IS_TRAIL(src[*char_index + 1])) {
- // Invalid surrogate pair.
- return false;
- }
-
- // Valid surrogate pair.
- *code_point = CBU16_GET_SUPPLEMENTARY(src[*char_index],
- src[*char_index + 1]);
- (*char_index)++;
- } else {
- // Not a surrogate, just one 16-bit word.
- *code_point = src[*char_index];
- }
-
- return IsValidCodepoint(*code_point);
-}
-
-#if defined(WCHAR_T_IS_UTF32)
-bool ReadUnicodeCharacter(const wchar_t* src,
- int32 src_len,
- int32* char_index,
- uint32* code_point) {
- // Conversion is easy since the source is 32-bit.
- *code_point = src[*char_index];
-
- // Validate the value.
- return IsValidCodepoint(*code_point);
-}
-#endif // defined(WCHAR_T_IS_UTF32)
-
// WriteUnicodeCharacter -------------------------------------------------------
size_t WriteUnicodeCharacter(uint32 code_point, std::string* output) {
@@ -89,19 +52,6 @@
return char_offset - original_char_offset;
}
-size_t WriteUnicodeCharacter(uint32 code_point, string16* output) {
- if (CBU16_LENGTH(code_point) == 1) {
- // Thie code point is in the Basic Multilingual Plane (BMP).
- output->push_back(static_cast<char16>(code_point));
- return 1;
- }
- // Non-BMP characters use a double-character encoding.
- size_t char_offset = output->length();
- output->resize(char_offset + CBU16_MAX_LENGTH);
- CBU16_APPEND_UNSAFE(&(*output)[0], char_offset, code_point);
- return CBU16_MAX_LENGTH;
-}
-
// Generalized Unicode converter -----------------------------------------------
template<typename CHAR>
@@ -120,10 +70,6 @@
}
}
-// Instantiate versions we know callers will need.
-template void PrepareForUTF8Output(const wchar_t*, size_t, std::string*);
-template void PrepareForUTF8Output(const char16*, size_t, std::string*);
-
template<typename STRING>
void PrepareForUTF16Or32Output(const char* src,
size_t src_len,
@@ -141,8 +87,4 @@
}
}
-// Instantiate versions we know callers will need.
-template void PrepareForUTF16Or32Output(const char*, size_t, std::wstring*);
-template void PrepareForUTF16Or32Output(const char*, size_t, string16*);
-
} // namespace base
diff --git a/libweave/external/base/strings/utf_string_conversion_utils.h b/libweave/external/base/strings/utf_string_conversion_utils.h
index 22abbbc..57940dd 100644
--- a/libweave/external/base/strings/utf_string_conversion_utils.h
+++ b/libweave/external/base/strings/utf_string_conversion_utils.h
@@ -5,10 +5,12 @@
#ifndef BASE_STRINGS_UTF_STRING_CONVERSION_UTILS_H_
#define BASE_STRINGS_UTF_STRING_CONVERSION_UTILS_H_
+#include <string>
+
// This should only be used by the various UTF string conversion files.
#include "base/base_export.h"
-#include "base/strings/string16.h"
+#include "base/basictypes.h"
namespace base {
@@ -42,12 +44,6 @@
int32* char_index,
uint32* code_point_out);
-// Reads a UTF-16 character. The usage is the same as the 8-bit version above.
-BASE_EXPORT bool ReadUnicodeCharacter(const char16* src,
- int32 src_len,
- int32* char_index,
- uint32* code_point);
-
#if defined(WCHAR_T_IS_UTF32)
// Reads UTF-32 character. The usage is the same as the 8-bit version above.
BASE_EXPORT bool ReadUnicodeCharacter(const wchar_t* src,
@@ -64,10 +60,6 @@
BASE_EXPORT size_t WriteUnicodeCharacter(uint32 code_point,
std::string* output);
-// Appends the given code point as a UTF-16 character to the given 16-bit
-// string. Returns the number of 16-bit values written.
-BASE_EXPORT size_t WriteUnicodeCharacter(uint32 code_point, string16* output);
-
#if defined(WCHAR_T_IS_UTF32)
// Appends the given UTF-32 character to the given 32-bit string. Returns the
// number of 32-bit values written.
diff --git a/libweave/external/base/template_util.h b/libweave/external/base/template_util.h
index 83fa322..f8f507b 100644
--- a/libweave/external/base/template_util.h
+++ b/libweave/external/base/template_util.h
@@ -6,55 +6,15 @@
#define BASE_TEMPLATE_UTIL_H_
#include <cstddef> // For size_t.
+#include <type_traits>
-#include "build/build_config.h"
+#include "base/build/build_config.h"
namespace base {
-// template definitions from tr1
-
-template<class T, T v>
-struct integral_constant {
- static const T value = v;
- typedef T value_type;
- typedef integral_constant<T, v> type;
-};
-
-template <class T, T v> const T integral_constant<T, v>::value;
-
-typedef integral_constant<bool, true> true_type;
-typedef integral_constant<bool, false> false_type;
-
-template <class T> struct is_pointer : false_type {};
-template <class T> struct is_pointer<T*> : true_type {};
-
-// Member function pointer detection. This is built-in to C++ 11's stdlib, and
-// we can remove this when we switch to it.
-template<typename T>
-struct is_member_function_pointer : false_type {};
-
-template <typename R, typename Z, typename... A>
-struct is_member_function_pointer<R(Z::*)(A...)> : true_type {};
-template <typename R, typename Z, typename... A>
-struct is_member_function_pointer<R(Z::*)(A...) const> : true_type {};
-
-
-template <class T, class U> struct is_same : public false_type {};
-template <class T> struct is_same<T,T> : true_type {};
-
-template<class> struct is_array : public false_type {};
-template<class T, size_t n> struct is_array<T[n]> : public true_type {};
-template<class T> struct is_array<T[]> : public true_type {};
-
-template <class T> struct is_non_const_reference : false_type {};
-template <class T> struct is_non_const_reference<T&> : true_type {};
-template <class T> struct is_non_const_reference<const T&> : false_type {};
-
-template <class T> struct is_const : false_type {};
-template <class T> struct is_const<const T> : true_type {};
-
-template <class T> struct is_void : false_type {};
-template <> struct is_void<void> : true_type {};
+template <class T> struct is_non_const_reference : std::false_type {};
+template <class T> struct is_non_const_reference<T&> : std::true_type {};
+template <class T> struct is_non_const_reference<const T&> : std::false_type {};
namespace internal {
@@ -66,63 +26,8 @@
YesType dummy[2];
};
-// This class is an implementation detail for is_convertible, and you
-// don't need to know how it works to use is_convertible. For those
-// who care: we declare two different functions, one whose argument is
-// of type To and one with a variadic argument list. We give them
-// return types of different size, so we can use sizeof to trick the
-// compiler into telling us which function it would have chosen if we
-// had called it with an argument of type From. See Alexandrescu's
-// _Modern C++ Design_ for more details on this sort of trick.
-
-struct ConvertHelper {
- template <typename To>
- static YesType Test(To);
-
- template <typename To>
- static NoType Test(...);
-
- template <typename From>
- static From& Create();
-};
-
-// Used to determine if a type is a struct/union/class. Inspired by Boost's
-// is_class type_trait implementation.
-struct IsClassHelper {
- template <typename C>
- static YesType Test(void(C::*)(void));
-
- template <typename C>
- static NoType Test(...);
-};
-
} // namespace internal
-// Inherits from true_type if From is convertible to To, false_type otherwise.
-//
-// Note that if the type is convertible, this will be a true_type REGARDLESS
-// of whether or not the conversion would emit a warning.
-template <typename From, typename To>
-struct is_convertible
- : integral_constant<bool,
- sizeof(internal::ConvertHelper::Test<To>(
- internal::ConvertHelper::Create<From>())) ==
- sizeof(internal::YesType)> {
-};
-
-template <typename T>
-struct is_class
- : integral_constant<bool,
- sizeof(internal::IsClassHelper::Test<T>(0)) ==
- sizeof(internal::YesType)> {
-};
-
-template<bool B, class T = void>
-struct enable_if {};
-
-template<class T>
-struct enable_if<true, T> { typedef T type; };
-
} // namespace base
#endif // BASE_TEMPLATE_UTIL_H_
diff --git a/libweave/external/base/template_util_unittest.cc b/libweave/external/base/template_util_unittest.cc
index 3ec3887..7c86355 100644
--- a/libweave/external/base/template_util_unittest.cc
+++ b/libweave/external/base/template_util_unittest.cc
@@ -4,8 +4,9 @@
#include "base/template_util.h"
+#include <gtest/gtest.h>
+
#include "base/basictypes.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
@@ -17,6 +18,13 @@
class Parent {};
class Child : public Parent {};
+using std::is_pointer;
+using std::is_array;
+using std::is_convertible;
+using std::is_same;
+using std::is_class;
+using std::is_member_function_pointer;
+
// is_pointer<Type>
COMPILE_ASSERT(!is_pointer<int>::value, IsPointer);
COMPILE_ASSERT(!is_pointer<int&>::value, IsPointer);
diff --git a/libweave/external/base/time/time.cc b/libweave/external/base/time/time.cc
index 8cbb382..7006407 100644
--- a/libweave/external/base/time/time.cc
+++ b/libweave/external/base/time/time.cc
@@ -10,10 +10,8 @@
#include <ostream>
#include <sstream>
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
-#include "base/third_party/nspr/prtime.h"
namespace base {
@@ -246,27 +244,6 @@
return FromLocalExploded(exploded);
}
-// static
-bool Time::FromStringInternal(const char* time_string,
- bool is_local,
- Time* parsed_time) {
- DCHECK((time_string != NULL) && (parsed_time != NULL));
-
- if (time_string[0] == '\0')
- return false;
-
- PRTime result_time = 0;
- PRStatus result = PR_ParseTimeString(time_string,
- is_local ? PR_FALSE : PR_TRUE,
- &result_time);
- if (PR_SUCCESS != result)
- return false;
-
- result_time += kTimeTToMicrosecondsOffset;
- *parsed_time = Time(result_time);
- return true;
-}
-
std::ostream& operator<<(std::ostream& os, Time time) {
Time::Exploded exploded;
time.UTCExplode(&exploded);
@@ -296,14 +273,6 @@
DISALLOW_COPY_AND_ASSIGN(UnixEpochSingleton);
};
-static LazyInstance<UnixEpochSingleton>::Leaky
- leaky_unix_epoch_singleton_instance = LAZY_INSTANCE_INITIALIZER;
-
-// Static
-TimeTicks TimeTicks::UnixEpoch() {
- return leaky_unix_epoch_singleton_instance.Get().unix_epoch();
-}
-
TimeTicks TimeTicks::SnappedToNextTick(TimeTicks tick_phase,
TimeDelta tick_interval) const {
// |interval_offset| is the offset from |this| to the next multiple of
diff --git a/libweave/external/base/time/time.h b/libweave/external/base/time/time.h
index a02fbeb..8764d6f 100644
--- a/libweave/external/base/time/time.h
+++ b/libweave/external/base/time/time.h
@@ -61,8 +61,8 @@
#include "base/base_export.h"
#include "base/basictypes.h"
+#include "base/build/build_config.h"
#include "base/numerics/safe_math.h"
-#include "build/build_config.h"
#if defined(OS_MACOSX)
#include <CoreFoundation/CoreFoundation.h>
@@ -539,21 +539,6 @@
return FromExploded(true, exploded);
}
- // Converts a string representation of time to a Time object.
- // An example of a time string which is converted is as below:-
- // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
- // in the input string, FromString assumes local time and FromUTCString
- // assumes UTC. A timezone that cannot be parsed (e.g. "UTC" which is not
- // specified in RFC822) is treated as if the timezone is not specified.
- // TODO(iyengar) Move the FromString/FromTimeT/ToTimeT/FromFileTime to
- // a new time converter class.
- static bool FromString(const char* time_string, Time* parsed_time) {
- return FromStringInternal(time_string, true, parsed_time);
- }
- static bool FromUTCString(const char* time_string, Time* parsed_time) {
- return FromStringInternal(time_string, false, parsed_time);
- }
-
// Fills the given exploded structure with either the local time or UTC from
// this time structure (containing UTC).
void UTCExplode(Exploded* exploded) const {
@@ -580,17 +565,6 @@
// Unexplodes a given time assuming the source is either local time
// |is_local = true| or UTC |is_local = false|.
static Time FromExploded(bool is_local, const Exploded& exploded);
-
- // Converts a string representation of time to a Time object.
- // An example of a time string which is converted is as below:-
- // "Tue, 15 Nov 1994 12:45:26 GMT". If the timezone is not specified
- // in the input string, local time |is_local = true| or
- // UTC |is_local = false| is assumed. A timezone that cannot be parsed
- // (e.g. "UTC" which is not specified in RFC822) is treated as if the
- // timezone is not specified.
- static bool FromStringInternal(const char* time_string,
- bool is_local,
- Time* parsed_time);
};
// Inline the TimeDelta factory methods, for fast TimeDelta construction.
diff --git a/libweave/external/base/time/time_posix.cc b/libweave/external/base/time/time_posix.cc
index fc82c62..b625af6 100644
--- a/libweave/external/base/time/time_posix.cc
+++ b/libweave/external/base/time/time_posix.cc
@@ -16,28 +16,12 @@
#include <ostream>
#include "base/basictypes.h"
+#include "base/build/build_config.h"
#include "base/logging.h"
-#include "build/build_config.h"
-
-#if defined(OS_ANDROID)
-#include "base/os_compat_android.h"
-#elif defined(OS_NACL)
-#include "base/os_compat_nacl.h"
-#endif
-
-#if !defined(OS_MACOSX)
-#include "base/lazy_instance.h"
-#include "base/synchronization/lock.h"
-#endif
namespace {
#if !defined(OS_MACOSX)
-// This prevents a crash on traversing the environment global and looking up
-// the 'TZ' variable in libc. See: crbug.com/390567.
-base::LazyInstance<base::Lock>::Leaky
- g_sys_time_to_time_struct_lock = LAZY_INSTANCE_INITIALIZER;
-
// Define a system-specific SysTime that wraps either to a time_t or
// a time64_t depending on the host system, and associated convertion.
// See crbug.com/162007
@@ -45,7 +29,6 @@
typedef time64_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
- base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
return mktime64(timestruct);
else
@@ -53,7 +36,6 @@
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
- base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
localtime64_r(&t, timestruct);
else
@@ -64,7 +46,6 @@
typedef time_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
- base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
return mktime(timestruct);
else
@@ -72,7 +53,6 @@
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
- base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
localtime_r(&t, timestruct);
else
@@ -154,7 +134,7 @@
struct timezone tz = { 0, 0 }; // UTC
if (gettimeofday(&tv, &tz) != 0) {
DCHECK(0) << "Could not determine time of day";
- PLOG(ERROR) << "Call to gettimeofday failed.";
+ LOG(ERROR) << "Call to gettimeofday failed.";
// Return null instead of uninitialized |tv| value, which contains random
// garbage data. This may result in the crash seen in crbug.com/147570.
return Time();
diff --git a/libweave/external/base/time/time_unittest.cc b/libweave/external/base/time/time_unittest.cc
index b7e05b7..43373e7 100644
--- a/libweave/external/base/time/time_unittest.cc
+++ b/libweave/external/base/time/time_unittest.cc
@@ -9,12 +9,12 @@
#include <limits>
#include <string>
+#include <gtest/gtest.h>
+
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
-#include "base/threading/platform_thread.h"
-#include "build/build_config.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "base/build/build_config.h"
namespace base {
@@ -162,201 +162,6 @@
EXPECT_EQ(0, exploded.millisecond);
}
-TEST_F(TimeTest, ParseTimeTest1) {
- time_t current_time = 0;
- time(¤t_time);
-
- const int BUFFER_SIZE = 64;
- struct tm local_time = {0};
- char time_buf[BUFFER_SIZE] = {0};
-#if defined(OS_WIN)
- localtime_s(&local_time, ¤t_time);
- asctime_s(time_buf, arraysize(time_buf), &local_time);
-#elif defined(OS_POSIX)
- localtime_r(¤t_time, &local_time);
- asctime_r(&local_time, time_buf);
-#endif
-
- Time parsed_time;
- EXPECT_TRUE(Time::FromString(time_buf, &parsed_time));
- EXPECT_EQ(current_time, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, DayOfWeekSunday) {
- Time time;
- EXPECT_TRUE(Time::FromString("Sun, 06 May 2012 12:00:00 GMT", &time));
- Time::Exploded exploded;
- time.UTCExplode(&exploded);
- EXPECT_EQ(0, exploded.day_of_week);
-}
-
-TEST_F(TimeTest, DayOfWeekWednesday) {
- Time time;
- EXPECT_TRUE(Time::FromString("Wed, 09 May 2012 12:00:00 GMT", &time));
- Time::Exploded exploded;
- time.UTCExplode(&exploded);
- EXPECT_EQ(3, exploded.day_of_week);
-}
-
-TEST_F(TimeTest, DayOfWeekSaturday) {
- Time time;
- EXPECT_TRUE(Time::FromString("Sat, 12 May 2012 12:00:00 GMT", &time));
- Time::Exploded exploded;
- time.UTCExplode(&exploded);
- EXPECT_EQ(6, exploded.day_of_week);
-}
-
-TEST_F(TimeTest, ParseTimeTest2) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("Mon, 15 Oct 2007 19:45:00 GMT", &parsed_time));
- EXPECT_EQ(comparison_time_pdt_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest3) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("15 Oct 07 12:45:00", &parsed_time));
- EXPECT_EQ(comparison_time_local_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest4) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("15 Oct 07 19:45 GMT", &parsed_time));
- EXPECT_EQ(comparison_time_pdt_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest5) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("Mon Oct 15 12:45 PDT 2007", &parsed_time));
- EXPECT_EQ(comparison_time_pdt_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest6) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("Monday, Oct 15, 2007 12:45 PM", &parsed_time));
- EXPECT_EQ(comparison_time_local_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest7) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("10/15/07 12:45:00 PM", &parsed_time));
- EXPECT_EQ(comparison_time_local_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest8) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("15-OCT-2007 12:45pm", &parsed_time));
- EXPECT_EQ(comparison_time_local_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest9) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("16 Oct 2007 4:45-JST (Tuesday)", &parsed_time));
- EXPECT_EQ(comparison_time_pdt_, parsed_time);
-}
-
-TEST_F(TimeTest, ParseTimeTest10) {
- Time parsed_time;
- EXPECT_TRUE(Time::FromString("15/10/07 12:45", &parsed_time));
- EXPECT_EQ(parsed_time, comparison_time_local_);
-}
-
-// Test some of edge cases around epoch, etc.
-TEST_F(TimeTest, ParseTimeTestEpoch0) {
- Time parsed_time;
-
- // time_t == epoch == 0
- EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:00 +0100 1970",
- &parsed_time));
- EXPECT_EQ(0, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:00 GMT 1970",
- &parsed_time));
- EXPECT_EQ(0, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEpoch1) {
- Time parsed_time;
-
- // time_t == 1 second after epoch == 1
- EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:01 +0100 1970",
- &parsed_time));
- EXPECT_EQ(1, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:01 GMT 1970",
- &parsed_time));
- EXPECT_EQ(1, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEpoch2) {
- Time parsed_time;
-
- // time_t == 2 seconds after epoch == 2
- EXPECT_TRUE(Time::FromString("Thu Jan 01 01:00:02 +0100 1970",
- &parsed_time));
- EXPECT_EQ(2, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Thu Jan 01 00:00:02 GMT 1970",
- &parsed_time));
- EXPECT_EQ(2, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEpochNeg1) {
- Time parsed_time;
-
- // time_t == 1 second before epoch == -1
- EXPECT_TRUE(Time::FromString("Thu Jan 01 00:59:59 +0100 1970",
- &parsed_time));
- EXPECT_EQ(-1, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:59 GMT 1969",
- &parsed_time));
- EXPECT_EQ(-1, parsed_time.ToTimeT());
-}
-
-// If time_t is 32 bits, a date after year 2038 will overflow time_t and
-// cause timegm() to return -1. The parsed time should not be 1 second
-// before epoch.
-TEST_F(TimeTest, ParseTimeTestEpochNotNeg1) {
- Time parsed_time;
-
- EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:59 GMT 2100",
- &parsed_time));
- EXPECT_NE(-1, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEpochNeg2) {
- Time parsed_time;
-
- // time_t == 2 seconds before epoch == -2
- EXPECT_TRUE(Time::FromString("Thu Jan 01 00:59:58 +0100 1970",
- &parsed_time));
- EXPECT_EQ(-2, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Wed Dec 31 23:59:58 GMT 1969",
- &parsed_time));
- EXPECT_EQ(-2, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEpoch1960) {
- Time parsed_time;
-
- // time_t before Epoch, in 1960
- EXPECT_TRUE(Time::FromString("Wed Jun 29 19:40:01 +0100 1960",
- &parsed_time));
- EXPECT_EQ(-299999999, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Wed Jun 29 18:40:01 GMT 1960",
- &parsed_time));
- EXPECT_EQ(-299999999, parsed_time.ToTimeT());
- EXPECT_TRUE(Time::FromString("Wed Jun 29 17:40:01 GMT 1960",
- &parsed_time));
- EXPECT_EQ(-300003599, parsed_time.ToTimeT());
-}
-
-TEST_F(TimeTest, ParseTimeTestEmpty) {
- Time parsed_time;
- EXPECT_FALSE(Time::FromString("", &parsed_time));
-}
-
-TEST_F(TimeTest, ParseTimeTestInvalidString) {
- Time parsed_time;
- EXPECT_FALSE(Time::FromString("Monday morning 2000", &parsed_time));
-}
-
TEST_F(TimeTest, ExplodeBeforeUnixEpoch) {
static const int kUnixEpochYear = 1970; // In case this changes (ha!).
Time t;
@@ -615,33 +420,6 @@
}
#endif // OS_ANDROID
-TEST(TimeTicks, Deltas) {
- for (int index = 0; index < 50; index++) {
- TimeTicks ticks_start = TimeTicks::Now();
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
- TimeTicks ticks_stop = TimeTicks::Now();
- TimeDelta delta = ticks_stop - ticks_start;
- // Note: Although we asked for a 10ms sleep, if the
- // time clock has a finer granularity than the Sleep()
- // clock, it is quite possible to wakeup early. Here
- // is how that works:
- // Time(ms timer) Time(us timer)
- // 5 5010
- // 6 6010
- // 7 7010
- // 8 8010
- // 9 9000
- // Elapsed 4ms 3990us
- //
- // Unfortunately, our InMilliseconds() function truncates
- // rather than rounds. We should consider fixing this
- // so that our averages come out better.
- EXPECT_GE(delta.InMilliseconds(), 9);
- EXPECT_GE(delta.InMicroseconds(), 9000);
- EXPECT_EQ(delta.InSeconds(), 0);
- }
-}
-
static void HighResClockTest(TimeTicks (*GetTicks)()) {
// IsHighResolution() is false on some systems. Since the product still works
// even if it's false, it makes this entire test questionable.
@@ -683,33 +461,6 @@
HighResClockTest(&TimeTicks::Now);
}
-// Fails frequently on Android http://crbug.com/352633 with:
-// Expected: (delta_thread.InMicroseconds()) > (0), actual: 0 vs 0
-#if defined(OS_ANDROID)
-#define MAYBE_ThreadNow DISABLED_ThreadNow
-#else
-#define MAYBE_ThreadNow ThreadNow
-#endif
-TEST(ThreadTicks, MAYBE_ThreadNow) {
- if (ThreadTicks::IsSupported()) {
- TimeTicks begin = TimeTicks::Now();
- ThreadTicks begin_thread = ThreadTicks::Now();
- // Make sure that ThreadNow value is non-zero.
- EXPECT_GT(begin_thread, ThreadTicks());
- // Sleep for 10 milliseconds to get the thread de-scheduled.
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
- ThreadTicks end_thread = ThreadTicks::Now();
- TimeTicks end = TimeTicks::Now();
- TimeDelta delta = end - begin;
- TimeDelta delta_thread = end_thread - begin_thread;
- // Make sure that some thread time have elapsed.
- EXPECT_GT(delta_thread.InMicroseconds(), 0);
- // But the thread time is at least 9ms less than clock time.
- TimeDelta difference = delta - delta_thread;
- EXPECT_GE(difference.InMicroseconds(), 9000);
- }
-}
-
TEST(TraceTicks, NowFromSystemTraceTime) {
// Re-use HighRes test for now since clock properties are identical.
using NowFunction = TimeTicks (*)(void);
@@ -1050,12 +801,6 @@
DCHECK_EQ(Time(), Time());
}
-TEST(TimeLogging, ChromeBirthdate) {
- Time birthdate;
- ASSERT_TRUE(Time::FromString("Tue, 02 Sep 2008 09:42:18 GMT", &birthdate));
- EXPECT_EQ("2008-09-02 09:42:18.000 UTC", AnyToString(birthdate));
-}
-
TEST(TimeLogging, DoesNotMessUpFormattingFlags) {
std::ostringstream oss;
std::ios_base::fmtflags flags_before = oss.flags();
diff --git a/libweave/external/base/tuple_unittest.cc b/libweave/external/base/tuple_unittest.cc
index 55a9139..668c115 100644
--- a/libweave/external/base/tuple_unittest.cc
+++ b/libweave/external/base/tuple_unittest.cc
@@ -4,8 +4,9 @@
#include "base/tuple.h"
+#include <gtest/gtest.h>
+
#include "base/compiler_specific.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
diff --git a/libweave/external/base/values.cc b/libweave/external/base/values.cc
index 4534d27..689fdd7 100644
--- a/libweave/external/base/values.cc
+++ b/libweave/external/base/values.cc
@@ -14,7 +14,7 @@
#include "base/logging.h"
#include "base/move.h"
#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
+#include "base/strings/utf_string_conversion_utils.h"
namespace base {
@@ -112,10 +112,6 @@
return false;
}
-bool Value::GetAsString(string16* out_value) const {
- return false;
-}
-
bool Value::GetAsString(const StringValue** out_value) const {
return false;
}
@@ -260,11 +256,6 @@
DCHECK(IsStringUTF8(in_value));
}
-StringValue::StringValue(const string16& in_value)
- : Value(TYPE_STRING),
- value_(UTF16ToUTF8(in_value)) {
-}
-
StringValue::~StringValue() {
}
@@ -282,12 +273,6 @@
return true;
}
-bool StringValue::GetAsString(string16* out_value) const {
- if (out_value)
- *out_value = UTF8ToUTF16(value_);
- return true;
-}
-
bool StringValue::GetAsString(const StringValue** out_value) const {
if (out_value)
*out_value = this;
@@ -433,11 +418,6 @@
Set(path, new StringValue(in_value));
}
-void DictionaryValue::SetString(const std::string& path,
- const string16& in_value) {
- Set(path, new StringValue(in_value));
-}
-
void DictionaryValue::SetWithoutPathExpansion(const std::string& key,
scoped_ptr<Value> in_value) {
Value* bare_ptr = in_value.release();
@@ -477,11 +457,6 @@
SetWithoutPathExpansion(path, new StringValue(in_value));
}
-void DictionaryValue::SetStringWithoutPathExpansion(
- const std::string& path, const string16& in_value) {
- SetWithoutPathExpansion(path, new StringValue(in_value));
-}
-
bool DictionaryValue::Get(const std::string& path,
const Value** out_value) const {
DCHECK(IsStringUTF8(path));
@@ -544,15 +519,6 @@
return value->GetAsString(out_value);
}
-bool DictionaryValue::GetString(const std::string& path,
- string16* out_value) const {
- const Value* value;
- if (!Get(path, &value))
- return false;
-
- return value->GetAsString(out_value);
-}
-
bool DictionaryValue::GetStringASCII(const std::string& path,
std::string* out_value) const {
std::string out;
@@ -684,15 +650,6 @@
return value->GetAsString(out_value);
}
-bool DictionaryValue::GetStringWithoutPathExpansion(const std::string& key,
- string16* out_value) const {
- const Value* value;
- if (!GetWithoutPathExpansion(key, &value))
- return false;
-
- return value->GetAsString(out_value);
-}
-
bool DictionaryValue::GetDictionaryWithoutPathExpansion(
const std::string& key,
const DictionaryValue** out_value) const {
@@ -949,14 +906,6 @@
return value->GetAsString(out_value);
}
-bool ListValue::GetString(size_t index, string16* out_value) const {
- const Value* value;
- if (!Get(index, &value))
- return false;
-
- return value->GetAsString(out_value);
-}
-
bool ListValue::GetBinary(size_t index, const BinaryValue** out_value) const {
const Value* value;
bool result = Get(index, &value);
@@ -1075,10 +1024,6 @@
Append(new StringValue(in_value));
}
-void ListValue::AppendString(const string16& in_value) {
- Append(new StringValue(in_value));
-}
-
void ListValue::AppendStrings(const std::vector<std::string>& in_values) {
for (std::vector<std::string>::const_iterator it = in_values.begin();
it != in_values.end(); ++it) {
@@ -1086,13 +1031,6 @@
}
}
-void ListValue::AppendStrings(const std::vector<string16>& in_values) {
- for (std::vector<string16>::const_iterator it = in_values.begin();
- it != in_values.end(); ++it) {
- AppendString(*it);
- }
-}
-
bool ListValue::AppendIfNotPresent(Value* in_value) {
DCHECK(in_value);
for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) {
@@ -1166,12 +1104,6 @@
return true;
}
-ValueSerializer::~ValueSerializer() {
-}
-
-ValueDeserializer::~ValueDeserializer() {
-}
-
std::ostream& operator<<(std::ostream& out, const Value& value) {
std::string json;
JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json);
diff --git a/libweave/external/base/values.h b/libweave/external/base/values.h
index 7feef9d..b95af6d 100644
--- a/libweave/external/base/values.h
+++ b/libweave/external/base/values.h
@@ -29,7 +29,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "base/strings/string16.h"
namespace base {
@@ -84,7 +83,6 @@
virtual bool GetAsInteger(int* out_value) const;
virtual bool GetAsDouble(double* out_value) const;
virtual bool GetAsString(std::string* out_value) const;
- virtual bool GetAsString(string16* out_value) const;
virtual bool GetAsString(const StringValue** out_value) const;
virtual bool GetAsBinary(const BinaryValue** out_value) const;
virtual bool GetAsList(ListValue** out_value);
@@ -149,9 +147,6 @@
// Initializes a StringValue with a UTF-8 narrow character string.
explicit StringValue(const std::string& in_value);
- // Initializes a StringValue with a string16.
- explicit StringValue(const string16& in_value);
-
~StringValue() override;
// Returns |value_| as a pointer or reference.
@@ -160,7 +155,6 @@
// Overridden from Value:
bool GetAsString(std::string* out_value) const override;
- bool GetAsString(string16* out_value) const override;
bool GetAsString(const StringValue** out_value) const override;
StringValue* DeepCopy() const override;
bool Equals(const Value* other) const override;
@@ -244,7 +238,6 @@
void SetInteger(const std::string& path, int in_value);
void SetDouble(const std::string& path, double in_value);
void SetString(const std::string& path, const std::string& in_value);
- void SetString(const std::string& path, const string16& in_value);
// Like Set(), but without special treatment of '.'. This allows e.g. URLs to
// be used as paths.
@@ -259,8 +252,6 @@
void SetDoubleWithoutPathExpansion(const std::string& path, double in_value);
void SetStringWithoutPathExpansion(const std::string& path,
const std::string& in_value);
- void SetStringWithoutPathExpansion(const std::string& path,
- const string16& in_value);
// Gets the Value associated with the given path starting from this object.
// A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes
@@ -283,7 +274,6 @@
// doubles.
bool GetDouble(const std::string& path, double* out_value) const;
bool GetString(const std::string& path, std::string* out_value) const;
- bool GetString(const std::string& path, string16* out_value) const;
bool GetStringASCII(const std::string& path, std::string* out_value) const;
bool GetBinary(const std::string& path, const BinaryValue** out_value) const;
bool GetBinary(const std::string& path, BinaryValue** out_value);
@@ -306,8 +296,6 @@
double* out_value) const;
bool GetStringWithoutPathExpansion(const std::string& key,
std::string* out_value) const;
- bool GetStringWithoutPathExpansion(const std::string& key,
- string16* out_value) const;
bool GetDictionaryWithoutPathExpansion(
const std::string& key,
const DictionaryValue** out_value) const;
@@ -424,7 +412,6 @@
// doubles.
bool GetDouble(size_t index, double* out_value) const;
bool GetString(size_t index, std::string* out_value) const;
- bool GetString(size_t index, string16* out_value) const;
bool GetBinary(size_t index, const BinaryValue** out_value) const;
bool GetBinary(size_t index, BinaryValue** out_value);
bool GetDictionary(size_t index, const DictionaryValue** out_value) const;
@@ -460,9 +447,7 @@
void AppendInteger(int in_value);
void AppendDouble(double in_value);
void AppendString(const std::string& in_value);
- void AppendString(const string16& in_value);
void AppendStrings(const std::vector<std::string>& in_values);
- void AppendStrings(const std::vector<string16>& in_values);
// Appends a Value if it's not already present. Takes ownership of the
// |in_value|. Returns true if successful, or false if the value was already
@@ -503,30 +488,6 @@
DISALLOW_COPY_AND_ASSIGN(ListValue);
};
-// This interface is implemented by classes that know how to serialize
-// Value objects.
-class BASE_EXPORT ValueSerializer {
- public:
- virtual ~ValueSerializer();
-
- virtual bool Serialize(const Value& root) = 0;
-};
-
-// This interface is implemented by classes that know how to deserialize Value
-// objects.
-class BASE_EXPORT ValueDeserializer {
- public:
- virtual ~ValueDeserializer();
-
- // This method deserializes the subclass-specific format into a Value object.
- // If the return value is non-NULL, the caller takes ownership of returned
- // Value. If the return value is NULL, and if error_code is non-NULL,
- // error_code will be set with the underlying error.
- // If |error_message| is non-null, it will be filled in with a formatted
- // error message including the location of the error if appropriate.
- virtual Value* Deserialize(int* error_code, std::string* error_str) = 0;
-};
-
// Stream operator so Values can be used in assertion statements. In order that
// gtest uses this operator to print readable output on test failures, we must
// override each specific type. Otherwise, the default template implementation
diff --git a/libweave/external/base/values_unittest.cc b/libweave/external/base/values_unittest.cc
index 37ed7ce..d246691 100644
--- a/libweave/external/base/values_unittest.cc
+++ b/libweave/external/base/values_unittest.cc
@@ -4,11 +4,11 @@
#include <limits>
+#include <gtest/gtest.h>
+
#include "base/memory/scoped_ptr.h"
-#include "base/strings/string16.h"
-#include "base/strings/utf_string_conversions.h"
+#include "base/strings/utf_string_conversion_utils.h"
#include "base/values.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -141,30 +141,16 @@
scoped_ptr<Value> narrow_value(new StringValue("narrow"));
ASSERT_TRUE(narrow_value.get());
ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
- scoped_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16")));
- ASSERT_TRUE(utf16_value.get());
- ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
// Test overloaded GetAsString.
std::string narrow = "http://google.com";
- string16 utf16 = ASCIIToUTF16("http://google.com");
const StringValue* string_value = NULL;
ASSERT_TRUE(narrow_value->GetAsString(&narrow));
- ASSERT_TRUE(narrow_value->GetAsString(&utf16));
ASSERT_TRUE(narrow_value->GetAsString(&string_value));
ASSERT_EQ(std::string("narrow"), narrow);
- ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
- ASSERT_EQ(string_value->GetString(), narrow);
-
- ASSERT_TRUE(utf16_value->GetAsString(&narrow));
- ASSERT_TRUE(utf16_value->GetAsString(&utf16));
- ASSERT_TRUE(utf16_value->GetAsString(&string_value));
- ASSERT_EQ(std::string("utf16"), narrow);
- ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
ASSERT_EQ(string_value->GetString(), narrow);
// Don't choke on NULL values.
- ASSERT_TRUE(narrow_value->GetAsString(static_cast<string16*>(NULL)));
ASSERT_TRUE(narrow_value->GetAsString(static_cast<std::string*>(NULL)));
ASSERT_TRUE(narrow_value->GetAsString(
static_cast<const StringValue**>(NULL)));
@@ -406,10 +392,6 @@
scoped_ptr<StringValue> scoped_string(new StringValue("hello"));
StringValue* original_string = scoped_string.get();
original_dict.Set("string", scoped_string.Pass());
- scoped_ptr<StringValue> scoped_string16(
- new StringValue(ASCIIToUTF16("hello16")));
- StringValue* original_string16 = scoped_string16.get();
- original_dict.Set("string16", scoped_string16.Pass());
scoped_ptr<char[]> original_buffer(new char[42]);
memset(original_buffer.get(), '!', 42);
@@ -476,21 +458,6 @@
ASSERT_NE(copy_string, original_string);
ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING));
std::string copy_string_value;
- string16 copy_string16_value;
- ASSERT_TRUE(copy_string->GetAsString(©_string_value));
- ASSERT_TRUE(copy_string->GetAsString(©_string16_value));
- ASSERT_EQ(std::string("hello"), copy_string_value);
- ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value);
-
- Value* copy_string16 = NULL;
- ASSERT_TRUE(copy_dict->Get("string16", ©_string16));
- ASSERT_TRUE(copy_string16);
- ASSERT_NE(copy_string16, original_string16);
- ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING));
- ASSERT_TRUE(copy_string16->GetAsString(©_string_value));
- ASSERT_TRUE(copy_string16->GetAsString(©_string16_value));
- ASSERT_EQ(std::string("hello16"), copy_string_value);
- ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value);
Value* copy_binary = NULL;
ASSERT_TRUE(copy_dict->Get("binary", ©_binary));
@@ -556,7 +523,6 @@
dv.SetInteger("b", 2);
dv.SetDouble("c", 2.5);
dv.SetString("d1", "string");
- dv.SetString("d2", ASCIIToUTF16("http://google.com"));
dv.Set("e", Value::CreateNullValue());
scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy();
@@ -624,10 +590,6 @@
scoped_ptr<StringValue> scoped_string(new StringValue("hello"));
Value* original_string = scoped_string.get();
original_dict.Set("string", scoped_string.Pass());
- scoped_ptr<StringValue> scoped_string16(
- new StringValue(ASCIIToUTF16("hello16")));
- Value* original_string16 = scoped_string16.get();
- original_dict.Set("string16", scoped_string16.Pass());
scoped_ptr<char[]> original_buffer(new char[42]);
memset(original_buffer.get(), '!', 42);
@@ -650,7 +612,6 @@
scoped_ptr<Value> copy_int = original_int->CreateDeepCopy();
scoped_ptr<Value> copy_double = original_double->CreateDeepCopy();
scoped_ptr<Value> copy_string = original_string->CreateDeepCopy();
- scoped_ptr<Value> copy_string16 = original_string16->CreateDeepCopy();
scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy();
scoped_ptr<Value> copy_list = original_list->CreateDeepCopy();
@@ -660,7 +621,6 @@
EXPECT_TRUE(original_int->Equals(copy_int.get()));
EXPECT_TRUE(original_double->Equals(copy_double.get()));
EXPECT_TRUE(original_string->Equals(copy_string.get()));
- EXPECT_TRUE(original_string16->Equals(copy_string16.get()));
EXPECT_TRUE(original_binary->Equals(copy_binary.get()));
EXPECT_TRUE(original_list->Equals(copy_list.get()));
}
@@ -933,15 +893,6 @@
EXPECT_FALSE(main_dict.GetString("list", static_cast<std::string*>(NULL)));
EXPECT_FALSE(main_dict.GetString("DNE", static_cast<std::string*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("bool", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("int", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("double", static_cast<string16*>(NULL)));
- EXPECT_TRUE(main_dict.GetString("string", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("binary", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("dict", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("list", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetString("DNE", static_cast<string16*>(NULL)));
-
EXPECT_FALSE(main_dict.GetBinary("bool", NULL));
EXPECT_FALSE(main_dict.GetBinary("int", NULL));
EXPECT_FALSE(main_dict.GetBinary("double", NULL));
@@ -1022,23 +973,6 @@
EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
"DNE", static_cast<std::string*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "bool", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "int", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "double", static_cast<string16*>(NULL)));
- EXPECT_TRUE(main_dict.GetStringWithoutPathExpansion(
- "string", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "binary", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "dict", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "list", static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_dict.GetStringWithoutPathExpansion(
- "DNE", static_cast<string16*>(NULL)));
-
// There is no GetBinaryWithoutPathExpansion for some reason, but if there
// were it should be tested here...
@@ -1105,15 +1039,6 @@
EXPECT_FALSE(main_list.GetString(6, static_cast<std::string*>(NULL)));
EXPECT_FALSE(main_list.GetString(7, static_cast<std::string*>(NULL)));
- EXPECT_FALSE(main_list.GetString(0, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(1, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(2, static_cast<string16*>(NULL)));
- EXPECT_TRUE(main_list.GetString(3, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(4, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(5, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(6, static_cast<string16*>(NULL)));
- EXPECT_FALSE(main_list.GetString(7, static_cast<string16*>(NULL)));
-
EXPECT_FALSE(main_list.GetBinary(0, NULL));
EXPECT_FALSE(main_list.GetBinary(1, NULL));
EXPECT_FALSE(main_list.GetBinary(2, NULL));