My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mnemo.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  mnemo.cpp
3  -----------
4  begin : Sat Jun 11 2005
5  copyright : (C) 2005 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "mnemo.h"
19 
20 struct tSpecialChar {
21  char Mnemonic[16];
22  unsigned short Unicode;
23 };
24 
25 
27  {"alpha", 0x03B1}, {"beta", 0x03B2}, {"gamma", 0x03B3},
28  {"delta", 0x03B4}, {"epsilon", 0x03B5}, {"zeta", 0x03B6},
29  {"eta", 0x03B7}, {"theta", 0x03B8}, {"iota", 0x03B9},
30  {"kappa", 0x03BA}, {"lambda", 0x03BB}, {"mu", 0x03BC},
31  {"nu", 0x03BD}, {"xi", 0x03BE}, {"pi", 0x03C0},
32  {"rho", 0x03C1}, {"sigma", 0x03C3}, {"tau", 0x03C4},
33  {"upsilon", 0x03C5}, {"phi", 0x03C6}, {"chi", 0x03C7},
34  {"psi", 0x03C8}, {"omega", 0x03C9},
35 
36  {"varpi", 0x03D6}, {"varrho", 0x03F1},
37 
38  {"Gamma", 0x0393}, {"Delta", 0x0394}, {"Theta", 0x0398},
39  {"Lambda", 0x039B}, {"Xi", 0x039E}, {"Pi", 0x03A0},
40  {"Sigma", 0x03A3}, {"Upsilon", 0x03A5}, {"Phi", 0x03A6},
41  {"Psi", 0x03A8}, {"Omega", 0x03A9},
42 
43  {"textmu", 0x00B5}, {"cdot", 0x00B7}, {"times", 0x00D7},
44  {"pm", 0x00B1}, {"mp", 0x2213}, {"partial", 0x2202},
45  {"nabla", 0x2207}, {"infty", 0x221E}, {"int", 0x222B},
46  {"approx", 0x2248}, {"neq", 0x2260}, {"in", 0x220A},
47  {"leq", 0x2264}, {"geq", 0x2265}, {"sim", 0x223C},
48  {"propto", 0x221D}, {"onehalf", 0x00BD}, {"onequarter", 0x00BC},
49  {"twosuperior", 0x00B2}, {"threesuperior", 0x00B3},
50  {"diameter", 0x00F8}, {"ohm", 0x03A9},
51 
52  {"", 0} // end mark
53 };
54 
55 
56 // This function replaces the LaTeX tags for special characters
57 // into its unicode value.
58 void encode_String(const QString& Input, QString& Output)
59 {
60  int Begin = 0, End = 0;
61  struct tSpecialChar *p;
62 
63  Output = "";
64  while((Begin=Input.find('\\', Begin)) >= 0) {
65  Output += Input.mid(End, Begin - End);
66  End = Begin++;
67 
68  p = SpecialChars;
69  while(p->Unicode != 0) // test all special characters
70  if(Input.mid(Begin).startsWith(p->Mnemonic)) {
71  Output += QChar(p->Unicode);
72  End = Begin + strlen(p->Mnemonic);
73  break;
74  }
75  else p++;
76  }
77  Output += Input.mid(End);
78 }
79 
80 // This function replaces the unicode of special characters
81 // by its LaTeX tags.
82 void decode_String(QString& Output)
83 {
84  struct tSpecialChar *p = SpecialChars;
85  while(p->Unicode != 0) { // test all special characters
86  Output.replace(QChar(p->Unicode), "\\"+QString(p->Mnemonic));
87  p++;
88  }
89 }