Xmipp  v3.23.11-Nereus
Public Member Functions | List of all members
cif::pdb::SpecificationListParser Class Reference

Public Member Functions

 SpecificationListParser (const std::string &text)
 
std::tuple< std::string, std::string > GetNextSpecification ()
 

Detailed Description

Definition at line 286 of file pdb2cif.cpp.

Constructor & Destructor Documentation

◆ SpecificationListParser()

cif::pdb::SpecificationListParser::SpecificationListParser ( const std::string &  text)
inline

Definition at line 289 of file pdb2cif.cpp.

290  : mText(text)
291  , mP(mText.begin())
292  {
293  }

Member Function Documentation

◆ GetNextSpecification()

std::tuple< std::string, std::string > cif::pdb::SpecificationListParser::GetNextSpecification ( )

Definition at line 302 of file pdb2cif.cpp.

303 {
304  std::string id, value;
305 
306  std::string::iterator start = mP, backup;
307 
308  enum
309  {
310  eStart,
311  eID,
312  eColon,
313  eValue,
314  eNL,
315  eNL_ID,
316  eSemiColon,
317  eError,
318  eDone
319  } state = eStart;
320 
321  while (mP != mText.end() and state != eDone)
322  {
323  char ch = *mP++;
324 
325  switch (state)
326  {
327  case eStart:
328  if (isalnum(ch) or ch == '_')
329  {
330  id = { ch };
331  value.clear();
332  state = eID;
333  start = mP;
334  }
335  else if (not isspace(ch))
336  {
337  if (cif::VERBOSE > 0)
338  std::cerr << "skipping invalid character in SOURCE ID: " << ch << std::endl;
339  }
340  break;
341 
342  case eID:
343  if (isalnum(ch) or ch == '_')
344  id += ch;
345  else if (ch == ':')
346  state = eColon;
347  else
348  state = eError;
349  break;
350 
351  case eColon:
352  if (ch == ';')
353  {
354  if (cif::VERBOSE > 0)
355  std::cerr << "Empty value for SOURCE: " << id << std::endl;
356  state = eStart;
357  }
358  else if (not isspace(ch))
359  {
360  value = { ch };
361  state = eValue;
362  }
363  break;
364 
365  case eValue:
366  if (ch == '\n')
367  {
368  backup = mP;
369  state = eNL;
370  }
371  else if (ch == ';')
372  {
373  backup = mP;
374  state = eSemiColon;
375  }
376  else
377  value += ch;
378  break;
379 
380  case eSemiColon:
381  if (ch == '\n')
382  state = eDone;
383  else if (ch != ' ')
384  {
385  value.insert(value.end(), backup, mP);
386  state = eValue;
387  }
388  break;
389 
390  case eNL:
391  if (isalnum(ch))
392  {
393  value += ' ';
394  state = eNL_ID;
395  }
396  else if (isspace(ch))
397  state = eValue;
398  break;
399 
400  case eNL_ID:
401  if (ch == ':')
402  {
403  mP = backup;
404  state = eDone;
405  }
406  else if (ch == ';')
407  state = eSemiColon;
408  else if (not(isalnum(ch) or ch == '_'))
409  {
410  value.insert(value.end(), backup, mP);
411  state = eValue;
412  }
413  break;
414 
415  case eError:
416  if (ch == ';')
417  {
418  if (cif::VERBOSE > 0)
419  std::cerr << "Skipping invalid header line: '" << std::string(start, mP) << std::endl;
420  state = eStart;
421  }
422  break;
423 
424  case eDone: break; // keep compiler happy
425  }
426  }
427 
428  cif::trim(value);
429 
430  return std::make_tuple(id, value);
431 }
void trim(std::string &s)
Definition: text.cpp:205
int VERBOSE
Definition: utilities.cpp:58
double * backup

The documentation for this class was generated from the following file: