21#ifndef GF_STRING_UTILS_H
22#define GF_STRING_UTILS_H
32#include "Portability.h"
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
49 GF_CORE_API std::string
niceNum(
float num,
float precision);
57 GF_CORE_API std::string
formatString(
const char *fmt, ...) GF_FORMAT(1, 2);
101 GF_CORE_API std::vector<std::string_view>
splitInWords(std::string_view str);
128 std::swap(current, other.current);
177 return current != other.current;
187 return current == other.current;
193 constexpr char32_t decode() const noexcept {
194 char32_t codepoint = 0;
195 uint8_t c = current[0];
197 if ((c & 0b10000000) == 0b00000000) {
198 codepoint = c & 0b01111111;
199 }
else if ((c & 0b11100000) == 0b11000000) {
200 codepoint = c & 0b00011111;
201 codepoint = (codepoint << 6) + (current[1] & 0b00111111);
202 }
else if ((c & 0b11110000) == 0b11100000) {
203 codepoint = c & 0b00001111;
204 codepoint = (codepoint << 6) + (current[1] & 0b00111111);
205 codepoint = (codepoint << 6) + (current[2] & 0b00111111);
207 assert((c & 0b11111000) == 0b11110000);
208 codepoint = c & 0b00000111;
209 codepoint = (codepoint << 6) + (current[1] & 0b00111111);
210 codepoint = (codepoint << 6) + (current[2] & 0b00111111);
211 codepoint = (codepoint << 6) + (current[3] & 0b00111111);
217 constexpr void step() noexcept {
218 uint8_t c = current[0];
220 if ((c & 0b10000000) == 0b00000000) {
222 }
else if ((c & 0b11100000) == 0b11000000) {
224 }
else if ((c & 0b11110000) == 0b11100000) {
227 assert((c & 0b11111000) == 0b11110000);
238 return Iterator{ ref.data() + ref.size() };
252#ifndef DOXYGEN_SHOULD_SKIP_THIS
GF_CORE_API std::string niceNum(float num, float precision)
Create a string representation of a floating point number.
GF_CORE_API std::vector< std::string_view > splitInWords(std::string_view str)
Split a string in multiples words.
GF_CORE_API std::string escapeString(std::string_view str)
Escape a string.
GF_CORE_API std::vector< std::string_view > splitInParagraphs(std::string_view str)
Split a string in multiples paragraphs.
GF_CORE_API std::string formatString(const char *fmt,...)
Format a string like printf.
The namespace for gf classes.
Iterator for a range of codepoints.
Definition: StringUtils.h:117
constexpr pointer operator->() const noexcept
Pointer operator.
Definition: StringUtils.h:145
value_type reference
Definition: StringUtils.h:121
char32_t value_type
Definition: StringUtils.h:119
constexpr bool operator!=(const Iterator &other) const noexcept
Inequality operator.
Definition: StringUtils.h:176
const char * current
Definition: StringUtils.h:190
std::ptrdiff_t difference_type
Definition: StringUtils.h:118
constexpr Iterator & operator++() noexcept
Increment operator (prefix)
Definition: StringUtils.h:154
std::forward_iterator_tag iterator_category
Definition: StringUtils.h:122
constexpr Iterator operator++(int) noexcept
Increment operator (postfix)
Definition: StringUtils.h:164
void swap(Iterator &other) noexcept
Swap the iterator with another iterator.
Definition: StringUtils.h:127
constexpr bool operator==(const Iterator &other) const noexcept
Equality operator.
Definition: StringUtils.h:186
constexpr reference operator*() const noexcept
Dereference operator.
Definition: StringUtils.h:136
value_type pointer
Definition: StringUtils.h:120
A range over a sequence of codepoints in UTF-8.
Definition: StringUtils.h:110
Iterator begin() const noexcept
Definition: StringUtils.h:233
constexpr CodepointRange codepoints(std::string_view ref)
Create a range over codepoints from a string.
Definition: StringUtils.h:248
std::string_view ref
Definition: StringUtils.h:111
Iterator end() const noexcept
Definition: StringUtils.h:237