stringbuffer.c
来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 124 行
C
124 行
#include "stringbuffer.h"
#include "stringbuffer_private.h"
#include <stdio.h>
stringbuffer_t* stringbuffer_new(char* data, size_t len)
{
stringbuffer_t* newBuf = (stringbuffer_t*)malloc(sizeof(stringbuffer_t));
newBuf->data = data;
newBuf->len = len;
newBuf->index = 0;
return newBuf;
}
stringbuffer_t* stringbuffer_reset(stringbuffer_t* buf, char* data, size_t len)
{
buf->data = data;
buf->len = len;
buf->index = 0;
return buf;
}
int stringbuffer_read(stringbuffer_t* buf)
{
/*
{
char* data = (char*)malloc(buf->len + 1);
memset(data, 0, buf->len + 1);
memcpy(data, buf->data, buf->len);
printf("stringbuffer_read current buffer contains [%s]\n", data);
free(data);
}
*/
if(buf->index >= buf->len) {
/*
fprintf(stdout, "stringbuffer_read returning EOF\n");
*/
return EOF;
}
/*
fprintf(stdout, "stringbuffer_read returning %o\n", (unsigned char)(buf->data[buf->index]));
*/
return((unsigned char)(buf->data[buf->index++]));
}
stringbuffer_t* stringbuffer_rewind(stringbuffer_t* buf, size_t rewindLen)
{
if(buf->index > rewindLen) {
buf->index -= rewindLen;
}
else {
buf->index = 0;
}
return buf;
}
stringbuffer_t* stringbuffer_setIndex(stringbuffer_t* buf, size_t newIndex)
{
buf->index = newIndex;
return buf;
}
void stringbuffer_delete(stringbuffer_t* buf)
{
free(buf);
}
char* stringbuffer_getData(stringbuffer_t* buf)
{
return buf->data;
}
size_t stringbuffer_getLen(stringbuffer_t* buf)
{
return buf->len;
}
size_t stringbuffer_getIndex(stringbuffer_t* buf)
{
return buf->index;
}
/**
* @defgroup Parser Parser
*
* Some text about this module.
*
* @{
*/
/**
* @file parser.c
*/
/**
* @file scan.c
*/
/**
* @file stdpccts.h
*/
/**
* @file err.c
*/
/**
* @file mode.h
*/
/**
* @file tokens.h
*/
/**
* @file stringbuffer.h
*/
/**
* @file stringbuffer.c
*/
/** @} */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?