MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / StringRef

Class StringRef

Bcore/src/main/cpp/Dobby/tests/catch.hpp:391–469  ·  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. 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) StringRe

Source from the content-addressed store, hash-verified

389/// visible - but it does mean (substring) StringRefs should not be shared between
390/// threads.
391class StringRef {
392public:
393 using size_type = std::size_t;
394
395private:
396 friend struct StringRefTestAccess;
397
398 char const *m_start;
399 size_type m_size;
400
401 char *m_data = nullptr;
402
403 void takeOwnership();
404
405 static constexpr char const *const s_empty = "";
406
407public: // construction/ assignment
408 StringRef() noexcept : StringRef(s_empty, 0) {
409 }
410
411 StringRef(StringRef const &other) noexcept : m_start(other.m_start), m_size(other.m_size) {
412 }
413
414 StringRef(StringRef &&other) noexcept : m_start(other.m_start), m_size(other.m_size), m_data(other.m_data) {
415 other.m_data = nullptr;
416 }
417
418 StringRef(char const *rawChars) noexcept;
419
420 StringRef(char const *rawChars, size_type size) noexcept : m_start(rawChars), m_size(size) {
421 }
422
423 StringRef(std::string const &stdString) noexcept : m_start(stdString.c_str()), m_size(stdString.size()) {
424 }
425
426 ~StringRef() noexcept {
427 delete[] m_data;
428 }
429
430 auto operator=(StringRef const &other) noexcept -> StringRef & {
431 delete[] m_data;
432 m_data = nullptr;
433 m_start = other.m_start;
434 m_size = other.m_size;
435 return *this;
436 }
437
438 operator std::string() const;
439
440 void swap(StringRef &other) noexcept;
441
442public: // operators
443 auto operator==(StringRef const &other) const noexcept -> bool;
444 auto operator!=(StringRef const &other) const noexcept -> bool;
445
446 auto operator[](size_type index) const noexcept -> char;
447
448public: // named queries

Callers 7

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

Calls

no outgoing calls

Tested by 5

operator"" _srFunction · 0.68
RunContextMethod · 0.68
resetAssertionInfoMethod · 0.68
runCurrentTestMethod · 0.68
substrMethod · 0.68