KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
unicode.h
1/**
2 * @brief A lookup table for commonly used Unicode special characters.
3 */
4#ifndef UNICODE_H
5#define UNICODE_H
6
7#include <QMap>
8#include <Kanoop/kanoopcommon.h>
9
10/**
11 * @brief Provides QChar values for common Unicode special characters by name.
12 *
13 * Use the SpecialCharacter enumeration with specialCharacter() to retrieve
14 * the corresponding QChar, e.g. arrows, mathematical symbols, and typographic marks.
15 */
16class KANOOP_EXPORT Unicode
17{
18public:
19 /**
20 * @brief Enumeration of supported Unicode special characters.
21 */
23 {
24 ArrowDown, ///< Downward arrow (↓, U+2193)
25 ArrowDownToLeft, ///< Down-left arrow (↙, U+2199)
26 ArrowDownToRight, ///< Down-right arrow (↙, U+2199)
27 ArrowHorizontalBoth,///< Left-right arrow (↔, U+2194)
28 ArrowLeft, ///< Leftward arrow (←, U+2190)
29 ArrowRight, ///< Rightward arrow (→, U+2192)
30 ArrowUp, ///< Upward arrow (↑, U+2191)
31 ArrowUpToLeft, ///< Up-left arrow (↖, U+2196)
32 ArrowUpToRight, ///< Up-right arrow (↗, U+2197)
33 ArrowVerticalBoth, ///< Up-down arrow (↕, U+2195)
34 Bullet, ///< Middle dot / bullet (·, U+00B7)
35 Copyright, ///< Copyright sign (©, U+00A9)
36 Cubed, ///< Superscript three (³, U+00B3)
37 Degrees, ///< Degree sign (°, U+00B0)
38 Delta, ///< Greek capital Delta (Δ, U+0394)
39 EmDash, ///< Em dash (—, U+2014)
40 Micro, ///< Micro sign (µ, U+00B5)
41 MusicNote, ///< Beamed eighth notes (♫, U+266B)
42 OneHalf, ///< Vulgar fraction one half (½, U+00BD)
43 OneQuarter, ///< Vulgar fraction one quarter (¼, U+00BC)
44 Paragraph, ///< Pilcrow / paragraph sign (¶, U+00B6)
45 PlusOrMinus, ///< Plus-minus sign (±, U+00B1)
46 RightsReserved, ///< Registered sign (®, U+00AE)
47 Squared, ///< Superscript two (², U+00B2)
48 ThreeQuarters, ///< Vulgar fraction three quarters (¾, U+00BE)
49 };
50
51 /**
52 * @brief Return the QChar for a given special character identifier.
53 * @param c Special character to look up
54 * @return Corresponding QChar, or a null QChar if not found
55 */
56 static QChar specialCharacter(SpecialCharacter c) { return _SpecialCharacterMap.value(c, QChar()); }
57
58private:
59 class SpecialCharacterMap : public QMap<SpecialCharacter, QChar>
60 {
61 public:
62 SpecialCharacterMap()
63 {
64 insert(ArrowDown, QChar(0x2193));
65 insert(ArrowDownToLeft, QChar(0x2199));
66 insert(ArrowDownToRight, QChar(0x2199));
67 insert(ArrowHorizontalBoth, QChar(0x2194));
68 insert(ArrowLeft, QChar(0x2190));
69 insert(ArrowRight, QChar(0x2192));
70 insert(ArrowUp, QChar(0x2191));
71 insert(ArrowUpToLeft, QChar(0x2196));
72 insert(ArrowUpToRight, QChar(0x2197));
73 insert(ArrowVerticalBoth, QChar(0x2195));
74 insert(Bullet, QChar(0x00b7));
75 insert(Copyright, QChar(0x00a9));
76 insert(Cubed, QChar(0x00b3));
77 insert(Degrees, QChar(0x00b0));
78 insert(Delta, QChar(0x0394));
79 insert(EmDash, QChar(0x2014));
80 insert(Micro, QChar(0x00b5));
81 insert(MusicNote, QChar(0x266b));
82 insert(OneHalf, QChar(0x00bd));
83 insert(OneQuarter, QChar(0x00bc));
84 insert(Paragraph, QChar(0x00b6));
85 insert(PlusOrMinus, QChar(0x00b1));
86 insert(RightsReserved, QChar(0x00ae));
87 insert(Squared, QChar(0x00b2));
88 insert(ThreeQuarters, QChar(0x00be));
89 }
90 };
91 static const SpecialCharacterMap _SpecialCharacterMap;
92};
93
94#endif // UNICODE_H
A lookup table for commonly used Unicode special characters.
Definition unicode.h:17
static QChar specialCharacter(SpecialCharacter c)
Return the QChar for a given special character identifier.
Definition unicode.h:56
SpecialCharacter
Enumeration of supported Unicode special characters.
Definition unicode.h:23
@ PlusOrMinus
Plus-minus sign (±, U+00B1)
Definition unicode.h:45
@ OneHalf
Vulgar fraction one half (½, U+00BD)
Definition unicode.h:42
@ RightsReserved
Registered sign (®, U+00AE)
Definition unicode.h:46
@ OneQuarter
Vulgar fraction one quarter (¼, U+00BC)
Definition unicode.h:43
@ ArrowHorizontalBoth
Left-right arrow (↔, U+2194)
Definition unicode.h:27
@ ArrowDownToRight
Down-right arrow (↙, U+2199)
Definition unicode.h:26
@ ThreeQuarters
Vulgar fraction three quarters (¾, U+00BE)
Definition unicode.h:48
@ Paragraph
Pilcrow / paragraph sign (¶, U+00B6)
Definition unicode.h:44
@ ArrowVerticalBoth
Up-down arrow (↕, U+2195)
Definition unicode.h:33
@ Degrees
Degree sign (°, U+00B0)
Definition unicode.h:37
@ ArrowUpToRight
Up-right arrow (↗, U+2197)
Definition unicode.h:32
@ Cubed
Superscript three (³, U+00B3)
Definition unicode.h:36
@ Copyright
Copyright sign (©, U+00A9)
Definition unicode.h:35
@ ArrowLeft
Leftward arrow (←, U+2190)
Definition unicode.h:28
@ ArrowRight
Rightward arrow (→, U+2192)
Definition unicode.h:29
@ Delta
Greek capital Delta (Δ, U+0394)
Definition unicode.h:38
@ ArrowDownToLeft
Down-left arrow (↙, U+2199)
Definition unicode.h:25
@ Squared
Superscript two (², U+00B2)
Definition unicode.h:47
@ ArrowUp
Upward arrow (↑, U+2191)
Definition unicode.h:30
@ ArrowUpToLeft
Up-left arrow (↖, U+2196)
Definition unicode.h:31
@ EmDash
Em dash (—, U+2014)
Definition unicode.h:39
@ MusicNote
Beamed eighth notes (♫, U+266B)
Definition unicode.h:41
@ Micro
Micro sign (µ, U+00B5)
Definition unicode.h:40
@ Bullet
Middle dot / bullet (·, U+00B7)
Definition unicode.h:34
@ ArrowDown
Downward arrow (↓, U+2193)
Definition unicode.h:24