Changeset 606 for trunk/lib/HtmlBuf.cc


Ignore:
Timestamp:
Apr 20, 2008, 5:46:56 AM (13 years ago)
Author:
Peter Johansson
Message:

Fixes ticket:318. Changed HtmlStream? to be inherited from ostream and created a HtmlBuf? (inherited from streambuf) that does the real work.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/HtmlBuf.cc

    r604 r606  
    33/*
    44  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2008 Peter Johansson
    56
    67  This file is part of svndigest, http://trac.thep.lu.se/svndigest
     
    2223*/
    2324
    24 #include "HtmlStream.h"
     25#include "HtmlBuf.h"
    2526
     27#include <cstdio>
     28#include <iostream>
    2629#include <string>
    2730
     
    2932namespace svndigest{
    3033
    31   HtmlStream::HtmlStream(std::ostream& os)
    32     : os_(os)
     34  HtmlBuf::HtmlBuf(std::streambuf& buf)
     35    : std::streambuf(), buf_(buf)
    3336  {
    3437    map_['"']=std::string("\"");
     
    5356  }
    5457
    55 
    56   HtmlStream::~HtmlStream(void)
     58  HtmlBuf::int_type HtmlBuf::overflow (HtmlBuf::int_type c)
    5759  {
    58   }
    59 
    60 
    61   void HtmlStream::print(std::stringstream& ss)
    62   {
    63     char c;
    64     while (true){
    65       ss.get(c);
    66       if (!ss.good())
    67         return;
    68       std::map<char, std::string>::const_iterator i = map_.find(c);
    69       if (i==map_.end())
    70         os_ << c;
    71       else
    72         os_ << i->second;
    73     }
    74   }
    75 
    76  
    77   std::ostream& HtmlStream::stream(void)
    78   {
    79     return os_;
     60    std::map<char, std::string>::const_iterator i = map_.find(c);
     61    if (i==map_.end())
     62      return buf_.sputc(c);
     63    // writing
     64    if (buf_.sputn(i->second.c_str(), i->second.size()) ==
     65        static_cast<std::streamsize>(i->second.size()))
     66      return c;
     67    return EOF;
    8068  }
    8169
Note: See TracChangeset for help on using the changeset viewer.