comparison base/RealTime.cpp @ 350:d7c41483af8f

* Merge from transforms branch -- switch over to using Transform object properly
author Chris Cannam
date Fri, 07 Dec 2007 16:47:31 +0000
parents 21b9b25bff48
children a38cd7823cb2
comparison
equal deleted inserted replaced
348:edda24bb85fc 350:d7c41483af8f
118 s = s.substr(1, s.length() - 1); 118 s = s.substr(1, s.length() - 1);
119 } 119 }
120 120
121 // remove trailing R 121 // remove trailing R
122 return s.substr(0, s.length() - 1); 122 return s.substr(0, s.length() - 1);
123 }
124
125 RealTime
126 RealTime::fromString(std::string s)
127 {
128 bool negative = false;
129 bool faulty = false;
130 bool section = 0;
131 std::string ssec, snsec;
132
133 for (size_t i = 0; i < s.length(); ++i) {
134
135 char c = s[i];
136 if (isspace(c)) continue;
137
138 if (section == 0) {
139
140 if (c == '-') negative = true;
141 else if (isdigit(c)) { section = 1; ssec += c; }
142 else if (c == '.') section = 2;
143 else break;
144
145 } else if (section == 1) {
146
147 if (c == '.') section = 2;
148 else if (isdigit(c)) ssec += c;
149 else break;
150
151 } else if (section == 2) {
152
153 if (isdigit(c)) snsec += c;
154 else break;
155 }
156 }
157
158 while (snsec.length() < 8) snsec += '0';
159
160 int sec = atoi(ssec.c_str());
161 int nsec = atoi(snsec.c_str());
162 if (negative) sec = -sec;
163
164 std::cerr << "RealTime::fromString: string " << s << " -> "
165 << sec << " sec, " << nsec << " nsec" << std::endl;
166
167 return RealTime(sec, nsec);
123 } 168 }
124 169
125 std::string 170 std::string
126 RealTime::toText(bool fixedDp) const 171 RealTime::toText(bool fixedDp) const
127 { 172 {