-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathmnemo.cpp
117 lines (108 loc) · 3.28 KB
/
mnemo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
mnemo.cpp
-----------
begin : Sat Jun 11 2005
copyright : (C) 2005 by Michael Margraf
email : michael.margraf@alumni.tu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "mnemo.h"
#include <QString>
#include <array>
typedef struct {
const char *Mnemonic;
unsigned short Unicode;
} tSpecialChar;
std::array<tSpecialChar, 59> SpecialChars{{
{"alpha", 0x03B1},
{"beta", 0x03B2},
{"gamma", 0x03B3},
{"delta", 0x03B4},
{"epsilon", 0x03B5},
{"zeta", 0x03B6},
{"eta", 0x03B7},
{"theta", 0x03B8},
{"iota", 0x03B9},
{"kappa", 0x03BA},
{"lambda", 0x03BB},
{"mu", 0x03BC},
{"nu", 0x03BD},
{"xi", 0x03BE},
{"pi", 0x03C0},
{"rho", 0x03C1},
{"sigma", 0x03C3},
{"tau", 0x03C4},
{"upsilon", 0x03C5},
{"phi", 0x03C6},
{"chi", 0x03C7},
{"psi", 0x03C8},
{"omega", 0x03C9},
{"varpi", 0x03D6},
{"varrho", 0x03F1},
{"Gamma", 0x0393},
{"Delta", 0x0394},
{"Theta", 0x0398},
{"Lambda", 0x039B},
{"Xi", 0x039E},
{"Pi", 0x03A0},
{"Sigma", 0x03A3},
{"Upsilon", 0x03A5},
{"Phi", 0x03A6},
{"Psi", 0x03A8},
{"Omega", 0x03A9},
{"textmu", 0x00B5},
{"cdot", 0x00B7},
{"times", 0x00D7},
{"pm", 0x00B1},
{"mp", 0x2213},
{"partial", 0x2202},
{"nabla", 0x2207},
{"infty", 0x221E},
{"int", 0x222B},
{"approx", 0x2248},
{"neq", 0x2260},
{"in", 0x220A},
{"leq", 0x2264},
{"geq", 0x2265},
{"sim", 0x223C},
{"propto", 0x221D},
{"onehalf", 0x00BD},
{"onequarter", 0x00BC},
{"twosuperior", 0x00B2},
{"threesuperior", 0x00B3},
{"diameter", 0x00F8},
{"ohm", 0x03A9},
{"", 0} // end mark
}};
// This function replaces the LaTeX tags for special characters
// into its unicode value.
void encode_String(const QString &Input, QString &Output) {
int Begin = 0, End = 0;
Output = "";
while ((Begin = Input.indexOf('\\', Begin)) >= 0) {
Output += Input.mid(End, Begin - End);
End = Begin++;
for (const auto &sc : SpecialChars) { // test all special characters
if (Input.mid(Begin).startsWith(sc.Mnemonic)) {
Output += QChar(sc.Unicode);
End = Begin + strlen(sc.Mnemonic);
break;
}
}
}
Output += Input.mid(End);
}
// This function replaces the unicode of special characters
// by its LaTeX tags.
void decode_String(QString &Output) {
for (const auto &sc : SpecialChars) {
Output.replace(QChar(sc.Unicode), "\\" + QString(sc.Mnemonic));
}
}