Ninja
Public Types | Public Member Functions | Public Attributes | List of all members
StringPiece Struct Reference

StringPiece represents a slice of a string whose memory is managed externally. More...

#include <string_piece.h>

Public Types

typedef const char * const_iterator
 

Public Member Functions

std::string AsString () const
 Convert the slice into a full-fledged std::string, copying the data into a new string. More...
 
const_iterator begin () const
 
size_t empty () const
 
const_iterator end () const
 
bool operator!= (const StringPiece &other) const
 
bool operator== (const StringPiece &other) const
 
char operator[] (size_t pos) const
 
size_t size () const
 
 StringPiece ()
 
 StringPiece (const char *str)
 
 StringPiece (const char *str, size_t len)
 
 StringPiece (const std::string &str)
 The constructors intentionally allow for implicit conversions. More...
 

Public Attributes

size_t len_
 
const char * str_
 

Detailed Description

StringPiece represents a slice of a string whose memory is managed externally.

It is useful for reducing the number of std::strings we need to allocate.

Definition at line 25 of file string_piece.h.

Member Typedef Documentation

◆ const_iterator

typedef const char* StringPiece::const_iterator

Definition at line 26 of file string_piece.h.

Constructor & Destructor Documentation

◆ StringPiece() [1/4]

StringPiece::StringPiece ( )
inline

Definition at line 28 of file string_piece.h.

◆ StringPiece() [2/4]

StringPiece::StringPiece ( const std::string &  str)
inline

The constructors intentionally allow for implicit conversions.

Definition at line 31 of file string_piece.h.

◆ StringPiece() [3/4]

StringPiece::StringPiece ( const char *  str)
inline

Definition at line 32 of file string_piece.h.

◆ StringPiece() [4/4]

StringPiece::StringPiece ( const char *  str,
size_t  len 
)
inline

Definition at line 34 of file string_piece.h.

Member Function Documentation

◆ AsString()

std::string StringPiece::AsString ( ) const
inline

Convert the slice into a full-fledged std::string, copying the data into a new string.

Definition at line 46 of file string_piece.h.

References len_, and str_.

Referenced by IncludesNormalize::AbsPath(), State::AddDefault(), State::AddOut(), EvalString::AddSpecial(), EvalString::AddText(), State::GetNode(), IncludesNormalize::Normalize(), Jobserver::ParseMakeFlagsValue(), and BuildLog::Restat().

◆ begin()

const_iterator StringPiece::begin ( ) const
inline

Definition at line 50 of file string_piece.h.

References str_.

Referenced by EvalString::AddText(), and SplitStringPiece().

◆ empty()

size_t StringPiece::empty ( ) const
inline

Definition at line 66 of file string_piece.h.

References len_.

◆ end()

const_iterator StringPiece::end ( ) const
inline

Definition at line 54 of file string_piece.h.

References len_, and str_.

Referenced by EvalString::AddText(), and SplitStringPiece().

◆ operator!=()

bool StringPiece::operator!= ( const StringPiece other) const
inline

Definition at line 40 of file string_piece.h.

◆ operator==()

bool StringPiece::operator== ( const StringPiece other) const
inline

Definition at line 36 of file string_piece.h.

References len_, and str_.

◆ operator[]()

char StringPiece::operator[] ( size_t  pos) const
inline

Definition at line 58 of file string_piece.h.

References str_.

◆ size()

size_t StringPiece::size ( ) const
inline

Definition at line 62 of file string_piece.h.

References len_.

Member Data Documentation

◆ len_

size_t StringPiece::len_

◆ str_

const char* StringPiece::str_

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