Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Catch::StringRef Class Reference

#include <catch_stringref.h>

Public Types

using size_type = std::size_t
 

Public Member Functions

 StringRef () noexcept
 
 StringRef (StringRef const &other) noexcept
 
 StringRef (StringRef &&other) noexcept
 
 StringRef (char const *rawChars) noexcept
 
 StringRef (char const *rawChars, size_type size) noexcept
 
 StringRef (std::string const &stdString) noexcept
 
 ~StringRef () noexcept
 
auto operator= (StringRef const &other) noexcept -> StringRef &
 
 operator std::string () const
 
void swap (StringRef &other) noexcept
 
auto operator== (StringRef const &other) const noexcept -> bool
 
auto operator!= (StringRef const &other) const noexcept -> bool
 
auto operator[] (size_type index) const noexcept -> char
 
auto empty () const noexcept -> bool
 
auto size () const noexcept -> size_type
 
auto numberOfCharacters () const noexcept -> size_type
 
auto c_str () const -> char const *
 
auto substr (size_type start, size_type size) const noexcept -> StringRef
 
auto currentData () const noexcept -> char const *
 
 StringRef () noexcept
 
 StringRef (StringRef const &other) noexcept
 
 StringRef (StringRef &&other) noexcept
 
 StringRef (char const *rawChars) noexcept
 
 StringRef (char const *rawChars, size_type size) noexcept
 
 StringRef (std::string const &stdString) noexcept
 
 ~StringRef () noexcept
 
auto operator= (StringRef const &other) noexcept -> StringRef &
 
 operator std::string () const
 
void swap (StringRef &other) noexcept
 
auto operator== (StringRef const &other) const noexcept -> bool
 
auto operator!= (StringRef const &other) const noexcept -> bool
 
auto operator[] (size_type index) const noexcept -> char
 
auto empty () const noexcept -> bool
 
auto size () const noexcept -> size_type
 
auto numberOfCharacters () const noexcept -> size_type
 
auto c_str () const -> char const *
 
auto substr (size_type start, size_type size) const noexcept -> StringRef
 
auto currentData () const noexcept -> char const *
 

Friends

struct StringRefTestAccess
 

Detailed Description

A non-owning string class (similar to the forthcoming std::string_view) Note that, because a StringRef may be a substring of another string, it may not be null terminated. c_str() must return a null terminated string, however, and so the StringRef will internally take ownership (taking a copy), if necessary. In theory this ownership is not externally visible - but it does mean (substring) StringRefs should not be shared between threads.

Definition at line 522 of file catch.hpp.

Member Typedef Documentation

◆ size_type

typedef std::size_t Catch::StringRef::size_type = std::size_t

Definition at line 25 of file catch_stringref.h.

Constructor & Destructor Documentation

◆ StringRef() [1/12]

Catch::StringRef::StringRef ( )
inlinenoexcept

Definition at line 40 of file catch_stringref.h.

41 : StringRef( s_empty, 0 )
42 {}
Here is the caller graph for this function:

◆ StringRef() [2/12]

Catch::StringRef::StringRef ( StringRef const & other)
inlinenoexcept

Definition at line 44 of file catch_stringref.h.

45 : m_start( other.m_start ),
46 m_size( other.m_size )
47 {}

◆ StringRef() [3/12]

Catch::StringRef::StringRef ( StringRef && other)
inlinenoexcept

Definition at line 49 of file catch_stringref.h.

50 : m_start( other.m_start ),
51 m_size( other.m_size ),
52 m_data( other.m_data )
53 {
54 other.m_data = nullptr;
55 }

◆ StringRef() [4/12]

Catch::StringRef::StringRef ( char const * rawChars)
noexcept

Definition at line 27 of file catch_stringref.cpp.

28 : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
29 {}
std::size_t size_type

◆ StringRef() [5/12]

Catch::StringRef::StringRef ( char const * rawChars,
size_type size )
inlinenoexcept

Definition at line 59 of file catch_stringref.h.

60 : m_start( rawChars ),
61 m_size( size )
62 {}
auto size() const noexcept -> size_type

◆ StringRef() [6/12]

Catch::StringRef::StringRef ( std::string const & stdString)
inlinenoexcept

Definition at line 64 of file catch_stringref.h.

65 : m_start( stdString.c_str() ),
66 m_size( stdString.size() )
67 {}

◆ ~StringRef() [1/2]

Catch::StringRef::~StringRef ( )
inlinenoexcept

Definition at line 69 of file catch_stringref.h.

69 {
70 delete[] m_data;
71 }

◆ StringRef() [7/12]

Catch::StringRef::StringRef ( )
inlinenoexcept

Definition at line 539 of file catch.hpp.

540 : StringRef( s_empty, 0 )
541 {}

◆ StringRef() [8/12]

Catch::StringRef::StringRef ( StringRef const & other)
inlinenoexcept

Definition at line 543 of file catch.hpp.

544 : m_start( other.m_start ),
545 m_size( other.m_size )
546 {}

◆ StringRef() [9/12]

Catch::StringRef::StringRef ( StringRef && other)
inlinenoexcept

Definition at line 548 of file catch.hpp.

549 : m_start( other.m_start ),
550 m_size( other.m_size ),
551 m_data( other.m_data )
552 {
553 other.m_data = nullptr;
554 }

◆ StringRef() [10/12]

Catch::StringRef::StringRef ( char const * rawChars)
noexcept

◆ StringRef() [11/12]

Catch::StringRef::StringRef ( char const * rawChars,
size_type size )
inlinenoexcept

Definition at line 558 of file catch.hpp.

559 : m_start( rawChars ),
560 m_size( size )
561 {}

◆ StringRef() [12/12]

Catch::StringRef::StringRef ( std::string const & stdString)
inlinenoexcept

Definition at line 563 of file catch.hpp.

564 : m_start( stdString.c_str() ),
565 m_size( stdString.size() )
566 {}

◆ ~StringRef() [2/2]

Catch::StringRef::~StringRef ( )
inlinenoexcept

Definition at line 568 of file catch.hpp.

568 {
569 delete[] m_data;
570 }

Member Function Documentation

◆ c_str() [1/2]

auto Catch::StringRef::c_str ( ) const -> char const*

Definition at line 41 of file catch_stringref.cpp.

41 {
42 if( isSubstring() )
43 const_cast<StringRef*>( this )->takeOwnership();
44 return m_start;
45 }

◆ c_str() [2/2]

auto Catch::StringRef::c_str ( ) const -> char const *

◆ currentData() [1/2]

auto Catch::StringRef::currentData ( ) const -> char const*
noexcept

Definition at line 46 of file catch_stringref.cpp.

46 {
47 return m_start;
48 }

◆ currentData() [2/2]

auto Catch::StringRef::currentData ( ) const -> char const *
noexcept
Here is the call graph for this function:

◆ empty() [1/2]

auto Catch::StringRef::empty ( ) const -> bool
inlinenoexcept

Definition at line 92 of file catch_stringref.h.

92 {
93 return m_size == 0;
94 }

◆ empty() [2/2]

auto Catch::StringRef::empty ( ) const -> bool
inlinenoexcept

Definition at line 591 of file catch.hpp.

591 {
592 return m_size == 0;
593 }

◆ numberOfCharacters() [1/2]

auto Catch::StringRef::numberOfCharacters ( ) const -> size_type
noexcept

Definition at line 84 of file catch_stringref.cpp.

84 {
85 size_type noChars = m_size;
86 // Make adjustments for uft encodings
87 for( size_type i=0; i < m_size; ++i ) {
88 char c = m_start[i];
89 if( ( c & byte_2_lead ) == byte_2_lead ) {
90 noChars--;
91 if (( c & byte_3_lead ) == byte_3_lead )
92 noChars--;
93 if( ( c & byte_4_lead ) == byte_4_lead )
94 noChars--;
95 }
96 }
97 return noChars;
98 }

◆ numberOfCharacters() [2/2]

auto Catch::StringRef::numberOfCharacters ( ) const -> size_type
noexcept

◆ operator std::string() [1/2]

Catch::StringRef::operator std::string ( ) const

Definition at line 31 of file catch_stringref.cpp.

31 {
32 return std::string( m_start, m_size );
33 }

◆ operator std::string() [2/2]

Catch::StringRef::operator std::string ( ) const

◆ operator!=() [1/2]

auto Catch::StringRef::operator!= ( StringRef const & other) const -> bool
noexcept

Definition at line 76 of file catch_stringref.cpp.

76 {
77 return !operator==( other );
78 }
auto operator==(StringRef const &other) const noexcept -> bool
Here is the call graph for this function:

◆ operator!=() [2/2]

auto Catch::StringRef::operator!= ( StringRef const & other) const -> bool
noexcept

◆ operator=() [1/2]

auto Catch::StringRef::operator= ( StringRef const & other) -> StringRef&
inlinenoexcept

Definition at line 73 of file catch_stringref.h.

73 {
74 delete[] m_data;
75 m_data = nullptr;
76 m_start = other.m_start;
77 m_size = other.m_size;
78 return *this;
79 }

◆ operator=() [2/2]

auto Catch::StringRef::operator= ( StringRef const & other) -> StringRef&
inlinenoexcept

Definition at line 572 of file catch.hpp.

572 {
573 delete[] m_data;
574 m_data = nullptr;
575 m_start = other.m_start;
576 m_size = other.m_size;
577 return *this;
578 }

◆ operator==() [1/2]

auto Catch::StringRef::operator== ( StringRef const & other) const -> bool
noexcept

Definition at line 71 of file catch_stringref.cpp.

71 {
72 return
73 size() == other.size() &&
74 (std::strncmp( m_start, other.m_start, size() ) == 0);
75 }

◆ operator==() [2/2]

auto Catch::StringRef::operator== ( StringRef const & other) const -> bool
noexcept

◆ operator[]() [1/2]

auto Catch::StringRef::operator[] ( size_type index) const -> char
noexcept

Definition at line 80 of file catch_stringref.cpp.

80 {
81 return m_start[index];
82 }

◆ operator[]() [2/2]

auto Catch::StringRef::operator[] ( size_type index) const -> char
noexcept

◆ size() [1/2]

auto Catch::StringRef::size ( ) const -> size_type
inlinenoexcept

Definition at line 95 of file catch_stringref.h.

95 {
96 return m_size;
97 }
Here is the caller graph for this function:

◆ size() [2/2]

auto Catch::StringRef::size ( ) const -> size_type
inlinenoexcept

Definition at line 594 of file catch.hpp.

594 {
595 return m_size;
596 }

◆ substr() [1/2]

auto Catch::StringRef::substr ( size_type start,
size_type size ) const -> StringRef
noexcept

Definition at line 65 of file catch_stringref.cpp.

65 {
66 if( start < m_size )
67 return StringRef( m_start+start, size );
68 else
69 return StringRef();
70 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ substr() [2/2]

auto Catch::StringRef::substr ( size_type start,
size_type size ) const -> StringRef
noexcept

◆ swap() [1/2]

void Catch::StringRef::swap ( StringRef & other)
noexcept

Definition at line 35 of file catch_stringref.cpp.

35 {
36 std::swap( m_start, other.m_start );
37 std::swap( m_size, other.m_size );
38 std::swap( m_data, other.m_data );
39 }
void swap(picojson::value &x, picojson::value &y)
Here is the call graph for this function:

◆ swap() [2/2]

void Catch::StringRef::swap ( StringRef & other)
noexcept

Friends And Related Symbol Documentation

◆ StringRefTestAccess

Definition at line 28 of file catch_stringref.h.


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