ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes
StringPiece Class Reference

A string-like object that points to a sized piece of memory. More...

#include <stringpiece.h>

Inheritance diagram for StringPiece:
UMemory

Public Member Functions

 StringPiece ()
 Default constructor, creates an empty StringPiece. More...
 
 StringPiece (const char *str)
 Constructs from a NUL-terminated const char * pointer. More...
 
 StringPiece (const char *offset, int32_t len)
 Constructs from a const char * pointer and a specified length. More...
 
 StringPiece (const StringPiece &x, int32_t pos)
 Substring of another StringPiece. More...
 
 StringPiece (const StringPiece &x, int32_t pos, int32_t len)
 Substring of another StringPiece. More...
 
const char * data () const
 Returns the string pointer. More...
 
int32_t size () const
 Returns the string length. More...
 
int32_t length () const
 Returns the string length. More...
 
UBool empty () const
 Returns whether the string is empty. More...
 
void clear ()
 Sets to an empty string. More...
 
void set (const char *xdata, int32_t len)
 Reset the stringpiece to refer to new data. More...
 
void set (const char *str)
 Reset the stringpiece to refer to new data. More...
 
void remove_prefix (int32_t n)
 Removes the first n string units. More...
 
void remove_suffix (int32_t n)
 Removes the last n string units. More...
 
StringPiece substr (int32_t pos, int32_t len=npos) const
 Returns a substring of this StringPiece. More...
 

Static Public Attributes

static const int32_t npos = 0x7fffffff
 Maximum integer, used as a default value for substring methods. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from UMemory
static void * operator new (size_t size)
 Override for ICU4C C++ memory management. More...
 
static void * operator new[] (size_t size)
 Override for ICU4C C++ memory management. More...
 
static void operator delete (void *p)
 Override for ICU4C C++ memory management. More...
 
static void operator delete[] (void *p)
 Override for ICU4C C++ memory management. More...
 
static void * operator new (size_t, void *ptr)
 Override for ICU4C C++ memory management for STL. More...
 
static void operator delete (void *, void *)
 Override for ICU4C C++ memory management for STL. More...
 

Detailed Description

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 const 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

Definition at line 52 of file stringpiece.h.

Constructor & Destructor Documentation

StringPiece::StringPiece ( )
inline

Default constructor, creates an empty StringPiece.

Stable:
ICU 4.2

Definition at line 62 of file stringpiece.h.

StringPiece::StringPiece ( const char *  str)

Constructs from a NUL-terminated const char * pointer.

Parameters
stra NUL-terminated const char * pointer
Stable:
ICU 4.2
StringPiece::StringPiece ( const char *  offset,
int32_t  len 
)
inline

Constructs from a const char * pointer and a specified length.

Parameters
offseta const char * pointer (need not be terminated)
lenthe length of the string; must be non-negative
Stable:
ICU 4.2

Definition at line 83 of file stringpiece.h.

StringPiece::StringPiece ( const StringPiece x,
int32_t  pos 
)

Substring of another StringPiece.

Parameters
xthe other StringPiece
posstart position in x; must be non-negative and <= x.length().
Stable:
ICU 4.2
StringPiece::StringPiece ( const StringPiece x,
int32_t  pos,
int32_t  len 
)

Substring of another StringPiece.

Parameters
xthe other StringPiece
posstart position in x; must be non-negative and <= x.length().
lenlength of the substring; must be non-negative and will be pinned to at most x.length() - pos.
Stable:
ICU 4.2

Member Function Documentation

void StringPiece::clear ( )
inline

Sets to an empty string.

Stable:
ICU 4.2

Definition at line 135 of file stringpiece.h.

References NULL.

const char* StringPiece::data ( ) const
inline

Returns the string pointer.

May be NULL if it is empty.

data() may return a pointer to a buffer with embedded NULs, and the returned buffer may or may not be null terminated. Therefore it is typically a mistake to pass data() to a routine that expects a NUL terminated string.

Returns
the string pointer
Stable:
ICU 4.2

Definition at line 111 of file stringpiece.h.

UBool StringPiece::empty ( ) const
inline

Returns whether the string is empty.

Returns
TRUE if the string is empty
Stable:
ICU 4.2

Definition at line 129 of file stringpiece.h.

int32_t StringPiece::length ( void  ) const
inline

Returns the string length.

Same as size().

Returns
the string length
Stable:
ICU 4.2

Definition at line 123 of file stringpiece.h.

void StringPiece::remove_prefix ( int32_t  n)
inline

Removes the first n string units.

Parameters
nprefix length, must be non-negative and <=length()
Stable:
ICU 4.2

Definition at line 157 of file stringpiece.h.

void StringPiece::remove_suffix ( int32_t  n)
inline

Removes the last n string units.

Parameters
nsuffix length, must be non-negative and <=length()
Stable:
ICU 4.2

Definition at line 172 of file stringpiece.h.

void StringPiece::set ( const char *  xdata,
int32_t  len 
)
inline

Reset the stringpiece to refer to new data.

Parameters
xdatapointer the new string data. Need not be nul terminated.
lenthe length of the new data
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Definition at line 143 of file stringpiece.h.

void StringPiece::set ( const char *  str)

Reset the stringpiece to refer to new data.

Parameters
stra pointer to a NUL-terminated string.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
int32_t StringPiece::size ( ) const
inline

Returns the string length.

Same as length().

Returns
the string length
Stable:
ICU 4.2

Definition at line 117 of file stringpiece.h.

StringPiece StringPiece::substr ( int32_t  pos,
int32_t  len = npos 
) const
inline

Returns a substring of this StringPiece.

Parameters
posstart position; must be non-negative and <= length().
lenlength of the substring; must be non-negative and will be pinned to at most length() - pos.
Returns
the substring StringPiece
Stable:
ICU 4.2

Definition at line 196 of file stringpiece.h.

Field Documentation

const int32_t StringPiece::npos = 0x7fffffff
static

Maximum integer, used as a default value for substring methods.

Stable:
ICU 4.2

Definition at line 186 of file stringpiece.h.


The documentation for this class was generated from the following file: