00001 /**** 00002 Hierarchical Data Objects 00003 Copyright (C) 2005-2010 Werner Van Belle 00004 http://flow.yellowcouch.org/data/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 ****/ 00020 #ifndef __loaded__data_string_cpp__ 00021 #define __loaded__data_string_cpp__ 00022 using namespace std; 00023 #line 1 "data-string.c++" 00024 #include "data-string.h" 00025 #include "data-visitor.h" 00026 00027 //--------------------------------------------------------------- 00028 // String 00029 //--------------------------------------------------------------- 00030 // strings start with a ' and end with a '. 00031 // if a ' is to be placed in a string it should be done as '' 00032 // newlines in a string are printed and then at an appropriate 00033 // column a > is placed. When String prints a string it can 00034 // insert appropriate newlines by printing a newline and starting 00035 // the next line with a |. 00036 void frontup(char* target, char * source) 00037 { 00038 memmove(target,source,strlen(source)+1); 00039 } 00040 00041 // When reading a string all data is read and afterward filtered out. 00042 // '' is replaced with ' 00043 // \n\ *| is removed from the string. 00044 // \n\ *> is replaced with \n 00045 String String::parse(const char *i) 00046 { 00047 assert(i); 00048 char * final = strdup(i); 00049 char * cur = final; 00050 while(*cur) 00051 { 00052 if (cur[0]=='\'' && cur[1]=='\'') 00053 { 00054 frontup(cur,cur+1); 00055 cur++; 00056 } 00057 else if (*cur=='\n') 00058 { 00059 char * end=cur; 00060 while(*end && !(*end=='|' || *end=='>')) 00061 end++; 00062 assert(*end); 00063 if (*end=='|') 00064 frontup(cur,end+1); 00065 else if (*end=='>') 00066 { 00067 frontup(cur+1,end+1); 00068 cur++; 00069 } 00070 } 00071 else 00072 cur++; 00073 } 00074 return String(QString::fromUtf8(final)); 00075 } 00076 00077 void String::visit(DataVisitor &v) 00078 { 00079 v.visit(*this); 00080 } 00081 #endif // __loaded__data_string_cpp__