glibmm: Glib::UStringView Class Reference

glibmm 2.64.5

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Glib::UStringView Class Reference

Helper class to avoid unnecessary string copying in function calls. More...

`#include <glibmm/ustring.h>`

## Public Member Functions
| UStringView (const Glib::ustring& s)
| UStringView (const char* s)
const char* | c_str () const

## Detailed Description

Helper class to avoid unnecessary string copying in function calls.

A Glib::UStringView holds a const char pointer. It can be used as an argument type in a function that passes a const char pointer to a C function.

Unlike std::string_view, Glib::UStringView shall be used only for null-terminated strings.

Glib::ustring f1(Glib::UStringView s1, Glib::UStringView s2);
// can be used instead of
Glib::ustring f2(const Glib::ustring& s1, const Glib::ustring& s2);

The strings are not copied when f1() is called with string literals.

auto r1 = f1("string 1", "string 2");

To pass a std::string to a function taking a Glib::UStringView, you may have to use std::string::c_str().

std::string str = "non-UTF8 string";
Glib::ustring ustr = "UTF8 string";
auto r1 = f1(str.c_str(), ustr);

Since glibmm 2.64:

## Constructor & Destructor Documentation

Glib::UStringView::UStringView | ( | const Glib::ustring& | s | ) |
| inline

Glib::UStringView::UStringView | ( | const char * | s | ) |
| inline

## Member Function Documentation

const char* Glib::UStringView::c_str | ( |  | ) | const
| inline