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
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
63size_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
112{
113 xstr = _str;
114 WvConstInPlaceBuf::reset(xstr.cstr(), xstr.len());
115}
void put(const T *data, size_t count)
Writes the specified number of elements from the specified storage location into the buffer at its ta...
Definition: wvbufbase.h:483
const T * peek(int offset, size_t count)
Returns a const pointer into the buffer at the specified offset to the specified number of elements w...
Definition: wvbufbase.h:225
void move(T *buf, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
Definition: wvbufbase.h:309
size_t used() const
Returns the number of elements in the buffer currently available for reading.
Definition: wvbufbase.h:92
The generic buffer base type.
Definition: wvbufbase.h:587
WvConstStringBuffer()
Creates a new empty buffer backed by a null string.
Definition: wvbuffer.cc:106
void reset(WvStringParm _str)
Resets the buffer contents to a new string.
Definition: wvbuffer.cc:111
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
const char * cstr() const
return a (const char *) for this string.
Definition: wvstring.h:267
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330
char * edit()
make the string editable, and return a non-const (char*)
Definition: wvstring.h:397