NCBI C++ ToolKit
ns_output_parser.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ns_output_parser.cpp 72694 2016-05-23 15:27:45Z sadyrovr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitry Kazimirov
27  *
28  * File Description: NetSchedule output parsers - implementation.
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
36 
38 
40  CTempString* attr_name, string* attr_value, size_t* attr_column)
41 {
42  while (isspace(*m_Position))
43  ++m_Position;
44 
45  if (*m_Position == '\0')
46  return eNoMoreAttributes;
47 
48  const char* attr_start = m_Position;
49  *attr_column = attr_start - m_Start + 1;
50 
51  for (;;)
52  if (*m_Position == '=') {
53  attr_name->assign(attr_start, m_Position - attr_start);
54  break;
55  } else if (isspace(*m_Position)) {
56  attr_name->assign(attr_start, m_Position - attr_start);
57  while (isspace(*++m_Position))
58  ;
59  if (*m_Position == '=')
60  break;
61  else
62  return eStandAloneAttribute;
63  } else if (*++m_Position == '\0') {
64  attr_name->assign(attr_start, m_Position - attr_start);
65  return eStandAloneAttribute;
66  }
67 
68  // Skip the equals sign and the spaces that may follow it.
69  while (isspace(*++m_Position))
70  ;
71 
72  attr_start = m_Position;
73 
74  switch (*m_Position) {
75  case '\0':
76  NCBI_THROW_FMT(CArgException, eInvalidArg,
77  "empty attribute value must be specified as " <<
78  attr_name << "=\"\"");
79  case '\'':
80  case '"':
81  {
82  size_t n_read;
83  *attr_value = NStr::ParseQuoted(CTempString(attr_start,
84  m_EOL - attr_start), &n_read);
85  m_Position += n_read;
86  }
87  break;
88  default:
89  while (*++m_Position != '\0' && !isspace(*m_Position))
90  ;
91  *attr_value = NStr::ParseEscapes(
92  CTempString(attr_start, m_Position - attr_start));
93  }
94 
95  return eAttributeWithValue;
96 }
97 
CArgException –.
Definition: ncbiargs.hpp:120
ENextAttributeType NextAttribute(CTempString *attr_name, string *attr_value, size_t *attr_column)
const char * m_Position
const char * m_Start
const char * m_EOL
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
Definition: tempstr.hpp:733
static string ParseEscapes(const CTempString str, EEscSeqRange mode=eEscSeqRange_Standard, char user_char='?')
Parse C-style escape sequences in the specified string.
Definition: ncbistr.cpp:4789
static string ParseQuoted(const CTempString str, size_t *n_read=NULL)
Discard C-style backslash escapes and extract a quoted string.
Definition: ncbistr.cpp:4923
int isspace(Uchar c)
Definition: ncbictype.hpp:69
Modified on Tue Dec 05 02:06:09 2023 by modify_doxy.py rev. 669887