WvStreams
|
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Specializations of the generic buffering API. 00006 */ 00007 #include "wvbuf.h" 00008 00009 /***** Specialization for raw memory buffers *****/ 00010 00011 void WvBufBase<unsigned char>::putstr(WvStringParm str) 00012 { 00013 put((const unsigned char*)str.cstr(), str.len()); 00014 } 00015 00016 00017 WvString WvBufBase<unsigned char>::getstr() 00018 { 00019 /* Copy the contents into the string. 00020 * We used to just return a reference to those bytes, but 00021 * that required modifying the buffer to append a null 00022 * terminator, which does not work with read-only buffers. 00023 * This method is also somewhat safer if a little slower. 00024 */ 00025 WvString result; 00026 size_t len = used(); 00027 result.setsize(len + 1); 00028 char *str = result.edit(); 00029 move(str, len); 00030 str[len] = '\0'; 00031 return result; 00032 } 00033 00034 00035 WvString WvBufBase<unsigned char>::getstr(size_t len) 00036 { 00037 WvString result; 00038 result.setsize(len + 1); 00039 char *str = result.edit(); 00040 move(str, len); 00041 str[len] = '\0'; 00042 return result; 00043 } 00044 00045 00046 size_t WvBufBase<unsigned char>::strchr(int ch) 00047 { 00048 size_t offset = 0; 00049 size_t avail = used(); 00050 while (offset < avail) 00051 { 00052 size_t len = optpeekable(offset); 00053 const unsigned char *str = peek(offset, len); 00054 for (size_t i = 0; i < len; ++i) 00055 if (str[i] == ch) 00056 return offset + i + 1; 00057 offset += len; 00058 } 00059 return 0; 00060 } 00061 00062 00063 size_t WvBufBase<unsigned char>::_match(const void *bytelist, 00064 size_t numbytes, bool reverse) 00065 { 00066 size_t offset = 0; 00067 size_t avail = used(); 00068 const unsigned char *chlist = (const unsigned char*)bytelist; 00069 while (offset < avail) 00070 { 00071 size_t len = optpeekable(offset); 00072 const unsigned char *str = peek(offset, len); 00073 for (size_t i = 0; i < len; ++i) 00074 { 00075 int ch = str[i]; 00076 size_t c; 00077 for (c = 0; c < numbytes; ++c) 00078 if (chlist[c] == ch) 00079 break; 00080 if (reverse) 00081 { 00082 if (c == numbytes) 00083 continue; 00084 } 00085 else 00086 { 00087 if (c != numbytes) 00088 continue; 00089 } 00090 return offset + i; 00091 } 00092 offset += len; 00093 } 00094 return reverse ? offset : 0; 00095 } 00096 00097 00098 /***** WvConstStringBuffer *****/ 00099 00100 WvConstStringBuffer::WvConstStringBuffer(WvStringParm _str) 00101 { 00102 reset(_str); 00103 } 00104 00105 00106 WvConstStringBuffer::WvConstStringBuffer() 00107 { 00108 } 00109 00110 00111 void WvConstStringBuffer::reset(WvStringParm _str) 00112 { 00113 xstr = _str; 00114 WvConstInPlaceBuf::reset(xstr.cstr(), xstr.len()); 00115 }