1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_STRINGS_NULLABLE_STRING16_H_
6 #define BASE_STRINGS_NULLABLE_STRING16_H_
7 
8 #include <iosfwd>
9 
10 #include "base/base_export.h"
11 #include "base/strings/string16.h"
12 
13 namespace base {
14 
15 // This class is a simple wrapper for string16 which also contains a null
16 // state.  This should be used only where the difference between null and
17 // empty is meaningful.
18 class NullableString16 {
19  public:
NullableString16()20   NullableString16() : is_null_(true) { }
NullableString16(const string16 & string,bool is_null)21   NullableString16(const string16& string, bool is_null)
22       : string_(string), is_null_(is_null) {
23   }
24 
string()25   const string16& string() const { return string_; }
is_null()26   bool is_null() const { return is_null_; }
27 
28  private:
29   string16 string_;
30   bool is_null_;
31 };
32 
33 inline bool operator==(const NullableString16& a, const NullableString16& b) {
34   return a.is_null() == b.is_null() && a.string() == b.string();
35 }
36 
37 inline bool operator!=(const NullableString16& a, const NullableString16& b) {
38   return !(a == b);
39 }
40 
41 BASE_EXPORT std::ostream& operator<<(std::ostream& out,
42                                      const NullableString16& value);
43 
44 }  // namespace base
45 
46 #endif  // BASE_STRINGS_NULLABLE_STRING16_H_
47