libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
char.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
11#include <cstddef>
13
15
23class Char {
24 public:
26 Char() : _cp(0) {}
27
29 Char(char c) : _cp(static_cast<unsigned char>(c)) {}
30
32 explicit Char(char32_t cp) : _cp(cp) {}
33
35 char32_t codepoint() const { return _cp; }
36
38 bool isNull() const { return _cp == 0; }
39
41 bool isAscii() const { return _cp < 0x80; }
42
44 bool isAlpha() const;
45
47 bool isDigit() const;
48
50 bool isAlphaNumeric() const;
51
53 bool isSpace() const;
54
56 bool isUpper() const;
57
59 bool isLower() const;
60
62 bool isPrintable() const;
63
65 Char toUpper() const;
66
68 Char toLower() const;
69
71 size_t utf8ByteCount() const;
72
78 size_t toUtf8(char *buf) const;
79
86 static Char fromUtf8(const char *buf, size_t *bytesRead = nullptr);
87
88 bool operator==(Char o) const { return _cp == o._cp; }
89 bool operator==(char c) const { return _cp == static_cast<unsigned char>(c); }
90 bool operator!=(Char o) const { return _cp != o._cp; }
91 bool operator<(Char o) const { return _cp < o._cp; }
92 bool operator<=(Char o) const { return _cp <= o._cp; }
93 bool operator>(Char o) const { return _cp > o._cp; }
94 bool operator>=(Char o) const { return _cp >= o._cp; }
95
96 private:
97 char32_t _cp;
98};
99
Unicode-aware character class wrapping a single codepoint.
Definition char.h:23
bool isAlphaNumeric() const
Returns true if the character is alphanumeric.
Char(char32_t cp)
Constructs from a Unicode codepoint.
Definition char.h:32
bool isPrintable() const
Returns true if the character is printable.
bool isAscii() const
Returns true if the codepoint is in the ASCII range (< 0x80).
Definition char.h:41
Char toLower() const
Returns the lowercase version of this character.
bool isLower() const
Returns true if the character is lowercase.
Char(char c)
Constructs from a Latin1 byte (0x00–0xFF).
Definition char.h:29
Char()
Constructs a null character (U+0000).
Definition char.h:26
bool isNull() const
Returns true if this is the null character.
Definition char.h:38
bool isUpper() const
Returns true if the character is uppercase.
bool isSpace() const
Returns true if the character is whitespace.
Char toUpper() const
Returns the uppercase version of this character.
size_t toUtf8(char *buf) const
Encodes this codepoint as UTF-8 into the given buffer.
char32_t codepoint() const
Returns the Unicode codepoint.
Definition char.h:35
bool isDigit() const
Returns true if the character is a decimal digit.
size_t utf8ByteCount() const
Returns the number of bytes needed to encode this codepoint as UTF-8 (1–4).
bool isAlpha() const
Returns true if the character is alphabetic.
static Char fromUtf8(const char *buf, size_t *bytesRead=nullptr)
Decodes a single UTF-8 codepoint from the given buffer.
Dynamic array container wrapping std::vector.
Definition list.h:40
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19