Classes | Public Member Functions | Static Public Member Functions | 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

CUDA_HOST_DEVICE_CALLABLE size_type size_bytes () const
 Return the number of bytes in this string.
 
CUDA_DEVICE_CALLABLE size_type length () const
 Return the number of characters in this string.
 
CUDA_HOST_DEVICE_CALLABLE const char * data () const
 Return a pointer to the internal device array.
 
CUDA_HOST_DEVICE_CALLABLE bool empty () const
 Return true if string has no characters.
 
CUDA_DEVICE_CALLABLE const_iterator begin () const
 Return new iterator pointing to the beginning of this string.
 
CUDA_DEVICE_CALLABLE const_iterator end () const
 Return new iterator pointing past the end of this string.
 
CUDA_DEVICE_CALLABLE char_utf8 operator[] (size_type pos) const
 Return single UTF-8 character at the given character position. More...
 
CUDA_DEVICE_CALLABLE size_type byte_offset (size_type pos) const
 Return the byte offset from data() for a given character position. More...
 
CUDA_DEVICE_CALLABLE int compare (const string_view &str) const
 Comparing target string with this string. Each character is compared as a UTF-8 code-point value. More...
 
CUDA_DEVICE_CALLABLE int compare (const char *str, size_type bytes) const
 Comparing target string with this string. Each character is compared as a UTF-8 code-point value. More...
 
CUDA_DEVICE_CALLABLE bool operator== (const string_view &rhs) const
 Returns true if rhs matches this string exactly.
 
CUDA_DEVICE_CALLABLE bool operator!= (const string_view &rhs) const
 Returns true if rhs does not match this string.
 
CUDA_DEVICE_CALLABLE bool operator< (const string_view &rhs) const
 Returns true if this string is ordered before rhs.
 
CUDA_DEVICE_CALLABLE bool operator> (const string_view &rhs) const
 Returns true if rhs is ordered before this string.
 
CUDA_DEVICE_CALLABLE bool operator<= (const string_view &rhs) const
 Returns true if this string matches or is ordered before rhs.
 
CUDA_DEVICE_CALLABLE bool operator>= (const string_view &rhs) const
 Returns true if rhs matches or is ordered before this string.
 
CUDA_DEVICE_CALLABLE size_type find (const string_view &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...
 
CUDA_DEVICE_CALLABLE size_type find (const char *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...
 
CUDA_DEVICE_CALLABLE 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...
 
CUDA_DEVICE_CALLABLE size_type rfind (const string_view &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...
 
CUDA_DEVICE_CALLABLE size_type rfind (const char *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...
 
CUDA_DEVICE_CALLABLE 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...
 
CUDA_DEVICE_CALLABLE 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...
 
CUDA_HOST_DEVICE_CALLABLE string_view ()
 Default constructor represents an empty string.
 
CUDA_HOST_DEVICE_CALLABLE string_view (const char *data, size_type bytes)
 Create instance from existing device char array. More...
 
 string_view (const string_view &)=default
 
 string_view (string_view &&)=default
 
string_viewoperator= (const string_view &)=default
 
string_viewoperator= (string_view &&)=default
 

Static Public Member Functions

static CUDA_HOST_DEVICE_CALLABLE string_view min ()
 Return minimum value associated with the string type. More...
 
static CUDA_HOST_DEVICE_CALLABLE string_view max ()
 Return maximum value associated with the string type. 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 63 of file string_view.hpp.

Constructor & Destructor Documentation

◆ string_view()

CUDA_HOST_DEVICE_CALLABLE cudf::string_view::string_view ( const char *  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 325 of file string_view.hpp.

Member Function Documentation

◆ byte_offset()

__device__ 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

Definition at line 249 of file string_view.cuh.

◆ compare() [1/2]

__device__ int cudf::string_view::compare ( const char *  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 268 of file string_view.cuh.

◆ compare() [2/2]

__device__ int cudf::string_view::compare ( const string_view 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 263 of file string_view.cuh.

◆ find() [1/3]

__device__ 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
-1 if arg string is not found in this string.

Definition at line 351 of file string_view.cuh.

◆ find() [2/3]

__device__ size_type cudf::string_view::find ( const char *  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
-1 if arg string is not found in this string.

Definition at line 323 of file string_view.cuh.

◆ find() [3/3]

__device__ size_type cudf::string_view::find ( const string_view 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
-1 if str is not found in this string.

Definition at line 316 of file string_view.cuh.

◆ max()

CUDA_HOST_DEVICE_CALLABLE string_view cudf::string_view::max ( )
static

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 80 of file string_view.cuh.

◆ min()

CUDA_HOST_DEVICE_CALLABLE string_view cudf::string_view::min ( )
static

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 69 of file string_view.cuh.

◆ operator[]()

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

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

Parameters
posCharacter position

Definition at line 240 of file string_view.cuh.

◆ rfind() [1/3]

__device__ 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
-1 if arg string is not found in this string.

Definition at line 392 of file string_view.cuh.

◆ rfind() [2/3]

__device__ size_type cudf::string_view::rfind ( const char *  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
-1 if arg string is not found in this string.

Definition at line 365 of file string_view.cuh.

◆ rfind() [3/3]

__device__ size_type cudf::string_view::rfind ( const string_view 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
-1 if arg string is not found in this string.

Definition at line 358 of file string_view.cuh.

◆ substr()

__device__ 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 400 of file string_view.cuh.


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