source: trunk/lib/utility/utility.cc @ 570

Last change on this file since 570 was 570, checked in by Jari Häkkinen, 15 years ago

Added copyright statement to files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1// $Id: utility.cc 570 2006-04-05 13:09:49Z jari $
2
3/*
4  Copyright (C) 2005 Jari Häkkinen, Markus Ringnér
5  Copyright (C) 2006 Jari Häkkinen
6
7  This file is part of the thep c++ tools library,
8                                http://lev.thep.lu.se/trac/c++_tools
9
10  The c++ tools library is free software; you can redistribute it
11  and/or modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2 of
13  the License, or (at your option) any later version.
14
15  The c++ tools library is distributed in the hope that it will be
16  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include <c++_tools/utility/utility.h>
27
28#include <c++_tools/utility/stl_utility.h>
29
30#include <sstream>
31#include <string>
32
33namespace theplu {
34namespace utility {
35
36  bool is_double(const std::string& s)
37  {
38    std::stringstream ss(s);
39    double a;
40    return (ss>>a);
41  }
42 
43  bool is_float(const std::string& s)
44  {
45    std::stringstream ss(s);
46    float a;
47    return (ss>>a);
48  }
49
50  bool is_int(const std::string& s)
51  {
52    std::stringstream ss(s);
53    int a;
54    return (ss>>a);
55  }
56
57  bool is_nan(const std::string& s)
58  {
59    std::stringstream ss(s);
60    std::string s2;
61    ss >> s2; // to trim surrounding whitespaces
62    to_lower(s2);
63    std::string nan("nan");
64    return (nan==s2);
65  }
66
67}} // end of namespace utility and namespace thep
Note: See TracBrowser for help on using the repository browser.