AString#
Represents a UTF-8 string.
Header: | #include <AUI/Common/AString.h> |
CMake: | aui_link(my_target PUBLIC aui::core) |
Detailed Description#
AString stores a sequence of 8-bit integers representing UTF-8 code units. Each Unicode character (codepoint) is encoded using 1-4 consecutive code units, supporting the full Unicode standard.
Unicode provides comprehensive support for international writing systems and symbols.
Examples#
examples/app/minesweeper/src/NewGameWindow.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
void NewGameWindow::updateDifficultyLabel() {
mMines->setMax(mWidth->getValue() * mHeight->getValue() * 3 / 4);
int difficulty = mWidth->getValue() * mHeight->getValue() / glm::max(mMines->getValue(), int64_t(1));
AString text = "Difficulty: ";
switch (difficulty) {
default:
case 0:
case 1:
text += "very low";
examples/ui/views/src/DemoListModel.h
Views Example - All-in-one views building example.
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
auto dateTextField(DateTextFieldState& state) {
return _new<ATextField>() AUI_LET {
AObject::biConnect(
state.parsed.biProjected(aui::lambda_overloaded {
[](const AOptional<system_clock::time_point>& v) -> AString {
if (!v) {
return "";
}
return formatDate(*v);
},
examples/7guis/cells/tests/FormulaTests.cpp
7GUIs Cells - Spreadsheet processor (Excel).
EXPECT_EQ(std::get<double>(formula::evaluate(mSpreadsheet, "0")), 0.0);
}
TEST_F(Cells_Formula, String) {
EXPECT_EQ(std::get<AString>(formula::evaluate(mSpreadsheet, "test")), "test");
}
TEST_F(Cells_Formula, EConstant) {
EXPECT_DOUBLE_EQ(std::get<double>(formula::evaluate(mSpreadsheet, "=1")), 1.0);
}
examples/app/fractal/src/JumpToCoordsWindow.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
auto im = _new<ATextField>();
auto scale = _new<ATextField>();
auto pos = fractalView->getPlotPosition();
re->setText(AString::number(pos.x));
im->setText(AString::number(pos.y));
scale->setText(AString::number(fractalView->getPlotScale()));
setContents(Vertical {
_form({
examples/app/minesweeper/src/CellView.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
examples/ui/views/src/DemoListModel.cpp
Views Example - All-in-one views building example.
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
namespace {
_<AView> profilePhoto(const _<Contact>& contact) {
return Centered {
Label {} & contact->displayName.readProjected([](const AString& s) {
return s.empty() ? "?" : AString(1, s.first()).uppercase();
}) AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
} AUI_WITH_STYLE {
FixedSize { 64_dp },
BorderRadius { 32_dp },
examples/ui/contacts/src/view/ContactDetailsView.h
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
examples/ui/contacts/src/model/Contact.h
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
examples/7guis/cells/src/Cell.cpp
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Functions.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Tokens.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/AST.cpp
7GUIs Cells - Spreadsheet processor (Excel).
formula::Value evaluate(const Spreadsheet& ctx) override { return value; }
};
struct StringLiteralNode : INode {
AString value;
explicit StringLiteralNode(AString value) : value(std::move(value)) {}
~StringLiteralNode() override = default;
formula::Value evaluate(const Spreadsheet& ctx) override { return value; }
};
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Functions.cpp
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/counter/src/main.cpp
7GUIs Counter - Simple counter.
CounterWindow(): AWindow("AUI - 7GUIs - Counter", 200_dp, 100_dp) {
setContents(Centered {
Horizontal {
_new<ATextField>() AUI_LET {
AObject::connect(mCounter.readProjected(AString::number<int>), it->text());
it->setEditable(false);
},
Button { "Count" }.connect(&AView::clicked, [&] { mCounter += 1; }),
},
});
Public Methods#
bytes#
Returns a view of the raw UTF-8 encoded byte data.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
Returns a view of the raw UTF-8 encoded byte data.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
encode#
AByteBuffer AString::encode(AStringEncoding encoding)
Encodes the string into a null-terminated byte buffer using the specified encoding.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
length#
Returns the number of Unicode characters in the string
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
resizeToNullTerminator#
Resizes the string to the length of its null-terminated content while preserving capacity.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
sizeBytes#
Returns the number of bytes in the UTF-8 encoded string
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toBool#
Converts the string to boolean value.
- Returns
- If the string equals to "true", true returned, false otherwise.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toDouble#
AOptional<double> AString::toDouble()
Converts the string to a double number.
- Returns
- The string converted to a double number. If conversion to int is not possible, nullopt is returned.
Examples#
examples/7guis/cells/src/Formula.cpp
7GUIs Cells - Spreadsheet processor (Excel).
formula::Precompiled formula::precompile(const AString& expression) {
if (expression.empty()) {
return [](const Spreadsheet&) { return std::nullopt; };
}
if (auto d = expression.toDouble()) {
return [d = *d](const Spreadsheet&) { return d; };
}
if (!expression.startsWith('=')) {
return [stringConstant = expression](const Spreadsheet&) { return stringConstant; };
}
toFloat#
AOptional<float> AString::toFloat()
Converts the string to a float number.
- Returns
- The string converted to a float number. If conversion to int is not possible, nullopt is returned.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toInt#
AOptional<int32_t> AString::toInt()
Converts the string to int value.
- Returns
- The string converted to an integer value using base 10. If the string starts with 0x or 0X, the base 16 used. If conversion to int is not possible, nullopt is returned.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toLong#
AOptional<int64_t> AString::toLong()
Converts the string to long value.
- Returns
- The string converted to an integer value using base 10. If the string starts with 0x or 0X, the base 16 used. If conversion to long is not possible, nullopt is returned.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toNumber#
AOptional<int> AString::toNumber(aui::ranged_number<int, 2, 36> base)
Returns the string converted to an int using base. Returns std::nullopt if the conversion fails.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toStdString#
Compatibility method. Guarantees std::string with UTF-8
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
}
return formatDate(*v);
},
[](const AString& s) -> AOptional<system_clock::time_point> {
auto std = s.toStdString();
auto match = REGEX_DATE.match(std);
if (!match) {
return std::nullopt;
}
year_month_day ymd(
examples/app/fractal/src/JumpToCoordsWindow.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
_new<AButton>("Jump").connect(
&AButton::clicked, this,
[&, fractalView, re, im, scale]() {
try {
auto dRe = std::stod((*re->text()).toStdString());
auto dIm = -std::stod((*re->text()).toStdString());
auto dScale = std::stod((*re->text()).toStdString());
fractalView->setPlotPositionAndScale(glm::dvec2 { dRe, dIm }, dScale);
close();
} catch (...) {
Compatibility method. Guarantees std::string with UTF-8
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
}
return formatDate(*v);
},
[](const AString& s) -> AOptional<system_clock::time_point> {
auto std = s.toStdString();
auto match = REGEX_DATE.match(std);
if (!match) {
return std::nullopt;
}
year_month_day ymd(
examples/app/fractal/src/JumpToCoordsWindow.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
_new<AButton>("Jump").connect(
&AButton::clicked, this,
[&, fractalView, re, im, scale]() {
try {
auto dRe = std::stod((*re->text()).toStdString());
auto dIm = -std::stod((*re->text()).toStdString());
auto dScale = std::stod((*re->text()).toStdString());
fractalView->setPlotPositionAndScale(glm::dvec2 { dRe, dIm }, dScale);
close();
} catch (...) {
toUInt#
AOptional<uint32_t> AString::toUInt()
Converts the string to unsigned int value.
- Returns
- The string converted to an integer value using base 10. If the string starts with 0x or 0X, the base 16 used. If conversion to unsigned int is not possible, exception is thrown.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toULong#
AOptional<uint64_t> AString::toULong()
Converts the string to unsigned long value.
- Returns
- The string converted to an integer value using base 10. If the string starts with 0x or 0X, the base 16 used. If conversion to unsigned long is not possible, exception is thrown.
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toUtf16#
Encodes the UTF-8 string into a UTF-16 string
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);
toUtf32#
Encodes the UTF-8 string into a UTF-32 string
Examples#
examples/ui/contacts/src/main.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
mSelectedContact = nullptr;
}
_<AView> indexedList() {
return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
}), AVerticalLayout) {
auto firstContact = *ranges::begin(group);
auto firstLetter = groupLetter(firstContact->displayName);
ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);