Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
cudf::string_view Class Reference

A non-owning, immutable view of device data that is a variable length char array representing a UTF-8 string. More...

#include <string_view.hpp>

Classes

class  const_iterator
 Handy iterator for navigating through encoded characters. More...
 

Public Member Functions

CUDF_HOST_DEVICE size_type size_bytes () const
 Return the number of bytes in this string. More...
 
size_type length () const
 Return the number of characters in this string. More...
 
CUDF_HOST_DEVICE char const * data () const
 Return a pointer to the internal device array. More...
 
CUDF_HOST_DEVICE bool empty () const
 Return true if string has no characters. More...
 
const_iterator begin () const
 Return new iterator pointing to the beginning of this string. More...
 
const_iterator end () const
 Return new iterator pointing past the end of this string. More...
 
char_utf8 operator[] (size_type pos) const
 Return single UTF-8 character at the given character position. More...
 
size_type byte_offset (size_type pos) const
 Return the byte offset from data() for a given character position. More...
 
int compare (string_view const &str) const
 Comparing target string with this string. Each character is compared as a UTF-8 code-point value. More...
 
int compare (char const *str, size_type bytes) const
 Comparing target string with this string. Each character is compared as a UTF-8 code-point value. More...
 
bool operator== (string_view const &rhs) const
 Returns true if rhs matches this string exactly. More...
 
bool operator!= (string_view const &rhs) const
 Returns true if rhs does not match this string. More...
 
bool operator< (string_view const &rhs) const
 Returns true if this string is ordered before rhs. More...
 
bool operator> (string_view const &rhs) const
 Returns true if rhs is ordered before this string. More...
 
bool operator<= (string_view const &rhs) const
 Returns true if this string matches or is ordered before rhs. More...
 
bool operator>= (string_view const &rhs) const
 Returns true if rhs matches or is ordered before this string. More...
 
size_type find (string_view const &str, size_type pos=0, size_type count=-1) const
 Returns the character position of the first occurrence where the argument str is found in this string within the character range [pos,pos+n). More...
 
size_type find (char const *str, size_type bytes, size_type pos=0, size_type count=-1) const
 Returns the character position of the first occurrence where the array str is found in this string within the character range [pos,pos+n). More...
 
size_type find (char_utf8 character, size_type pos=0, size_type count=-1) const
 Returns the character position of the first occurrence where character is found in this string within the character range [pos,pos+n). More...
 
size_type rfind (string_view const &str, size_type pos=0, size_type count=-1) const
 Returns the character position of the last occurrence where the argument str is found in this string within the character range [pos,pos+n). More...
 
size_type rfind (char const *str, size_type bytes, size_type pos=0, size_type count=-1) const
 Returns the character position of the last occurrence where the array str is found in this string within the character range [pos,pos+n). More...
 
size_type rfind (char_utf8 character, size_type pos=0, size_type count=-1) const
 Returns the character position of the last occurrence where character is found in this string within the character range [pos,pos+n). More...
 
string_view substr (size_type start, size_type length) const
 Return a sub-string of this string. The original string and device memory must still be maintained for the lifetime of the returned instance. More...
 
CUDF_HOST_DEVICE string_view ()
 Default constructor represents an empty string.
 
CUDF_HOST_DEVICE string_view (char const *data, size_type bytes)
 Create instance from existing device char array. More...
 
 string_view (string_view const &)=default
 Copy constructor.
 
 string_view (string_view &&)=default
 Move constructor.
 
string_viewoperator= (string_view const &)=default
 Copy assignment operator. More...
 
string_viewoperator= (string_view &&)=default
 Move assignment operator. More...
 

Static Public Member Functions

static CUDF_HOST_DEVICE string_view min ()
 Return minimum value associated with the string type. More...
 
static CUDF_HOST_DEVICE string_view max ()
 Return maximum value associated with the string type. More...
 

Static Public Attributes

static cudf::size_type const npos {-1}
 No-position value. More...
 

Detailed Description

A non-owning, immutable view of device data that is a variable length char array representing a UTF-8 string.

The caller must maintain the device memory for the lifetime of this instance.

This may be used to wrap a device pointer and size but any member function that requires accessing the device memory must be called from a kernel.

Definition at line 44 of file string_view.hpp.

Constructor & Destructor Documentation

◆ string_view()

CUDF_HOST_DEVICE cudf::string_view::string_view ( char const *  data,
size_type  bytes 
)
inline

Create instance from existing device char array.

Parameters
dataDevice char array encoded in UTF8.
bytesNumber of bytes in data array.

Definition at line 343 of file string_view.hpp.

Member Function Documentation

◆ begin()

const_iterator cudf::string_view::begin ( ) const
inline

Return new iterator pointing to the beginning of this string.

Returns
new iterator pointing to the beginning of this string

◆ byte_offset()

size_type cudf::string_view::byte_offset ( size_type  pos) const
inline

Return the byte offset from data() for a given character position.

Parameters
posCharacter position
Returns
Byte offset from data() for a given character position

Definition at line 303 of file string_view.cuh.

◆ compare() [1/2]

int cudf::string_view::compare ( char const *  str,
size_type  bytes 
) const
inline

Comparing target string with this string. Each character is compared as a UTF-8 code-point value.

Parameters
strTarget string to compare with this string.
bytesNumber of bytes in str.
Returns
0 If they compare equal. <0 Either the value of the first character of this string that does not match is lower in the arg string, or all compared characters match but the arg string is shorter. >0 Either the value of the first character of this string that does not match is greater in the arg string, or all compared characters match but the arg string is longer.

Definition at line 314 of file string_view.cuh.

◆ compare() [2/2]

int cudf::string_view::compare ( string_view const &  str) const
inline

Comparing target string with this string. Each character is compared as a UTF-8 code-point value.

Parameters
strTarget string to compare with this string.
Returns
0 If they compare equal. <0 Either the value of the first character of this string that does not match is lower in the arg string, or all compared characters match but the arg string is shorter. >0 Either the value of the first character of this string that does not match is greater in the arg string, or all compared characters match but the arg string is longer.

Definition at line 309 of file string_view.cuh.

◆ data()

CUDF_HOST_DEVICE char const* cudf::string_view::data ( ) const
inline

Return a pointer to the internal device array.

Returns
A pointer to the internal device array

Definition at line 63 of file string_view.hpp.

◆ empty()

CUDF_HOST_DEVICE bool cudf::string_view::empty ( ) const
inline

Return true if string has no characters.

Returns
true if string has no characters

Definition at line 70 of file string_view.hpp.

◆ end()

const_iterator cudf::string_view::end ( ) const
inline

Return new iterator pointing past the end of this string.

Returns
new iterator pointing past the end of this string

◆ find() [1/3]

size_type cudf::string_view::find ( char const *  str,
size_type  bytes,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the first occurrence where the array str is found in this string within the character range [pos,pos+n).

Parameters
strTarget array to search within this string.
bytesNumber of bytes in str.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if arg string is not found in this string.

Definition at line 401 of file string_view.cuh.

◆ find() [2/3]

size_type cudf::string_view::find ( char_utf8  character,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the first occurrence where character is found in this string within the character range [pos,pos+n).

Parameters
characterSingle encoded character.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if arg string is not found in this string.

Definition at line 409 of file string_view.cuh.

◆ find() [3/3]

size_type cudf::string_view::find ( string_view const &  str,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the first occurrence where the argument str is found in this string within the character range [pos,pos+n).

Parameters
strTarget string to search within this string.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if str is not found in this string.

Definition at line 363 of file string_view.cuh.

◆ length()

size_type cudf::string_view::length ( ) const
inline

Return the number of characters in this string.

Returns
The number of characters in this string

Definition at line 137 of file string_view.cuh.

◆ max()

CUDF_HOST_DEVICE string_view cudf::string_view::max ( )
inlinestatic

Return maximum value associated with the string type.

This function is needed to be host callable because it is called by a host callable function DeviceMin::identity<string_view>()

Returns
A string value which represents the highest possible valid UTF-8 encoded character.

Definition at line 125 of file string_view.cuh.

◆ min()

CUDF_HOST_DEVICE string_view cudf::string_view::min ( )
inlinestatic

Return minimum value associated with the string type.

This function is needed to be host callable because it is called by a host callable function DeviceMax::identity<string_view>()

Returns
An empty string

Definition at line 114 of file string_view.cuh.

◆ operator!=()

bool cudf::string_view::operator!= ( string_view const &  rhs) const
inline

Returns true if rhs does not match this string.

Parameters
rhsTarget string to compare with this string.
Returns
true if rhs does not match this string

Definition at line 336 of file string_view.cuh.

◆ operator<()

bool cudf::string_view::operator< ( string_view const &  rhs) const
inline

Returns true if this string is ordered before rhs.

Parameters
rhsTarget string to compare with this string.
Returns
true if this string is ordered before rhs

Definition at line 341 of file string_view.cuh.

◆ operator<=()

bool cudf::string_view::operator<= ( string_view const &  rhs) const
inline

Returns true if this string matches or is ordered before rhs.

Parameters
rhsTarget string to compare with this string.
Returns
true if this string matches or is ordered before rhs

Definition at line 351 of file string_view.cuh.

◆ operator=() [1/2]

string_view& cudf::string_view::operator= ( string_view &&  )
default

Move assignment operator.

Returns
Reference to this instance (after transferring ownership)

◆ operator=() [2/2]

string_view& cudf::string_view::operator= ( string_view const &  )
default

Copy assignment operator.

Returns
Reference to this instance

◆ operator==()

bool cudf::string_view::operator== ( string_view const &  rhs) const
inline

Returns true if rhs matches this string exactly.

Parameters
rhsTarget string to compare with this string.
Returns
true if rhs matches this string exactly

Definition at line 331 of file string_view.cuh.

◆ operator>()

bool cudf::string_view::operator> ( string_view const &  rhs) const
inline

Returns true if rhs is ordered before this string.

Parameters
rhsTarget string to compare with this string.
Returns
true if rhs is ordered before this string

Definition at line 346 of file string_view.cuh.

◆ operator>=()

bool cudf::string_view::operator>= ( string_view const &  rhs) const
inline

Returns true if rhs matches or is ordered before this string.

Parameters
rhsTarget string to compare with this string.
Returns
true if rhs matches or is ordered before this string

Definition at line 357 of file string_view.cuh.

◆ operator[]()

char_utf8 cudf::string_view::operator[] ( size_type  pos) const
inline

Return single UTF-8 character at the given character position.

Parameters
posCharacter position
Returns
UTF-8 character at the given character position

Definition at line 294 of file string_view.cuh.

◆ rfind() [1/3]

size_type cudf::string_view::rfind ( char const *  str,
size_type  bytes,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the last occurrence where the array str is found in this string within the character range [pos,pos+n).

Parameters
strTarget string to search with this string.
bytesNumber of bytes in str.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if arg string is not found in this string.

Definition at line 423 of file string_view.cuh.

◆ rfind() [2/3]

size_type cudf::string_view::rfind ( char_utf8  character,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the last occurrence where character is found in this string within the character range [pos,pos+n).

Parameters
characterSingle encoded character.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if arg string is not found in this string.

Definition at line 431 of file string_view.cuh.

◆ rfind() [3/3]

size_type cudf::string_view::rfind ( string_view const &  str,
size_type  pos = 0,
size_type  count = -1 
) const
inline

Returns the character position of the last occurrence where the argument str is found in this string within the character range [pos,pos+n).

Parameters
strTarget string to search within this string.
posCharacter position to start search within this string.
countNumber of characters from pos to include in the search. Specify -1 to indicate to the end of the string.
Returns
npos if arg string is not found in this string.

Definition at line 416 of file string_view.cuh.

◆ size_bytes()

CUDF_HOST_DEVICE size_type cudf::string_view::size_bytes ( ) const
inline

Return the number of bytes in this string.

Returns
The number of bytes in this string

Definition at line 51 of file string_view.hpp.

◆ substr()

string_view cudf::string_view::substr ( size_type  start,
size_type  length 
) const
inline

Return a sub-string of this string. The original string and device memory must still be maintained for the lifetime of the returned instance.

Parameters
startCharacter position to start the sub-string.
lengthNumber of characters from start to include in the sub-string.
Returns
New instance pointing to a subset of the characters within this instance.

Definition at line 439 of file string_view.cuh.

Member Data Documentation

◆ npos

cudf::size_type const cudf::string_view::npos {-1}
inlinestatic

No-position value.

Used when specifying or returning an invalid or unknown character position value.

Definition at line 369 of file string_view.hpp.


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