WvStreams
wvbuffer.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Specializations of the generic buffering API.
6  */
7 #include "wvbuf.h"
8 
9 /***** Specialization for raw memory buffers *****/
10 
11 void WvBufBase<unsigned char>::putstr(WvStringParm str)
12 {
13  put((const unsigned char*)str.cstr(), str.len());
14 }
15 
16 
18 {
19  /* Copy the contents into the string.
20  * We used to just return a reference to those bytes, but
21  * that required modifying the buffer to append a null
22  * terminator, which does not work with read-only buffers.
23  * This method is also somewhat safer if a little slower.
24  */
25  WvString result;
26  size_t len = used();
27  result.setsize(len + 1);
28  char *str = result.edit();
29  move(str, len);
30  str[len] = '\0';
31  return result;
32 }
33 
34 
36 {
37  WvString result;
38  result.setsize(len + 1);
39  char *str = result.edit();
40  move(str, len);
41  str[len] = '\0';
42  return result;
43 }
44 
45 
47 {
48  size_t offset = 0;
49  size_t avail = used();
50  while (offset < avail)
51  {
52  size_t len = optpeekable(offset);
53  const unsigned char *str = peek(offset, len);
54  for (size_t i = 0; i < len; ++i)
55  if (str[i] == ch)
56  return offset + i + 1;
57  offset += len;
58  }
59  return 0;
60 }
61 
62 
63 size_t WvBufBase<unsigned char>::_match(const void *bytelist,
64  size_t numbytes, bool reverse)
65 {
66  size_t offset = 0;
67  size_t avail = used();
68  const unsigned char *chlist = (const unsigned char*)bytelist;
69  while (offset < avail)
70  {
71  size_t len = optpeekable(offset);
72  const unsigned char *str = peek(offset, len);
73  for (size_t i = 0; i < len; ++i)
74  {
75  int ch = str[i];
76  size_t c;
77  for (c = 0; c < numbytes; ++c)
78  if (chlist[c] == ch)
79  break;
80  if (reverse)
81  {
82  if (c == numbytes)
83  continue;
84  }
85  else
86  {
87  if (c != numbytes)
88  continue;
89  }
90  return offset + i;
91  }
92  offset += len;
93  }
94  return reverse ? offset : 0;
95 }
96 
97 
98 /***** WvConstStringBuffer *****/
99 
101 {
102  reset(_str);
103 }
104 
105 
107 {
108 }
109 
110 
111 void WvConstStringBuffer::reset(WvStringParm _str)
112 {
113  xstr = _str;
114  WvConstInPlaceBuf::reset(xstr.cstr(), xstr.len());
115 }
WvString::edit
char * edit()
make the string editable, and return a non-const (char*)
Definition: wvstring.h:397
WvBufBase
The generic buffer base type.
Definition: wvbufbase.h:15
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvFastString::cstr
const char * cstr() const
return a (const char *) for this string.
Definition: wvstring.h:267
WvConstStringBuffer::WvConstStringBuffer
WvConstStringBuffer()
Creates a new empty buffer backed by a null string.
Definition: wvbuffer.cc:106
WvConstStringBuffer::reset
void reset(WvStringParm _str)
Resets the buffer contents to a new string.
Definition: wvbuffer.cc:111