Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/mnemo.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                mnemo.cpp
00003                               -----------
00004     begin                : Sat Jun 11 2005
00005     copyright            : (C) 2005 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "mnemo.h"
00019 #include <QString>
00020 
00021 struct tSpecialChar {
00022      char Mnemonic[16];
00023      unsigned short Unicode;
00024 };
00025 
00026 
00027 struct tSpecialChar SpecialChars[] = {
00028      {"alpha", 0x03B1}, {"beta", 0x03B2}, {"gamma", 0x03B3},
00029      {"delta", 0x03B4}, {"epsilon", 0x03B5}, {"zeta", 0x03B6},
00030      {"eta", 0x03B7}, {"theta", 0x03B8}, {"iota", 0x03B9},
00031      {"kappa", 0x03BA}, {"lambda", 0x03BB}, {"mu", 0x03BC},
00032      {"nu", 0x03BD}, {"xi", 0x03BE}, {"pi", 0x03C0},
00033      {"rho", 0x03C1}, {"sigma", 0x03C3}, {"tau", 0x03C4},
00034      {"upsilon", 0x03C5}, {"phi", 0x03C6}, {"chi", 0x03C7},
00035      {"psi", 0x03C8}, {"omega", 0x03C9},
00036 
00037      {"varpi", 0x03D6}, {"varrho", 0x03F1},
00038 
00039      {"Gamma", 0x0393}, {"Delta", 0x0394}, {"Theta", 0x0398},
00040      {"Lambda", 0x039B}, {"Xi", 0x039E}, {"Pi", 0x03A0},
00041      {"Sigma", 0x03A3}, {"Upsilon", 0x03A5}, {"Phi", 0x03A6},
00042      {"Psi", 0x03A8}, {"Omega", 0x03A9},
00043 
00044      {"textmu", 0x00B5}, {"cdot", 0x00B7}, {"times", 0x00D7},
00045      {"pm", 0x00B1}, {"mp", 0x2213}, {"partial", 0x2202},
00046      {"nabla", 0x2207}, {"infty", 0x221E}, {"int", 0x222B},
00047      {"approx", 0x2248}, {"neq", 0x2260}, {"in", 0x220A},
00048      {"leq", 0x2264}, {"geq", 0x2265}, {"sim", 0x223C},
00049      {"propto", 0x221D}, {"onehalf", 0x00BD}, {"onequarter", 0x00BC},
00050      {"twosuperior", 0x00B2}, {"threesuperior", 0x00B3},
00051      {"diameter", 0x00F8}, {"ohm", 0x03A9},
00052 
00053      {"", 0}  // end mark
00054 };
00055 
00056 
00057 // This function replaces the LaTeX tags for special characters
00058 // into its unicode value.
00059 void encode_String(const QString& Input, QString& Output)
00060 {
00061   int Begin = 0, End = 0;
00062   struct tSpecialChar *p;
00063 
00064   Output = "";
00065   while((Begin=Input.indexOf('\\', Begin)) >= 0) {
00066     Output += Input.mid(End, Begin - End);
00067     End = Begin++;
00068 
00069     p = SpecialChars;
00070     while(p->Unicode != 0)   // test all special characters
00071       if(Input.mid(Begin).startsWith(p->Mnemonic)) {
00072         Output += QChar(p->Unicode);
00073         End = Begin + strlen(p->Mnemonic);
00074         break;
00075       }
00076       else p++;
00077   }
00078   Output += Input.mid(End);
00079 }
00080 
00081 // This function replaces the unicode of special characters
00082 // by its LaTeX tags.
00083 void decode_String(QString& Output)
00084 {
00085   struct tSpecialChar *p = SpecialChars;
00086   while(p->Unicode != 0) {   // test all special characters
00087     Output.replace(QChar(p->Unicode), "\\"+QString(p->Mnemonic));
00088     p++;
00089   }
00090 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines