17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright (c) 2010 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef BASE_STRINGS_NULLABLE_STRING16_H_ 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define BASE_STRINGS_NULLABLE_STRING16_H_ 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <iosfwd> 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/base_export.h" 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace base { 147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// This class is a simple wrapper for string16 which also contains a null 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// state. This should be used only where the difference between null and 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// empty is meaningful. 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class NullableString16 { 197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NullableString16() : is_null_(true) { } 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) NullableString16(const string16& string, bool is_null) 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) : string_(string), is_null_(is_null) { 237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const string16& string() const { return string_; } 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool is_null() const { return is_null_; } 277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private: 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) string16 string_; 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool is_null_; 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)inline bool operator==(const NullableString16& a, const NullableString16& b) { 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return a.is_null() == b.is_null() && a.string() == b.string(); 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)inline bool operator!=(const NullableString16& a, const NullableString16& b) { 387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return !(a == b); 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)BASE_EXPORT std::ostream& operator<<(std::ostream& out, 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const NullableString16& value); 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace 457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif // BASE_STRINGS_NULLABLE_STRING16_H_ 47