|
Cogs.Core
|
Provides a weakly referenced view over the contents of a string. More...
#include <StringView.h>
Public Types | |
| using | iterator = const char * |
| Iterator type. | |
| using | const_iterator = const char * |
| Const iterator type. | |
| using | value_type = char |
| Value type. | |
| using | Vector = Cogs::Collections::SmallVector< StringView, 10 > |
| Vector of strings type. | |
Public Member Functions | |
| constexpr | StringView () noexcept=default |
| Constructs an empty string view. | |
| constexpr | StringView (const char *data) noexcept |
| Construct a string view of the given null-terminated string. | |
| template<size_t LENGTH> | |
| constexpr | StringView (const char(&data)[LENGTH]) noexcept |
| Construct a string view from the given string literal. | |
| constexpr | StringView (const char *data, const size_t length) noexcept |
| Construct a string view of the given string data, with the given length. | |
| constexpr | StringView (const std::string_view s) noexcept |
| Construct a String view of the given std::string_view object. | |
| StringView (const std::string &s) noexcept | |
| Construct a string view of the given string object. | |
| bool | operator== (const StringView &other) const |
| Operator equal. | |
| constexpr iterator | begin () noexcept |
| Iterator to the beginning of the string. | |
| constexpr iterator | end () noexcept |
| Iterator to the end of the string. | |
| constexpr const_iterator | begin () const noexcept |
| Const iterator to the beginning of the string. | |
| constexpr const_iterator | end () const noexcept |
| Const iterator to the end of the string. | |
| constexpr const_iterator | cbegin () const noexcept |
| Const iterator to the beginning of the string. | |
| constexpr const_iterator | cend () const noexcept |
| Const iterator to the end of the string. | |
| constexpr bool | empty () const noexcept |
| Check if the string is empty. | |
| constexpr | operator bool () const noexcept |
| Explicit boolean conversion operator. | |
| operator std::string () const | |
| Explicit std::string conversion operator. | |
| constexpr | operator std::string_view () const noexcept |
| Implicit std::string_view conversion operator. | |
| std::string | to_string () const |
| String conversion method. | |
| constexpr std::string_view | to_string_view () const noexcept |
| Create a standard library string_view of the same view. | |
| constexpr const char * | data () const noexcept |
| Get the sequence of characters referenced by the string view. | |
| constexpr size_t | size () const noexcept |
| Get the size of the string. | |
| constexpr size_t | length () const noexcept |
| Get the length of the string. | |
| constexpr char | operator[] (const size_t index) const noexcept |
| Get the character at position index in the string. | |
| constexpr size_t | hash () const noexcept |
| Get the hash code of the string. | |
| constexpr size_t | hash (size_t hashValue) const noexcept |
| Combine the hash code of the string with the initial hash value provided. | |
| size_t | hashLowercase (size_t hashValue=Cogs::hash()) const noexcept |
| Get the hash code of the string converted to lowercase. | |
| size_t | find (const StringView &other, size_t offset=0) const noexcept |
| Find the given string segment inside the string. | |
| size_t | find_first_of (char character, size_t pos=0) const noexcept |
| Find the first occurance of the given character from the specified starting position. | |
| size_t | find_last_of (const StringView characters, size_t pos=NoPosition) const noexcept |
| See std::basic_string::find_last_of. | |
| size_t | find_last_of (const char character, size_t pos=NoPosition) const noexcept |
| See std::basic_string::find_last_of. | |
| int | compare (const StringView &other) const noexcept |
| Lexicographically compares the content of this string view with the given other. | |
| constexpr StringView | substr (size_t offset, size_t count=NoPosition) const noexcept |
| Get the given sub string. | |
| Vector | split (const StringView &delimiters) const |
| Split this string into parts. | |
| Vector | splitAll (const StringView &delimiters) const |
| Split this string into parts, empty parts will be retained. | |
| StringView & | trimStart () noexcept |
| Remove any whitespace from the start of this StringView's contents. | |
| StringView & | trimEnd () noexcept |
| Remove any whitespace from the end of this StringView's contents. | |
| StringView & | trim () noexcept |
| Remove any whitespace from the start and end of this StringView's contents. | |
Static Public Attributes | |
| static constexpr size_t | npos = static_cast<size_t>(-1) |
| No position. | |
| static constexpr size_t | NoPosition = npos |
| No position. | |
Private Types | |
| using | traits_type = std::char_traits< char > |
Private Member Functions | |
| int | compareMemory (const char *a, const char *b, size_t length) const |
| Compare two memory sequences. | |
Static Private Member Functions | |
| static bool | isWhiteSpace (char c) |
| Helper function that tests whether the given character is an ASCII whitespace character. | |
Private Attributes | |
| const char * | str = nullptr |
| Pointer to the string this view is over. | |
| size_t | strSize = 0 |
| Length of the string data pointed to. | |
Provides a weakly referenced view over the contents of a string.
E.g. same usage rules as std::string_view
No ownership is assumed over the given string, making the valid lifetime of a StringView bound to the lifetime of the string data it is constructed from. Therefore, it is usually not safe to store instances of StringView in objects, except when it can be reasonably guaranteed that the strings in question are literals or otherwise exists in the StringView instance usage lifetime.
Definition at line 49 of file StringView.h.
| using Cogs::StringView::const_iterator = const char * |
Const iterator type.
Definition at line 57 of file StringView.h.
| using Cogs::StringView::iterator = const char * |
Iterator type.
Definition at line 54 of file StringView.h.
|
private |
Definition at line 51 of file StringView.h.
| using Cogs::StringView::value_type = char |
Value type.
Definition at line 60 of file StringView.h.
Vector of strings type.
Definition at line 63 of file StringView.h.
|
inlineconstexprnoexcept |
Construct a string view of the given null-terminated string.
The string length is automatically calculated from the string data.
| data | Pointer to string data in memory. |
Definition at line 80 of file StringView.h.
|
inlineconstexprnoexcept |
Construct a string view from the given string literal.
| data | Pointer to the string literal. |
Definition at line 91 of file StringView.h.
|
inlineconstexprnoexcept |
Construct a string view of the given string data, with the given length.
| data | Pointer to string data in memory. |
| length | Length of the string data, not including null-termination, if any. |
Definition at line 100 of file StringView.h.
|
inlineconstexprnoexcept |
Construct a String view of the given std::string_view object.
| s | string_view to create a view of. |
Definition at line 106 of file StringView.h.
|
noexcept |
Construct a string view of the given string object.
| s | String to create a view of. |
Definition at line 5 of file StringView.cpp.
|
inlineconstexprnoexcept |
Const iterator to the beginning of the string.
Definition at line 132 of file StringView.h.
|
inlineconstexprnoexcept |
Iterator to the beginning of the string.
Definition at line 126 of file StringView.h.
Referenced by Cogs::ContextD3D11::pushCommandGroupAnnotation(), and Cogs::ContextD3D11::setAnnotationMarker().
|
inlineconstexprnoexcept |
Const iterator to the beginning of the string.
Definition at line 138 of file StringView.h.
|
inlineconstexprnoexcept |
Const iterator to the end of the string.
Definition at line 141 of file StringView.h.
|
noexcept |
Lexicographically compares the content of this string view with the given other.
| other | StringView instance to compare to. |
Definition at line 68 of file StringView.cpp.
|
inlineprivate |
Compare two memory sequences.
Definition at line 324 of file StringView.h.
|
inlineconstexprnoexcept |
Get the sequence of characters referenced by the string view.
Note: the data is not necessarily null-terminated, and may even contain null characters. To get a null-terminated string, use to_string.
Definition at line 197 of file StringView.h.
Referenced by Cogs::Core::ExtensionRegistry::add(), Cogs::BuffersGL20::annotate(), Cogs::BuffersWebGPU::annotate(), Cogs::RenderTargetsD3D11::annotate(), Cogs::EffectsGL20::annotate(), Cogs::RenderTargetsGL20::annotate(), Cogs::TexturesD3D11::annotate(), Cogs::TexturesGL20::annotate(), Cogs::EffectsGL20::annotateCS(), Cogs::EffectsGL20::annotateGS(), Cogs::EffectsGL20::annotatePS(), Cogs::EffectsGL20::annotateVS(), Cogs::EffectsGL20::getConstantBufferBinding(), Cogs::EffectsGLES30::getEffectVariable(), Cogs::EffectsGLES30::getSamplerStateBinding(), Cogs::ImmutableString::ImmutableString(), Cogs::RationalReducerExtension::AnnotationComponent::indexOfKey(), Cogs::Core::parseInt_(), Cogs::ContextGL20::pushCommandGroupAnnotation(), Cogs::ContextGL20::setAnnotationMarker(), and Cogs::ContextWebGPU::setAnnotationMarker().
|
inlineconstexprnoexcept |
Check if the string is empty.
Definition at line 148 of file StringView.h.
Referenced by Cogs::Core::ExtensionRegistry::add(), Cogs::EffectsGL20::annotate(), Cogs::RenderTargetsD3D11::annotate(), Cogs::RenderTargetsGL20::annotate(), Cogs::TexturesD3D11::annotate(), Cogs::EffectsGL20::annotateCS(), Cogs::EffectsGL20::annotateGS(), Cogs::EffectsGL20::annotatePS(), Cogs::EffectsGL20::annotateVS(), Cogs::Core::RemapMaterialCommand::apply(), Cogs::Reflection::TypeDatabase::createType(), Cogs::Core::ResourceManagerBase::destroy(), Cogs::EffectsGLES30::getConstantBufferBinding(), Cogs::EffectsGLES30::getTextureBinding(), Cogs::ImmutableString::ImmutableString(), Cogs::Core::EntityStore::renameEntity(), and Cogs::Core::ResourceBase::ResourceBase().
|
inlineconstexprnoexcept |
Const iterator to the end of the string.
Definition at line 135 of file StringView.h.
|
inlineconstexprnoexcept |
Iterator to the end of the string.
Definition at line 129 of file StringView.h.
Referenced by Cogs::ContextD3D11::pushCommandGroupAnnotation(), and Cogs::ContextD3D11::setAnnotationMarker().
|
noexcept |
Find the given string segment inside the string.
Starts the search at character offset.
Definition at line 18 of file StringView.cpp.
|
noexcept |
Find the first occurance of the given character from the specified starting position.
Definition at line 46 of file StringView.cpp.
Referenced by split(), and splitAll().
|
noexcept |
See std::basic_string::find_last_of.
Definition at line 56 of file StringView.cpp.
|
noexcept |
See std::basic_string::find_last_of.
Definition at line 31 of file StringView.cpp.
|
inlineconstexprnoexcept |
Get the hash code of the string.
Definition at line 226 of file StringView.h.
References Cogs::hash().
Referenced by Cogs::Core::Variables::erase(), Cogs::Core::Variables::exist(), Cogs::Core::Variables::get(), Cogs::Core::InputManager::getActionState(), Cogs::Core::InputManager::getAxisValue(), Cogs::Core::Variables::getIfExists(), and Cogs::Core::TextureManager::getTexture().
|
inlineconstexprnoexcept |
Combine the hash code of the string with the initial hash value provided.
Deprecated. Use Cogs::hash(string, hashValue)
Definition at line 235 of file StringView.h.
References Cogs::hash().
|
noexcept |
Get the hash code of the string converted to lowercase.
Deprecated. Use Cogs::hashLowercase(string, hashValue)
Lowercase is here defined as default "C" locale, i.e., A-Z is converted to a-z.
Definition at line 13 of file StringView.cpp.
References Cogs::hashLowercase().
Referenced by Cogs::Core::ModelManager::handleLoad(), Cogs::Core::parseBool_(), Cogs::Core::MaterialInstance::setTextureAddressMode(), and Cogs::Core::MaterialInstance::setTextureFilterMode().
|
inlinestaticprivate |
Helper function that tests whether the given character is an ASCII whitespace character.
Tests for tab (\t), line feed (
), carriage return (\r), and space ( ).
Definition at line 337 of file StringView.h.
|
inlineconstexprnoexcept |
Get the length of the string.
Equivalent to size().
Definition at line 211 of file StringView.h.
Referenced by Cogs::BuffersWebGPU::annotate(), Cogs::RenderTargetsD3D11::annotate(), Cogs::TexturesD3D11::annotate(), Cogs::EffectsGLES30::getSamplerStateBinding(), Cogs::Core::parseInt_(), and Cogs::ContextWebGPU::setAnnotationMarker().
|
inlineexplicitconstexprnoexcept |
Explicit boolean conversion operator.
Provided for better check before use semantics.
Definition at line 155 of file StringView.h.
|
inlineexplicit |
Explicit std::string conversion operator.
Provided to make it possible to cast a string view to a std::string.
Definition at line 163 of file StringView.h.
|
inlineconstexprnoexcept |
Implicit std::string_view conversion operator.
Provided to make StringView and std::string_view buddies (transition to std::string_view).
Definition at line 171 of file StringView.h.
|
inline |
Operator equal.
Compares this instance to the given StringView. To consider the string views equal, the length and content of the referenced strings must match exactly.
| other | StringView instance to compare this instance to. |
Definition at line 123 of file StringView.h.
|
inlineconstexprnoexcept |
Get the character at position index in the string.
Definition at line 218 of file StringView.h.
|
inlineconstexprnoexcept |
Get the size of the string.
Equivalent to length().
Definition at line 204 of file StringView.h.
Referenced by Cogs::BuffersGL20::annotate(), Cogs::EffectsGL20::annotate(), Cogs::RenderTargetsGL20::annotate(), Cogs::TexturesGL20::annotate(), Cogs::EffectsGL20::annotateCS(), Cogs::EffectsGL20::annotateGS(), Cogs::EffectsGL20::annotatePS(), Cogs::EffectsGL20::annotateVS(), Cogs::Core::EntityStore::createEntity(), Cogs::Core::EntityStore::destroyEntity(), Cogs::EffectsGLES30::getSamplerStateBinding(), Cogs::RationalReducerExtension::AnnotationComponent::getValue(), Cogs::ImmutableString::ImmutableString(), Cogs::RationalReducerExtension::AnnotationComponent::indexOfKey(), Cogs::EffectsCommon::loadEffect(), Cogs::Core::parseInt_(), Cogs::ContextGL20::pushCommandGroupAnnotation(), Cogs::ContextGL20::setAnnotationMarker(), and Cogs::RationalReducerExtension::AnnotationComponent::setValue().
| Cogs::StringView::Vector Cogs::StringView::split | ( | const StringView & | delimiters | ) | const |
Split this string into parts.
Definition at line 79 of file StringView.cpp.
References find_first_of().
| Cogs::StringView::Vector Cogs::StringView::splitAll | ( | const StringView & | delimiters | ) | const |
Split this string into parts, empty parts will be retained.
Definition at line 102 of file StringView.cpp.
References find_first_of().
|
inlineconstexprnoexcept |
Get the given sub string.
Definition at line 284 of file StringView.h.
Referenced by Cogs::Core::RemapMaterialCommand::apply(), Cogs::Core::applyFieldValues(), and Cogs::EffectsGLES30::getSamplerStateBinding().
| std::string Cogs::StringView::to_string | ( | ) | const |
String conversion method.
Provided to match standard library API. Deprecated: Use std::string(StringViewObject) for portability when converting to std::string_view
Definition at line 9 of file StringView.cpp.
Referenced by Cogs::Core::ExportCommand::apply(), Cogs::Core::RemapMaterialCommand::apply(), Cogs::Core::AudioExtension::initialize(), Cogs::Core::OGC3DTilesSystem::loadMissingModels(), Cogs::Core::ModelManager::loadModel(), Cogs::Core::TextureManager::loadTexture(), Cogs::Core::TextureManager::loadTextureFromMemory(), Cogs::RationalReducerExtension::AnnotationComponent::setValue(), and Cogs::Core::Variable::setValue().
|
inlineconstexprnoexcept |
Create a standard library string_view of the same view.
Deprecated: Use std::string_view(StringViewObject)
Definition at line 187 of file StringView.h.
|
noexcept |
Remove any whitespace from the start and end of this StringView's contents.
Definition at line 135 of file StringView.cpp.
References trimEnd().
|
noexcept |
Remove any whitespace from the end of this StringView's contents.
Definition at line 127 of file StringView.cpp.
Referenced by trim().
|
noexcept |
Remove any whitespace from the start of this StringView's contents.
Definition at line 118 of file StringView.cpp.
|
staticconstexpr |
No position.
Definition at line 69 of file StringView.h.
Referenced by Cogs::Core::RemapMaterialCommand::apply(), and Cogs::Core::TextureManager::getTexture().
|
staticconstexpr |
No position.
Definition at line 66 of file StringView.h.
|
private |
Pointer to the string this view is over.
Definition at line 327 of file StringView.h.
Referenced by operator==(), and to_string().
|
private |
Length of the string data pointed to.
Definition at line 330 of file StringView.h.
Referenced by operator==(), and to_string().