📄 strtokp.cpp
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -