Changeset 327
- Timestamp:
- May 31, 2005, 1:00:20 AM (18 years ago)
- Location:
- trunk/lib/utility
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/utility/Makefile.am
r319 r327 10 10 libutility_la_SOURCES = \ 11 11 Alignment.cc FileIO.cc kNNI.cc Merge.cc NNI.cc PCA.cc\ 12 random_singleton.cc stl_utility.cc SVD.cc WeNNI.cc12 random_singleton.cc stl_utility.cc SVD.cc utility.cc WeNNI.cc 13 13 14 14 include_utilitydir = $(includedir)/c++_tools/utility … … 16 16 include_utility_HEADERS = \ 17 17 Alignment.h FileIO.h kNNI.h Merge.h NNI.h PCA.h random_singleton.h \ 18 stl_utility.h SVD.h WeNNI.h18 stl_utility.h SVD.h utility.h WeNNI.h 19 19 -
trunk/lib/utility/stl_utility.cc
r301 r327 2 2 3 3 #include <c++_tools/utility/stl_utility.h> 4 #include <c++_tools/utility/utility.h> 4 5 5 6 #include <iostream> … … 11 12 namespace utility { 12 13 13 bool is_float(const std::string& s)14 {15 // have decimal point16 bool dp = false;17 size_t i = 0;18 if (s[i] == '-' || s[i] == '+') {19 i++;20 // empty after sign21 if (i >= s.size())22 return false;23 }24 bool isf = false;25 while(i<s.size()){26 if (s[i] < '0' || s[i] > '9'){27 if (s[i] == '.') {28 // two decimals29 if (dp)30 return false;31 else32 dp = true;33 }34 else if (s[i] == 'E' || s[i] == 'e'){35 i++;36 // nothing following E37 if (i >=s.size())38 return false;39 std::string tmp_str(s,i) ;40 return is_int(tmp_str);41 }42 }43 else44 isf = true;45 i++;46 }47 return isf;48 }49 14 50 bool is_int(const std::string& s)51 {52 size_t i = 0;53 if (s[i] == '-' || s[i] == '+') {54 i++;55 // nothing following sign56 if (i >= s.size())57 return false;58 }59 while (i<s.size()) {60 if (s[i] < '0' || s[i] > '9')61 return false;62 i++;63 }64 return true;65 }66 67 15 bool read_to_double(std::istream& is, std::vector<double>& vec) 68 16 { … … 82 30 return false; 83 31 } 32 33 84 34 85 35 bool read_to_int(std::istream& is, std::vector<int>& vec) … … 101 51 } 102 52 53 54 103 55 bool read_to_string(std::istream& is, std::vector<std::string>& vec) 104 56 { -
trunk/lib/utility/stl_utility.h
r303 r327 39 39 40 40 /// 41 /// Function return true if string is a number. A number is defined42 /// to start with '+', '-' or a digit. It must contain at most one43 /// decimal point '.'. Also it may contain 'E' or 'e' followed by an44 /// integer (see is_int).45 ///46 /// @return true if string is a number47 ///48 bool is_float(const std::string&);49 50 ///51 /// @return true if every character in string is a digit except the52 /// first one that may be '+' or '-'53 ///54 bool is_int(const std::string&);55 56 ///57 41 /// Function reading from istream to vector of doubles. Function 58 42 /// reads the line until next '\\n'. The line is splitted with
Note: See TracChangeset
for help on using the changeset viewer.