// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html // Copyright (C) 2009-2013, International Business Machines // Corporation and others. All Rights Reserved. // // Copyright 2001 and onwards Google Inc. // Author: Sanjay Ghemawat // This code is a contribution of Google code, and the style used here is // a compromise between the original Google code and the ICU coding guidelines. // For example, data types are ICU-ified (size_t,int->int32_t), // and API comments doxygen-ified, but function names and behavior are // as in the original, if possible. // Assertion-style error handling, not available in ICU, was changed to // parameter "pinning" similar to UnicodeString. // // In addition, this is only a partial port of the original Google code, // limited to what was needed so far. The (nearly) complete original code // is in the ICU svn repository at icuhtml/trunk/design/strings/contrib // (see ICU ticket 6765, r25517). #ifndef __STRINGPIECE_H__ #define __STRINGPIECE_H__ /** * \file * \brief C++ API: StringPiece: Read-only byte string wrapper class. */ #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API #include <cstddef> #include <type_traits> #include "unicode/uobject.h" #include "unicode/std_string.h" // Arghh! I wish C++ literals were "string". U_NAMESPACE_BEGIN /** * A string-like object that points to a sized piece of memory. * * We provide non-explicit singleton constructors so users can pass * in a "const char*" or a "string" wherever a "StringPiece" is * expected. * * Functions or methods may use StringPiece parameters to accept either a * "const char*" or a "string" value that will be implicitly converted to a * StringPiece. * * Systematic usage of StringPiece is encouraged as it will reduce unnecessary * conversions from "const char*" to "string" and back again. * * @stable ICU 4.2 */ class U_COMMON_API StringPiece : public UMemory { … }; /** * Global operator == for StringPiece * @param x The first StringPiece to compare. * @param y The second StringPiece to compare. * @return true if the string data is equal * @stable ICU 4.8 */ U_EXPORT UBool U_EXPORT2 operator==(const StringPiece& x, const StringPiece& y); /** * Global operator != for StringPiece * @param x The first StringPiece to compare. * @param y The second StringPiece to compare. * @return true if the string data is not equal * @stable ICU 4.8 */ inline bool operator!=(const StringPiece& x, const StringPiece& y) { … } U_NAMESPACE_END #endif /* U_SHOW_CPLUSPLUS_API */ #endif // __STRINGPIECE_H__