1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident	"%Z%%M%	%I%	%E% SMI"
4 
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8 #include "splib.h"
9 #include <string.h>
10 #include "InternalInputSource.h"
11 #include "macros.h"
12 
13 #ifdef SP_NAMESPACE
14 namespace SP_NAMESPACE {
15 #endif
16 
InternalInputSource(const StringC & str,InputSourceOrigin * origin)17 InternalInputSource::InternalInputSource(const StringC &str,
18 					 InputSourceOrigin *origin)
19 : InputSource(origin, str.data(), str.data() + str.size()), buf_(0),
20   contents_(&str)
21 {
22 }
23 
~InternalInputSource()24 InternalInputSource::~InternalInputSource()
25 {
26   if (buf_)
27     delete [] buf_;
28 }
29 
fill(Messenger &)30 Xchar InternalInputSource::fill(Messenger &)
31 {
32   return eE;
33 }
34 
pushCharRef(Char c,const NamedCharRef & ref)35 void InternalInputSource::pushCharRef(Char c, const NamedCharRef &ref)
36 {
37   ASSERT(cur() == start());
38   noteCharRef(startIndex() + (cur() - start()), ref);
39   if (buf_ == 0) {
40     buf_ = new Char[end() - start() + 1];
41     memcpy(buf_ + 1, cur(), (end() - start())*sizeof(Char));
42     changeBuffer(buf_ + 1, cur());
43   }
44   moveLeft();
45   *(Char *)cur() = c;
46 }
47 
rewind(Messenger &)48 Boolean InternalInputSource::rewind(Messenger &)
49 {
50   reset(contents_->data(),
51 	contents_->data() + contents_->size());
52   if (buf_) {
53     delete [] buf_;
54     buf_ = 0;
55   }
56   return 1;
57 }
58 
59 #ifdef SP_NAMESPACE
60 }
61 #endif
62