MCPcopy Create free account
hub / github.com/Profactor/cv-plot / StringRef

Class StringRef

CvPlot/ext/catch2/inc/catch.hpp:583–652  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

581 /// Note that, because a StringRef may be a substring of another string,
582 /// it may not be null terminated.
583 class StringRef {
584 public:
585 using size_type = std::size_t;
586 using const_iterator = const char*;
587
588 private:
589 static constexpr char const* const s_empty = "";
590
591 char const* m_start = s_empty;
592 size_type m_size = 0;
593
594 public: // construction
595 constexpr StringRef() noexcept = default;
596
597 StringRef( char const* rawChars ) noexcept;
598
599 constexpr StringRef( char const* rawChars, size_type size ) noexcept
600 : m_start( rawChars ),
601 m_size( size )
602 {}
603
604 StringRef( std::string const& stdString ) noexcept
605 : m_start( stdString.c_str() ),
606 m_size( stdString.size() )
607 {}
608
609 explicit operator std::string() const {
610 return std::string(m_start, m_size);
611 }
612
613 public: // operators
614 auto operator == ( StringRef const& other ) const noexcept -> bool;
615 auto operator != (StringRef const& other) const noexcept -> bool {
616 return !(*this == other);
617 }
618
619 auto operator[] ( size_type index ) const noexcept -> char {
620 assert(index < m_size);
621 return m_start[index];
622 }
623
624 public: // named queries
625 constexpr auto empty() const noexcept -> bool {
626 return m_size == 0;
627 }
628 constexpr auto size() const noexcept -> size_type {
629 return m_size;
630 }
631
632 // Returns the current start pointer. If the StringRef is not
633 // null-terminated, throws std::domain_exception
634 auto c_str() const -> char const*;
635
636 public: // substrings and searches
637 // Returns a substring of [start, start + length).
638 // If start + length > size(), then the substring is [start, size()).
639 // If start > size(), then the substring is empty.
640 auto substr( size_type start, size_type length ) const noexcept -> StringRef;

Callers 7

operator "" _srFunction · 0.85
operator "" _catch_srFunction · 0.85
NameAndTagsClass · 0.85
RunContextMethod · 0.85
resetAssertionInfoMethod · 0.85
runCurrentTestMethod · 0.85
substrMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected