00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }