Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. #include <vector>
  2. #include <cstdlib>
  3. using namespace std;
  4. //
  5. // utility function to tokenize a given line based on the delimiters
  6. // specified
  7. //
  8. template< class T >
  9. unsigned Tokenize(const T &szInput, const T & szDelimiters, vector<T>& tokens) {
  10. unsigned uDelimiterCount = 0;
  11. tokens.clear();
  12. if(!szInput.empty()){
  13. if(!szDelimiters.empty()){
  14. T::const_iterator inputIter = szInput.begin();
  15. T::const_iterator copyIter = szInput.begin();
  16. while(inputIter != szInput.end()){
  17. if(szDelimiters.find(*inputIter) != string::npos){
  18. if (copyIter < inputIter) {
  19. tokens.push_back(szInput.substr(copyIter - szInput.begin(),
  20. inputIter - copyIter));
  21. }
  22. uDelimiterCount++;
  23. inputIter++;
  24. copyIter = inputIter;
  25. continue;
  26. }
  27. inputIter++;
  28. }
  29. if(copyIter != inputIter){
  30. tokens.push_back(szInput.substr(copyIter - szInput.begin(),
  31. inputIter - szInput.begin()));
  32. }
  33. }
  34. else
  35. tokens.push_back(szInput);
  36. }
  37. return uDelimiterCount;
  38. }
  39. unsigned long toUnsignedLong(const string& str) {
  40. int radix = 10; //decimal
  41. if ((str.find("0x") != str.npos) || (str.find("0X") != str.npos))
  42. radix = 16; // hex decimal
  43. return ::strtoul(str.c_str(), 0, radix);
  44. }