[Fix][StringUtils] Prevent infinite loop or crash.

Example:

  std::string rep = "1";
  StringUtils::Replace(rep,"",""); //infinite loop
  StringUtils::Replace(rep,"","1"); //crash std::bad_alloc
Merge pull request #3255 from ace20022/fix_replace

[Fix][StringUtils] Prevent infinite loop or crash.