Data Overview

From reSIProcate
Jump to navigation Jump to search

Data is resiprocate's string class. It is named Data rather than String for historical reasons. VOCAL had a reference counting version of Data. Resiprocate's version is not reference counting.

Data handles 8 bit character buffers.

Data is internally aware of its content length and is not guaranteed to be null terminated. Data::data() returns a raw pointer of type const char* to internal memory. Data::c_str() also returns a raw pointer of type const char* to internal memory, but will guarantee that the internal buffer is null terminated, by copying it if necessary. c_str() is generally necessary only when transitioning to another string representation, like char* or std::string.

Data::empty() returns true if the Data is empty, and false otherwise. Data::size() returns a size_type with the length of the data.

Data::lowercase() and Data::uppercase() convert the Data in place (modifies the object they are called on) to be be either all lower or all upper case. These calls also return a reference to the modified Data object.

Data::from() is a static function that can be used to create a Data from any object that defines the operator<<. For example, one can convert from a resiprocate URI to a data using:

Uri uri;
Data result = Data::from(uri);

Use this same technique to create a Data from any type defining operator<<.