PrettyPrintBuffer.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "PrettyPrintBuffer.h"
00019 #include "util/StringBuffer.h"
00020 
00021 namespace oasys {
00022 
00023 const int PrettyPrintBuf::MAX_COL = 80;
00024 
00025 //----------------------------------------------------------------------------
00026 PrettyPrintBuf::PrettyPrintBuf(const char* buf, int len)
00027     : buf_(buf), cur_(0), len_(len)
00028 {
00029     if(len_ == -1)
00030     {
00031         len_ = strlen(buf);
00032     }
00033 }
00034 
00035 //----------------------------------------------------------------------------
00036 bool
00037 PrettyPrintBuf::next_str(std::string* s)
00038 {
00039     StringBuffer buf;
00040 
00041     int bound = std::min(cur_ + MAX_COL, len_);
00042     for(int i = cur_; i<bound; ++i, ++cur_)
00043     {
00044         switch(buf_[i])
00045         { 
00046         case '\n': buf.append("\\n"); break;
00047         case '\r': buf.append("\\r"); break;
00048         case '\t': buf.append("\\t"); break;
00049         case '\0': buf.append("\\0"); break;
00050 
00051         default:
00052             buf.append(buf_[i]);
00053         }
00054     }
00055 
00056     bool full = (bound == len_) ? true : false;
00057     s->assign(buf.c_str());
00058     return full;
00059 }
00060 
00061 } // namespace oasys

Generated on Thu Jun 7 16:56:51 2007 for DTN Reference Implementation by  doxygen 1.5.1