UFO
StringUtils.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018-2019 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
9 
10 #include <sstream>
11 #include <string>
12 
13 #include "eckit/exception/Exceptions.h"
14 
15 namespace ufo {
16 
17 // -----------------------------------------------------------------------------
18 
19 void splitVarGroup(const std::string & vargrp, std::string & var, std::string & grp) {
20  const size_t at = vargrp.find("@");
21  var = vargrp.substr(0, at);
22  grp = "";
23  if (at != std::string::npos) {
24  grp = vargrp.substr(at + 1, std::string::npos);
25  const size_t no_at = grp.find("@");
26  ASSERT(no_at == std::string::npos);
27  }
28 }
29 
30 // -----------------------------------------------------------------------------
31 
32 void splitInstSat(const std::string & instsat, std::string & inst, std::string & sat) {
33  const size_t at = instsat.find("_");
34  inst = instsat.substr(0, at);
35  sat = "";
36  if (at != std::string::npos) {
37  sat = instsat.substr(at + 1, std::string::npos);
38  const size_t no_at = sat.find("_");
39  ASSERT(no_at == std::string::npos);
40  }
41 }
42 
43 // -----------------------------------------------------------------------------
44 
45 bool isFloat(const std::string & str) {
46  std::istringstream iss(str);
47  float factor;
48  iss >> factor;
49  return (iss.eof() && !iss.fail());
50 }
51 
52 // -----------------------------------------------------------------------------
53 
54 bool readFloat(const std::string & str, float & num) {
55  std::istringstream iss(str);
56  iss >> num;
57  return (iss.eof() && !iss.fail());
58 }
59 
60 } // namespace ufo
ufo::splitVarGroup
void splitVarGroup(const std::string &vargrp, std::string &var, std::string &grp)
Definition: StringUtils.cc:19
ufo::readFloat
bool readFloat(const std::string &str, float &num)
Definition: StringUtils.cc:54
ufo
Definition: RunCRTM.h:27
ufo::splitInstSat
void splitInstSat(const std::string &instsat, std::string &inst, std::string &sat)
Definition: StringUtils.cc:32
ufo::isFloat
bool isFloat(const std::string &str)
Definition: StringUtils.cc:45
StringUtils.h