159d709d503bab6e2b61931737e662dd293b40578ccornelius// Copyright (C) 2009-2013, International Business Machines
2b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// Corporation and others. All Rights Reserved.
3b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//
4b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// Copyright 2001 and onwards Google Inc.
5b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// Author: Sanjay Ghemawat
6b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
7b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// This code is a contribution of Google code, and the style used here is
8b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// a compromise between the original Google code and the ICU coding guidelines.
9b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// For example, data types are ICU-ified (size_t,int->int32_t),
10b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// and API comments doxygen-ified, but function names and behavior are
11b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// as in the original, if possible.
12b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// Assertion-style error handling, not available in ICU, was changed to
13b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// parameter "pinning" similar to UnicodeString.
14b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru//
15b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// In addition, this is only a partial port of the original Google code,
16b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// limited to what was needed so far. The (nearly) complete original code
17b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// is in the ICU svn repository at icuhtml/trunk/design/strings/contrib
18b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// (see ICU ticket 6765, r25517).
19b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
20b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#ifndef __STRINGPIECE_H__
21b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#define __STRINGPIECE_H__
22b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
23b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/**
24b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * \file
25b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * \brief C++ API: StringPiece: Read-only byte string wrapper class.
26b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */
27b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
28b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#include "unicode/utypes.h"
29b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#include "unicode/uobject.h"
30b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#include "unicode/std_string.h"
31b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
32b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru// Arghh!  I wish C++ literals were "string".
33b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
34b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruU_NAMESPACE_BEGIN
35b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
36b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/**
37b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * A string-like object that points to a sized piece of memory.
38b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *
39b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * We provide non-explicit singleton constructors so users can pass
40b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * in a "const char*" or a "string" wherever a "StringPiece" is
41b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * expected.
42b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *
43b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Functions or methods may use const StringPiece& parameters to accept either
44b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * a "const char*" or a "string" value that will be implicitly converted to
45b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * a StringPiece.
46b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *
47b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Systematic usage of StringPiece is encouraged as it will reduce unnecessary
48b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * conversions from "const char*" to "string" and back again.
49b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *
5050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @stable ICU 4.2
51b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */
52b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queruclass U_COMMON_API StringPiece : public UMemory {
53b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru private:
54b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  const char*   ptr_;
55b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  int32_t       length_;
56b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
57b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru public:
58b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
59b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Default constructor, creates an empty StringPiece.
6050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
61b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
62b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece() : ptr_(NULL), length_(0) { }
63b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
64b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Constructs from a NUL-terminated const char * pointer.
65b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param str a NUL-terminated const char * pointer
6650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
67b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
68b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece(const char* str);
69b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#if U_HAVE_STD_STRING
70b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
71b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Constructs from a std::string.
7250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
73b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
7483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius  StringPiece(const std::string& str)
75b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    : ptr_(str.data()), length_(static_cast<int32_t>(str.size())) { }
76b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#endif
77b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
78b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Constructs from a const char * pointer and a specified length.
79b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param offset a const char * pointer (need not be terminated)
80b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param len the length of the string; must be non-negative
8150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
82b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
83b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece(const char* offset, int32_t len) : ptr_(offset), length_(len) { }
84b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
85b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Substring of another StringPiece.
86b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param x the other StringPiece
87b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param pos start position in x; must be non-negative and <= x.length().
8850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
89b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
90b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece(const StringPiece& x, int32_t pos);
91b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
92b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Substring of another StringPiece.
93b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param x the other StringPiece
94b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param pos start position in x; must be non-negative and <= x.length().
95b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param len length of the substring;
96b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   *            must be non-negative and will be pinned to at most x.length() - pos.
9750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
98b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
99b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece(const StringPiece& x, int32_t pos, int32_t len);
100b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
101b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
102b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Returns the string pointer. May be NULL if it is empty.
103b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   *
104b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * data() may return a pointer to a buffer with embedded NULs, and the
105b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * returned buffer may or may not be null terminated.  Therefore it is
106b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * typically a mistake to pass data() to a routine that expects a NUL
107b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * terminated string.
108b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @return the string pointer
10950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
110b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
111b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  const char* data() const { return ptr_; }
112b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
113b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Returns the string length. Same as length().
114b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @return the string length
11550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
116b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
117b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  int32_t size() const { return length_; }
118b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
119b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Returns the string length. Same as size().
120b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @return the string length
12150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
122b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
123b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  int32_t length() const { return length_; }
124b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
125b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Returns whether the string is empty.
126b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @return TRUE if the string is empty
12750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
128b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
129b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  UBool empty() const { return length_ == 0; }
130b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
131b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
132b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Sets to an empty string.
13350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
134b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
135b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  void clear() { ptr_ = NULL; length_ = 0; }
136b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
137b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
13850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * Reset the stringpiece to refer to new data.
139b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho   * @param xdata pointer the new string data.  Need not be nul terminated.
14050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @param len the length of the new data
14183a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius   * @stable ICU 4.8
14250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   */
143b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  void set(const char* xdata, int32_t len) { ptr_ = xdata; length_ = len; }
14450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
14550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho  /**
14650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * Reset the stringpiece to refer to new data.
14750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @param str a pointer to a NUL-terminated string.
14883a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius   * @stable ICU 4.8
14950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   */
15050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho  void set(const char* str);
15150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
15250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho  /**
153b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Removes the first n string units.
154b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param n prefix length, must be non-negative and <=length()
15550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
156b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
157b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  void remove_prefix(int32_t n) {
158b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    if (n >= 0) {
159b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      if (n > length_) {
160b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        n = length_;
161b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      }
162b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      ptr_ += n;
163b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      length_ -= n;
164b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    }
165b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  }
166b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
167b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
168b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Removes the last n string units.
169b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param n suffix length, must be non-negative and <=length()
17050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
171b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
172b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  void remove_suffix(int32_t n) {
173b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    if (n >= 0) {
174b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      if (n <= length_) {
175b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        length_ -= n;
176b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      } else {
177b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        length_ = 0;
178b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru      }
179b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    }
180b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  }
181b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
182b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
183b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Maximum integer, used as a default value for substring methods.
18450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
185b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
18659d709d503bab6e2b61931737e662dd293b40578ccornelius  static const int32_t npos; // = 0x7fffffff;
187b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
188b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  /**
189b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * Returns a substring of this StringPiece.
190b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param pos start position; must be non-negative and <= length().
191b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @param len length of the substring;
192b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   *            must be non-negative and will be pinned to at most length() - pos.
193b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   * @return the substring StringPiece
19450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho   * @stable ICU 4.2
195b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru   */
196b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  StringPiece substr(int32_t pos, int32_t len = npos) const {
197b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    return StringPiece(*this, pos, len);
198b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru  }
199b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru};
200b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
20150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/**
20250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Global operator == for StringPiece
20350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param x The first StringPiece to compare.
20450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param y The second StringPiece to compare.
20550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @return TRUE if the string data is equal
20683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius * @stable ICU 4.8
20750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */
20850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_EXPORT UBool U_EXPORT2
20950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehooperator==(const StringPiece& x, const StringPiece& y);
21050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
21150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/**
21250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Global operator != for StringPiece
21350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param x The first StringPiece to compare.
21450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param y The second StringPiece to compare.
21550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @return TRUE if the string data is not equal
21683a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius * @stable ICU 4.8
21750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */
21850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoinline UBool operator!=(const StringPiece& x, const StringPiece& y) {
21950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho  return !(x == y);
22050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}
22150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
222b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste QueruU_NAMESPACE_END
223b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
224b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru#endif  // __STRINGPIECE_H__
225