description.cpp File Reference

#include <map>
#include <set>
#include <string>
#include "description.hh"
#include "Text.hh"
Include dependency graph for description.cpp:

Go to the source code of this file.

Functions

static string rmWhiteSpaces (const string &s)
 rmWhiteSpaces(): Remove the leading and trailing white spaces of a string (but not those in the middle of the string)
static void extractMetadata (const string &fulllabel, string &label, map< string, set< string > > &metadata)
 Extracts metdata from a label : 'vol [unit: dB]' -> 'vol' + metadata.
static string xmlize (const string &fullsrc)
 removes enclosing quotes and transforms '<', '>' and '&' characters

Function Documentation

static void extractMetadata ( const string &  fulllabel,
string &  label,
map< string, set< string > > &  metadata 
) [static]

Extracts metdata from a label : 'vol [unit: dB]' -> 'vol' + metadata.

Definition at line 30 of file description.cpp.

References rmWhiteSpaces().

Referenced by xmlize().

00031 {
00032     enum {kLabel, kEscape1, kEscape2, kEscape3, kKey, kValue};
00033     int state = kLabel; int deep = 0;
00034     string key, value;
00035 
00036     for (size_t i=0; i < fulllabel.size(); i++) {
00037         char c = fulllabel[i];
00038         switch (state) {
00039             case kLabel :
00040                 assert (deep == 0);
00041                 switch (c) {
00042                     case '\\' : state = kEscape1; break;
00043                     case '[' : state = kKey; deep++; break;
00044                     default : label += c;
00045                 }
00046                 break;
00047 
00048             case kEscape1 :
00049                 label += c;
00050                 state = kLabel;
00051                 break;
00052 
00053             case kEscape2 :
00054                 key += c;
00055                 state = kKey;
00056                 break;
00057 
00058             case kEscape3 :
00059                 value += c;
00060                 state = kValue;
00061                 break;
00062 
00063             case kKey :
00064                 assert (deep > 0);
00065                 switch (c) {
00066                     case '\\' :  state = kEscape2;
00067                                 break;
00068 
00069                     case '[' :  deep++;
00070                                 key += c;
00071                                 break;
00072 
00073                     case ':' :  if (deep == 1) {
00074                                     state = kValue;
00075                                 } else {
00076                                     key += c;
00077                                 }
00078                                 break;
00079                     case ']' :  deep--;
00080                                 if (deep < 1) {
00081                                     metadata[rmWhiteSpaces(key)].insert("");
00082                                     state = kLabel;
00083                                     key="";
00084                                     value="";
00085                                 } else {
00086                                     key += c;
00087                                 }
00088                                 break;
00089                     default :   key += c;
00090                 }
00091                 break;
00092 
00093             case kValue :
00094                 assert (deep > 0);
00095                 switch (c) {
00096                     case '\\' : state = kEscape3;
00097                                 break;
00098 
00099                     case '[' :  deep++;
00100                                 value += c;
00101                                 break;
00102 
00103                     case ']' :  deep--;
00104                                 if (deep < 1) {
00105                                     metadata[rmWhiteSpaces(key)].insert(rmWhiteSpaces(value));
00106                                     state = kLabel;
00107                                     key="";
00108                                     value="";
00109                                 } else {
00110                                     value += c;
00111                                 }
00112                                 break;
00113                     default :   value += c;
00114                 }
00115                 break;
00116 
00117             default :
00118                 cerr << "ERROR unrecognized state " << state << endl;
00119         }
00120     }
00121     label = rmWhiteSpaces(label);
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:

static string rmWhiteSpaces ( const string &  s  )  [static]

rmWhiteSpaces(): Remove the leading and trailing white spaces of a string (but not those in the middle of the string)

Definition at line 15 of file description.cpp.

Referenced by extractMetadata().

00016 {
00017     size_t i = s.find_first_not_of(" \t");
00018     size_t j = s.find_last_not_of(" \t");
00019 
00020     if ( (i != string::npos) & (j != string::npos) ) {
00021         return s.substr(i, 1+j-i);
00022     } else {
00023         return "";
00024     }
00025 }

Here is the caller graph for this function:

static string xmlize ( const string &  fullsrc  )  [static]

removes enclosing quotes and transforms '<', '>' and '&' characters

Definition at line 128 of file description.cpp.

References extractMetadata().

Referenced by Description::addGroup(), Description::addWidget(), and Description::print().

00129 {
00130     map<string, set<string> > metadata;
00131     string dst;
00132     string src;
00133 
00134     extractMetadata(fullsrc, src, metadata);
00135     
00136     for (size_t i=0; i<src.size(); i++) {
00137         if (src[i] == '"' & (i==0 | i==src.size()-1)) {
00138             // nothing to do just skip the quotes
00139         } else {
00140             switch (src[i]) {
00141                 case '<' : dst += "&lt;"; break;
00142                 case '>' : dst += "&gt;"; break;
00143                 case '&' : dst += "&amp;"; break;
00144                 default :  dst += src[i];
00145             }
00146         }
00147     }
00148     return dst;
00149 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated on Thu Jul 15 15:46:57 2010 for FAUST compiler by  doxygen 1.6.3