Программа преобразования исходного текста на С++ в RTF-файл

Автор работы: Пользователь скрыл имя, 04 Июня 2012 в 12:17, курсовая работа

Краткое описание

Целью курсовой работы является разработка программного продукта, реализующего преобразование Си текста в RTF-файл. Для реализации поставленной цели были определены следующие задачи:
1. Разобрать структуру RTF-файла.
2. Реализовать алгоритм чтения файла.
3. Реализовать алгоритм преобразования Си в RTF.
4. Реализовать запись полученных данных в файл.

Содержание

Введение 3
I.Теоретический раздел 4
1.1 RTF- Rich Text Format 4
II. Технологический раздел 11
2.1. Стандартные заголовочные файлы. 11
2.2.Стандартные типы данных. 13
2.3. Описание собственных функций 14
Заключение 16
Литература 17
Приложение 18

Вложенные файлы: 1 файл

Документ Microsoft Word.doc

— 235.00 Кб (Скачать файл)

                                                                                             

                                                                                                                                                                        if((text[position]=='*')  &&  (text[position+1]=='/')){

                                                                      text.insert(position+2,cm21);

                                                                      position+=3;

                                                                      k+=3;

                                                                                                                                                                        }

                                                                                                                                                                        if((text[position]=='/') && (text[position+1]=='/')){

                                                                       text.insert(position,cm12);

                                                                       position+=9;

                                                                       k+=9;

                                                                                                     while(text[position]!='\r' && text[position+1]!='\n'){

                                                                                                     position++;

                                                                                                     }

                                                                       text.insert(position,cm2);

                                                                       position+=3;

                                                                       k+=3;

                           

                                                }

                                             

                                                                                                                position++; 

                                                                                                  } 

                          return text; 

}

string colorLib(string &text){

                       string libbegin("\{\\cf5 #");

                       string libend("\}");

                       int k=text.length();

                       int position=0;

                           while(position!=k){

                                              if(text[position]=='#'){

                                                                      text.replace(position,1,libbegin);

                                                                      position+=6;

                                                                      k+=6;

                                                                      while(text[position]!='\r' && text[position+1]!='\n'){

                                                                                                                          position++;

                                                                       }

                                                                       text.insert(position,libend);

                                                                       position++;

                                                                       k++;

                                              }                                             

                                             

                          position++; 

                          }

                          return text; 

                      

}

string colorIF(string &text,string &base){

       string str;

       string IF("if");

       string afterIF("\{\\cf1 if\}");

       int position=0;

           position=text.find(IF);

           while(position!=-1){

                               str=text.substr(0,position+2);

                               str.replace(position,2,afterIF);

                               text=text.substr(position+2);

                               base+=str;

                               return colorIF(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorELSE(string &text,string &base){

       string str;

       string ELSE("else");

       string afterELSE("\{\\cf1\\b else\}");

       int position=0;

           position=text.find(ELSE);

           while(position!=-1){

                               str=text.substr(0,position+4);

                               str.replace(position,4,afterELSE);

                               text=text.substr(position+4);

                               base+=str;

                               return colorELSE(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorFOR(string &text,string &base){

       string str;

       string FOR("for");

       string afterFOR("\{\\cf1\\b for\}");

       int position=0;

           position=text.find(FOR);

           while(position!=-1){

                               str=text.substr(0,position+3);

                               str.replace(position,3,afterFOR);

                               text=text.substr(position+3);

                               base+=str;

                               return colorFOR(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorDO(string &text,string &base){

       string str;

       string DO("do");

       string afterDO("\{\\cf1\\b do\}");

       int position=0;

           position=text.find(DO);

           while(position!=-1){

                               str=text.substr(0,position+2);

                               str.replace(position,2,afterDO);

                               text=text.substr(position+2);

                               base+=str;

                               return colorDO(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorWHILE(string &text,string &base){

       string str;

       string WHILE("while");

       string afterWHILE("\{\\cf1\\b while\}");

       int position=0;

           position=text.find(WHILE);

           while(position!=-1){

                               str=text.substr(0,position+5);

                               str.replace(position,5,afterWHILE);

                               text=text.substr(position+5);

                               base+=str;

                               return colorWHILE(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorSWITCH(string &text,string &base){

       string str;

       string SWITCH("switch");

       string afterSWITCH("\{\\cf1\\b switch\}");

       int position=0;

           position=text.find(SWITCH);

           while(position!=-1){

                               str=text.substr(0,position+6);

                               str.replace(position,6,afterSWITCH);

                               text=text.substr(position+6);

                               base+=str;

                               return colorSWITCH(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorCASE(string &text,string &base){

       string str;

       string CASE("case");

       string afterCASE("\{\\cf1\\b case\}");

       int position=0;

           position=text.find(CASE);

           while(position!=-1){

                               str=text.substr(0,position+4);

                               str.replace(position,4,afterCASE);

                               text=text.substr(position+4);

                               base+=str;

                               return colorCASE(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorDEFAULT(string &text,string &base){

       string str;

       string DEFAULT("default");

       string afterDEFAULT("\{\\cf1\\b default\}");

       int position=0;

            position=text.find(DEFAULT);

            while(position!=-1){

                               str=text.substr(0,position+7);

                               str.replace(position,7,afterDEFAULT);

                               text=text.substr(position+7);

                               base+=str;

                               return colorDEFAULT(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorRETURN(string &text,string &base){

        string str;

        string RETURN("return");

        string afterRETURN("\{\\cf1\\b return\}");

        int position=0;

            position=text.find(RETURN);

            while(position!=-1){

                               str=text.substr(0,position+6);

                               str.replace(position,6,afterRETURN);

                               text=text.substr(position+6);

                               base+=str;

                               return colorRETURN(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

}

string colorCONTINUE(string &text,string &base){

       string str;

        string CONTINUE("continue");

        string afterCONTINUE("\{\\cf1\\b continue\}");

        int position=0;

            position=text.find(CONTINUE);

            while(position!=-1){

                               str=text.substr(0,position+8);

                               str.replace(position,8,afterCONTINUE);

                               text=text.substr(position+8);

                               base+=str;

                               return colorCONTINUE(text,base);

           }

           text=base+text;

           base="";    

                            

return text;                            

Информация о работе Программа преобразования исходного текста на С++ в RTF-файл