Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::StringView Class Reference

View of a UTF-8 character string. More...

#include </__w/arcaneframework.github.io/arcaneframework.github.io/framework/arccore/src/base/arccore/base/StringView.h>

Collaboration diagram for Arcane::StringView:

Public Member Functions

 StringView ()=default
 Creates a view of an empty string.
 StringView (const char *str) ARCCORE_NOEXCEPT
 Creates a view from str encoded in UTF-8. str may be null.
 StringView (std::string_view str) ARCCORE_NOEXCEPT
 Creates a string from str in UTF-8 encoding.
constexpr StringView (Span< const Byte > str) ARCCORE_NOEXCEPT
 Creates a string from str in UTF-8 encoding.
constexpr StringView (const StringView &str)=default
 Copy constructor.
constexpr StringViewoperator= (const StringView &str)=default
 Copies the view str into this instance.
StringViewoperator= (const char *str) ARCCORE_NOEXCEPT
 Creates a view from str encoded in UTF-8.
StringViewoperator= (std::string_view str) ARCCORE_NOEXCEPT
 Creates a view from str encoded in UTF-8.
constexpr StringViewoperator= (Span< const Byte > str) ARCCORE_NOEXCEPT
 Creates a view from str encoded in UTF-8.
 ~StringView ()=default
 Frees resources.
constexpr Span< const Bytebytes () const ARCCORE_NOEXCEPT
 Returns the conversion of the instance in UTF-8 encoding.
constexpr Int64 length () const ARCCORE_NOEXCEPT
 Length in bytes of the character string.
constexpr Int64 size () const ARCCORE_NOEXCEPT
 Length in bytes of the character string.
constexpr bool empty () const ARCCORE_NOEXCEPT
 True if the string is null or empty.
std::string_view toStdStringView () const ARCCORE_NOEXCEPT
 Returns an STL view of the current view.
void writeBytes (std::ostream &o) const
 Writes the string in UTF-8 format to the stream o.
StringView subView (Int64 pos) const
 Substring starting at position pos.
StringView subView (Int64 pos, Int64 len) const
 Substring starting at position pos and of length len.

Private Attributes

Span< const Bytem_v

Friends

std::ostream & operator<< (std::ostream &o, const StringView &str)
 StringView output operator.
bool operator== (const StringView &a, const StringView &b)
 Compares two views.
bool operator!= (const StringView &a, const StringView &b)
 Compares two Unicode strings.
bool operator== (const char *a, const StringView &b)
 Compares two Unicode strings.
bool operator!= (const char *a, const StringView &b)
 Compares two Unicode strings.
bool operator== (const StringView &a, const char *b)
 Compares two Unicode strings.
bool operator!= (const StringView &a, const char *b)
 Compares two Unicode strings.
bool operator< (const StringView &a, const StringView &b)
 Compares two Unicode strings.

Detailed Description

View of a UTF-8 character string.

This class is similar to std::string_view in C++17 in that it only holds a pointer to memory managed by another class. Therefore, instances of this class should not be kept. The main difference lies in the encoding, which must be UTF-8 with this class.

Note
Like the std::string_view class, the bytes() array does not necessarily contain a null terminator. This means, among other things, that this class should not be used to pass parameters to C functions.

Definition at line 43 of file StringView.h.

Constructor & Destructor Documentation

◆ StringView() [1/3]

Arcane::StringView::StringView ( const char * str)
inline

Creates a view from str encoded in UTF-8. str may be null.

Definition at line 50 of file StringView.h.

References StringView().

Here is the call graph for this function:

◆ StringView() [2/3]

Arcane::StringView::StringView ( std::string_view str)
inline

Creates a string from str in UTF-8 encoding.

Definition at line 53 of file StringView.h.

◆ StringView() [3/3]

Arcane::StringView::StringView ( Span< const Byte > str)
inlineconstexpr

Creates a string from str in UTF-8 encoding.

Definition at line 56 of file StringView.h.

Member Function Documentation

◆ bytes()

Span< const Byte > Arcane::StringView::bytes ( ) const
inlineconstexpr

Returns the conversion of the instance in UTF-8 encoding.

Warning
The returned instance does not contain a null terminator.
The instance remains the owner of the returned value, and this value is invalidated by any modification of this instance.

Definition at line 93 of file StringView.h.

Referenced by Arcane::StringVariableReplace::_countChar(), Arcane::Convert::Impl::StringViewToDoubleConverter::_getDoubleValueWithFromChars(), Arcane::StringVariableReplace::_splitString(), Arcane::MeshUtils::dumpSynchronizerTopologyJSON(), Arcane::ParameterOptionAddr::ParameterOptionAddr(), and Arcane::StringVariableReplace::replaceWithCmdLineArgs().

Here is the caller graph for this function:

◆ empty()

bool Arcane::StringView::empty ( ) const
inlineconstexpr

True if the string is null or empty.

Definition at line 102 of file StringView.h.

References size().

Referenced by Arcane::builtInGetValue(), Arcane::StringVariableReplace::replaceWithCmdLineArgs(), Arcane::Accelerator::AcceleratorRuntimeInitialisationInfo::setAcceleratorRuntime(), Arcane::Convert::ScalarType< T >::tryParse(), and Arcane::Convert::ScalarType< T >::tryParseIfNotEmpty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

Int64 Arcane::StringView::length ( ) const
inlineconstexpr

Length in bytes of the character string.

Definition at line 96 of file StringView.h.

Referenced by Arcane::StringVariableReplace::_splitString(), and subView().

Here is the caller graph for this function:

◆ operator=() [1/3]

StringView & Arcane::StringView::operator= ( const char * str)
inline

Creates a view from str encoded in UTF-8.

Definition at line 63 of file StringView.h.

References operator=(), and StringView().

Here is the call graph for this function:

◆ operator=() [2/3]

StringView & Arcane::StringView::operator= ( Span< const Byte > str)
inlineconstexpr

Creates a view from str encoded in UTF-8.

Definition at line 75 of file StringView.h.

References StringView().

Here is the call graph for this function:

◆ operator=() [3/3]

StringView & Arcane::StringView::operator= ( std::string_view str)
inline

Creates a view from str encoded in UTF-8.

Definition at line 69 of file StringView.h.

References StringView().

Here is the call graph for this function:

◆ size()

Int64 Arcane::StringView::size ( ) const
inlineconstexpr

Length in bytes of the character string.

Definition at line 99 of file StringView.h.

Referenced by Arcane::Convert::Impl::StringViewToDoubleConverter::_getDoubleValue(), empty(), and Arcane::Convert::ScalarType< Int32 >::tryParse().

Here is the caller graph for this function:

◆ subView() [1/2]

StringView Arcane::StringView::subView ( Int64 pos) const

Substring starting at position pos.

Definition at line 36 of file StringView.cc.

References length(), StringView(), and subView().

Referenced by Arcane::StringVariableReplace::_splitString(), Arcane::ParameterOptionElementsCollection::addParameter(), Arcane::ParameterOptionAddr::ParameterOptionAddr(), and subView().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subView() [2/2]

StringView Arcane::StringView::subView ( Int64 pos,
Int64 len ) const

Substring starting at position pos and of length len.

Definition at line 45 of file StringView.cc.

References StringView().

Here is the call graph for this function:

◆ toStdStringView()

std::string_view Arcane::StringView::toStdStringView ( ) const
inline

Returns an STL view of the current view.

Definition at line 109 of file StringView.h.

Referenced by operator<, and operator==.

Here is the caller graph for this function:

◆ writeBytes()

void Arcane::StringView::writeBytes ( std::ostream & o) const

Writes the string in UTF-8 format to the stream o.

Definition at line 27 of file StringView.cc.

Referenced by operator<<.

Here is the caller graph for this function:

◆ operator!= [1/3]

bool operator!= ( const char * a,
const StringView & b )
friend

Compares two Unicode strings.

Return values
trueif they are different,
falseif they are equal. \relate String

Definition at line 149 of file StringView.h.

References operator==, and StringView().

◆ operator!= [2/3]

bool operator!= ( const StringView & a,
const char * b )
friend

Compares two Unicode strings.

Return values
trueif they are different,
falseif they are equal. \relate String

Definition at line 165 of file StringView.h.

References operator==, and StringView().

◆ operator!= [3/3]

bool operator!= ( const StringView & a,
const StringView & b )
friend

Compares two Unicode strings.

Return values
trueif they are different,
falseif they are equal. \relate String

Definition at line 130 of file StringView.h.

References operator==, and StringView().

◆ operator<

bool operator< ( const StringView & a,
const StringView & b )
friend

Compares two Unicode strings.

Return values
trueif a<b
falseotherwise. \relate String

Definition at line 93 of file StringView.cc.

References StringView(), and toStdStringView().

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
const StringView & str )
friend

StringView output operator.

Definition at line 56 of file StringView.cc.

References operator<<, StringView(), and writeBytes().

Referenced by operator<<.

◆ operator== [1/3]

bool operator== ( const char * a,
const StringView & b )
friend

Compares two Unicode strings.

Return values
trueif they are equal,
falseotherwise. \relate String

Definition at line 77 of file StringView.cc.

References operator==, and StringView().

◆ operator== [2/3]

bool operator== ( const StringView & a,
const char * b )
friend

Compares two Unicode strings.

Return values
trueif they are equal,
falseotherwise. \relate String

Definition at line 85 of file StringView.cc.

References operator==, and StringView().

◆ operator== [3/3]

bool operator== ( const StringView & a,
const StringView & b )
friend

Compares two views.

Return values
trueif they are equal,
falseotherwise.

Definition at line 66 of file StringView.cc.

References operator==, StringView(), and toStdStringView().

Referenced by operator!=, operator!=, operator!=, operator==, operator==, and operator==.

Member Data Documentation

◆ m_v

Span<const Byte> Arcane::StringView::m_v
private

Definition at line 191 of file StringView.h.


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