typename T::return_type operator()(T& t, const char* d, typename T::size_type s) { _clear_flag = false; data_type::size_type offset = 0; if ( _data.empty() ) { if (_data.capacity() > 0 ) data_type(_data).swap(_data); offset = _parse_(t, d, s, 0, 0); if (!_clear_flag) { if (offset == static_cast<data_type::size_type>(-1)) _assign(d, d + s); else if ( static_cast<typename T::size_type>(offset) != s) _assign(d + offset, d + s); } } else { const size_t datasize = _data.size(); if (_data.capacity() < datasize + s) { _data.reserve( datasize < 16384 ? datasize + s : datasize+(datasize>>1)+s); } std::copy(d, d + s, std::back_inserter(_data)); offset = _parse_(t, &(_data[0]), _data.size(), 0, datasize>size_sep ? datasize-size_sep : 0); if (!_clear_flag) { if ( offset == static_cast<typename T::size_type>( _data.size() ) ) _data.clear(); else if ( offset!= static_cast<data_type::size_type>(-1) ) _data.erase( _data.begin(), _data.begin() + offset ); } }
void Calendar::parse(const char* text) { if(text[0] == ' ' || text[0] == '\t') { calbuf += text; } else { _parse_(); calbuf = text; } }
/** * @brief read configure file * @param[in] name : configure file name */ inline int file_stream::read(const char *name) { FILE *fp; int ret = 0; int line = 0; if( !(fp = fopen(name, "r")) ) return -1; ret = _parse_(fp, this, &line); fclose(fp); return ret; }
/** * @brief parse - substruction context * @param[in] fp : file stream * @param[in] n : name string header pointer * @param[in] v : value string header pointer * @param[in] s : configuration * @param[in] line : reading line * @return ==0 : success */ inline int file_stream::substitution(FILE *fp, char *n, char *v, configuration *conf, int *line) { char name[512]; char value[512]; LogDebugf("Begin: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); { // ---> get name // zero initialize ::memset(name, 0, sizeof(name)); get_ascii(name, n); erase_blank(n); if( *n != '\0'){ LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); return -1; } LogDebugf(" : name \"%s\"\n", name); } // <--- get name { // ----> get value or nesting erase_blank(v); LogDebugf(" : value \"%s\"\n", v); if( v[0] != TokenBeginScope ){ // check error if( *v == '\0' ){ LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); return -1; } {// ---> get value get_ascii(value, v); erase_blank(v); if( *value == '\0'){ LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); return -1; } if( *v != '\0'){ LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); return -1; } conf->child_push_back(name, value); }// <--- get value } // ---> nesting else { LogDebug(" : nesting\n"); ::memmove(v, v + 1, ::strlen(v) - 1); erase_blank(v); LogDebugf(" : nesting \"%s\"\n", v); if( *v == '\0' ){ configuration *p; // todo modify to not need search conf->child_push_back(name, 0); p = conf->child_find(name, 0); _parse_(fp, p, line); } else { configuration *p; // todo modify to not need search conf->child_push_back(name, 0); p = conf->child_find(name, 0); if( unnamed(v, p, line) == 1) { // not end of nesting // read next line _parse_(fp, p, line); } } } // <--- nesting } // <---- get value or nesting LogDebugf(" End: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line); return 0; }
void Calendar::flush() { _parse_(); calbuf = ""; }