text.h Source File

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

text.h
Go to the documentation of this file.

    00001 /**********************************************************************
    00002 text.h - Declaration and Implementation of OBText
    00003
    00004 Copyright (C) 2008 by Chris Morley
    00005
    00006 This file is part of the Open Babel project.
    00007 For more information, see <http://openbabel.org/>
    00008
    00009 This program is free software; you can redistribute it and/or modify
    00010 it under the terms of the GNU General Public License as published by
    00011 the Free Software Foundation version 2 of the License.
    00012
    00013 This program is distributed in the hope that it will be useful,
    00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00016 GNU General Public License for more details.
    00017 ***********************************************************************/
    00018
    00019 #ifndef OB_TEXT_H
    00020 #define OB_TEXT_H
    00021
    00022 #include <openbabel/babelconfig.h>
    00023 #include <openbabel/base.h>
    00024
    00025 namespace OpenBabel
    00026 {
    00029 class OBText : public OBBase
    00030 {
    00031 private:
    00032   std::string txt;
    00033 public:
    00034   //Constructors
    00035   OBText(){}
    00036   OBText(const std::string& text) :txt(text) {}
    00037
    00039   std::string GetText()const { return txt; }
    00040
    00068   std::string GetText(std::string::size_type& pos, bool ToInsertOnly=false) const
    00069   {
    00070     std::string::size_type oldpos = pos;
    00071     std::string::size_type newpos = txt.find("OPENBABEL_INSERT", pos);
    00072     if(newpos== std::string::npos)//not found: return rest of txt
    00073     {
    00074       if(ToInsertOnly)
    00075         return("");
    00076       pos = 0;
    00077       return txt.substr(oldpos);
    00078     }
    00079
    00080     newpos = txt.rfind('\n', newpos); //to end of previous line
    00081     pos = txt.find("\n", newpos+1)+1; //to past end of line, or 0
    00082     return txt.substr(oldpos, newpos-oldpos);
    00083   }
    00084
    00085   void SetText(const std::string& text){ txt = text; }
    00086 };
    00087
    00088 }//namespace
    00089 #endif //OB_TEXT_H
    00090

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines