strtokp.cpp
来自「伯克利做的SFTP安全文件传输协议」· C++ 代码 · 共 80 行
CPP
80 行
// strtokp.cc// code for strtokp.h// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt#include "strtokp.h" // this module#include "exc.h" // xassert#include <string.h> // strtokStrtokParse::StrtokParse(char const *str, char const *delim){ xassert(str != NULL); // make local copy buf = str; // parse it first time to count # of tokens int ct=0; char *tok = strtok(buf.pchar(), delim); while (tok) { ct++; tok = strtok(NULL, delim); } // restore buf buf = str; // allocate storage _tokc = ct; if (ct) { _tokv = new char*[ct+1]; _tokv[ct] = NULL; // terminate argv[]-like list } else { _tokv = NULL; } // parse it again, this time saving the values ct=0; tok = strtok(buf.pchar(), delim); while (tok) { _tokv[ct] = tok; ct++; tok = strtok(NULL, delim); } // simple check just because it's easy xassert(ct == _tokc);}StrtokParse::~StrtokParse(){ // buf deletes itself if (_tokv) { delete _tokv; }}void StrtokParse::validate(int which) const{ xassert((unsigned)which < (unsigned)_tokc);}char const *StrtokParse::tokv(int which) const{ validate(which); return _tokv[which];}int StrtokParse::offset(int which) const{ return tokv(which) - (char const*)buf;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?