Changeset 73:7378840a824a in rrlib_util


Ignore:
Timestamp:
04.12.2012 15:36:43 (7 years ago)
Author:
Jochen Hirth <hirth@…>
Branch:
default
Phase:
public
Message:

Added ConstReplace to replace a char in a string without changing the original string.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sStringUtils.cpp

    r41 r73  
    120120    } 
    121121  } 
     122} 
     123 
     124std::string sStringUtils::ConstReplace(const std::string &input_str, const char* target_token, const char* replace_token) 
     125{ 
     126  std::string output_str = input_str; 
     127  size_t pos = output_str.find(target_token); 
     128  while (pos != std::string::npos) 
     129  { 
     130    output_str.replace(pos, strlen(target_token), replace_token); 
     131    pos = output_str.find(target_token); 
     132  } 
     133  return output_str; 
    122134} 
    123135 
  • sStringUtils.h

    r72 r73  
    225225  static void Replace(char *input_str, char target_token, char replace_token); 
    226226 
     227  static std::string ConstReplace(const std::string &input_str, const char* target_token, const char* replace_token); 
     228 
    227229  /*! 
    228230   * Stream manipulator implementation for reading a string from actual position within the stream up to the end of line. 
Note: See TracChangeset for help on using the changeset viewer.