The LIBS line was apparently accidentally deleted from configure-mingw32.
[wvstreams.git] / utils / wvbuffer.cc
blob75d53a9cad05b05ca5374e87a0882adfff3bd729
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"
9 /***** Specialization for raw memory buffers *****/
11 void WvBufBase<unsigned char>::putstr(WvStringParm str)
13 put((const unsigned char*)str.cstr(), str.len());
17 WvString WvBufBase<unsigned char>::getstr()
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;
35 WvString WvBufBase<unsigned char>::getstr(size_t len)
37 WvString result;
38 result.setsize(len + 1);
39 char *str = result.edit();
40 move(str, len);
41 str[len] = '\0';
42 return result;
46 size_t WvBufBase<unsigned char>::strchr(int ch)
48 size_t offset = 0;
49 size_t avail = used();
50 while (offset < avail)
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;
59 return 0;
63 size_t WvBufBase<unsigned char>::_match(const void *bytelist,
64 size_t numbytes, bool reverse)
66 size_t offset = 0;
67 size_t avail = used();
68 const unsigned char *chlist = (const unsigned char*)bytelist;
69 while (offset < avail)
71 size_t len = optpeekable(offset);
72 const unsigned char *str = peek(offset, len);
73 for (size_t i = 0; i < len; ++i)
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)
82 if (c == numbytes)
83 continue;
85 else
87 if (c != numbytes)
88 continue;
90 return offset + i;
92 offset += len;
94 return reverse ? offset : 0;
98 /***** WvConstStringBuffer *****/
100 WvConstStringBuffer::WvConstStringBuffer(WvStringParm _str)
102 reset(_str);
106 WvConstStringBuffer::WvConstStringBuffer()
111 void WvConstStringBuffer::reset(WvStringParm _str)
113 xstr = _str;
114 WvConstInPlaceBuf::reset(xstr.cstr(), xstr.len());