PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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