string.cc
来自「larbin是一种开源的网络爬虫/网络蜘蛛」· CC 代码 · 共 89 行
CC
89 行
// Larbin// Sebastien Ailleret// 20-12-99 -> 10-12-01#include <string.h>#include <iostream.h>#include "options.h"#include "utils/text.h"#include "utils/string.h"// ConstructorLarbinString::LarbinString (uint size) { chaine = new char[size]; this->size = size; pos = 0; chaine[0] = 0;}// DestructorLarbinString::~LarbinString () { delete [] chaine;}// Recycle this stringvoid LarbinString::recycle (uint size) { if (this->size > size) { delete [] chaine; chaine = new char[size]; this->size = size; } pos = 0; chaine[0] = 0;}// get the char *char *LarbinString::getString () { return chaine;}/** give a new string (allocate a new one * the caller will have to delete it */char *LarbinString::giveString () { return newString(chaine);}// append a charvoid LarbinString::addChar (char c) { chaine[pos] = c; pos++; if (pos >= size) { char *tmp = new char[size * 2]; memcpy(tmp, chaine, pos); delete [] chaine; chaine = tmp; size *= 2; } chaine[pos] = 0;}// append a char *void LarbinString::addString (char *s) { uint len = strlen(s); addBuffer(s, len);}// append a buffervoid LarbinString::addBuffer (char *s, uint len) { if (size <= pos + len) { size *= 2; if (size <= pos + len) size = pos + len + 1; char *tmp = new char[size]; memcpy(tmp, chaine, pos); delete [] chaine; chaine = tmp; } memcpy(chaine+pos, s, len); pos += len; chaine[pos] = 0;}// change a charvoid LarbinString::setChar (uint i, char c) { chaine[i] = c;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?