nis-util  1.0.D108
lib/output/string.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #include <lib/output/string.h>
00020 
00021 
00022 output_string::~output_string()
00023 {
00024 }
00025 
00026 
00027 output_string::output_string(int a_linlen) :
00028     linlen(a_linlen),
00029     column(0)
00030 {
00031 }
00032 
00033 
00034 output_string::pointer
00035 output_string::create(int a_linlen)
00036 {
00037     return pointer(new output_string(a_linlen));
00038 }
00039 
00040 
00041 void
00042 output_string::put(char c)
00043 {
00044     acc.push_back(c);
00045     switch (c)
00046     {
00047     case '\n':
00048         column = 0;
00049         break;
00050 
00051     case '\t':
00052         column = (column + 8) & ~7;
00053         break;
00054 
00055     default:
00056         ++column;
00057         break;
00058     }
00059 }
00060 
00061 
00062 rcstring
00063 output_string::mkstr(void)
00064     const
00065 {
00066     return acc.mkstr();
00067 }
00068 
00069 
00070 int
00071 output_string::get_line_width(void)
00072     const
00073 {
00074     return linlen;
00075 }
00076 
00077 
00078 int
00079 output_string::get_column(void)
00080     const
00081 {
00082     return column;
00083 }
00084 
00085 
00086 // vim: set ts=8 sw=4 et :