ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/StringUtils.cpp
(Generate patch)

Comparing branches/development/src/utils/StringUtils.cpp (file contents):
Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC vs.
Revision 1808 by gezelter, Mon Oct 22 20:42:10 2012 UTC

# Line 36 | Line 36
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38   * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43 + #include "config.h"
44   #include <algorithm>
45 + #include <stdlib.h>
46 + #include <cctype>
47 + #include <cstdlib>
48 + #include <string>
49   #include "utils/StringUtils.hpp"
50  
51 + #ifdef _MSC_VER
52 + #define strcasecmp _stricmp
53 + #define strdup _strdup
54 + #define strtoull _strtoui64
55 + #endif
56 +
57 +
58   namespace OpenMD {
59    std::string UpperCase(const std::string& S) {
60      std::string uc = S;
# Line 97 | Line 110 | namespace OpenMD {
110      int foundText = 0;
111      int lineNum;
112      char* the_token;
100    char* eof_test;
113  
114      // rewind the stream
115      theStream.seekg (0, std::ios::beg);
# Line 217 | Line 229 | namespace OpenMD {
229    std::string getSuffix(const std::string& str) {
230      return str.substr(0, str.find('.'));
231    }
232 <
233 < bool isInteger(const std::string& str) {
234 <
232 >  
233 >  bool isInteger(const std::string& str) {
234 >    
235      bool result = false;
236 <
236 >    
237      std::string::const_iterator i = str.begin();    
238      if (i != str.end() && (*i == '+' || *i == '-' || std::isdigit(*i) )) {
239 <        ++i;        
240 <        while (i != str.end() && std::isdigit(*i))
241 <            ++i;
242 <        if (i == str.end())
243 <            result = true;
239 >      ++i;        
240 >      while (i != str.end() && std::isdigit(*i))
241 >        ++i;
242 >      if (i == str.end())
243 >        result = true;
244      }
245      
246      return result;
247 < }
247 >  }
248  
249 < bool CaseInsensitiveEquals(const char ch1, const char ch2) {
250 <  return std::toupper((unsigned char)ch1) == std::toupper((unsigned char)ch2);
251 < }
252 <
253 < size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2) {
254 <  std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CaseInsensitiveEquals);
255 <  if (pos == str1.end())
256 <    return std::string::npos;
257 <  else
258 <    return pos - str1.begin();
249 >  bool CaseInsensitiveEquals(const char ch1, const char ch2) {
250 >    return std::toupper((unsigned char)ch1) == std::toupper((unsigned char)ch2);
251 >  }
252 >  
253 >  size_t CaseInsensitiveFind(const std::string& str1, const std::string& str2) {
254 >    std::string::const_iterator pos = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CaseInsensitiveEquals);
255 >    if (pos == str1.end())
256 >      return std::string::npos;
257 >    else
258 >      return pos - str1.begin();
259 >  }
260 >  
261 >  /**
262 >   *    memparse - parse a string with mem suffixes into a number
263 >   *    @param ptr: Where parse begins
264 >   *    @param retptr: (output) Pointer to next char after parse completes
265 >   *
266 >   *    Parses a string into a number.  The number stored at @param ptr is
267 >   *    potentially suffixed with %K (for kilobytes, or 1024 bytes),
268 >   *    %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or
269 >   *    1073741824).  If the number is suffixed with K, M, or G, then
270 >   *    the return value is the number multiplied by one kilobyte, one
271 >   *    megabyte, or one gigabyte, respectively.
272 >   */  
273 >  unsigned long long memparse (char *ptr,  char **retptr) {
274 >    unsigned long long ret = strtoull (ptr, retptr, 0);
275 >    
276 >    switch (**retptr) {
277 >    case 'G':
278 >    case 'g':
279 >      ret <<= 10;
280 >    case 'M':
281 >    case 'm':
282 >      ret <<= 10;
283 >    case 'K':
284 >    case 'k':
285 >      ret <<= 10;
286 >      (*retptr)++;
287 >    default:
288 >      break;
289 >    }
290 >    return ret;
291 >  }
292 >  
293   }
248
249 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines