/src/util/stringUtil.cpp

https://github.com/deltaforge/nebu-common-cpp · C++ · 33 lines · 22 code · 8 blank · 3 comment · 8 complexity · 9a3727da1156f690a52a44f3eed778ed MD5 · raw file

  1. #include "nebu/util/exceptions.h"
  2. #include "nebu/util/stringUtil.h"
  3. // Using declarations - standard library
  4. using std::string;
  5. namespace nebu
  6. {
  7. namespace common
  8. {
  9. string StringUtil::concatWithDelimiter(string A, string B, const char delimiter)
  10. {
  11. if (delimiter == '\0') {
  12. throw IllegalArgumentException("SpringUtil::concatWithDelimiter: Delimiter must not be '\\0'.");
  13. }
  14. // Remove trailing delimiters
  15. while (A.length() > 0 && A.at(A.length() - 1) == delimiter) {
  16. A.erase(A.end() - 1);
  17. }
  18. // Remove leading delimiters
  19. while (B.length() > 0 && B.at(0) == delimiter) {
  20. B.erase(B.begin());
  21. }
  22. return A + delimiter + B;
  23. }
  24. }
  25. }