MCPcopy Create free account
hub / github.com/andreasfertig/cppinsights / trim

Function trim

tests/ClassOperatorHandler5Test.cpp:3–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <string>
2
3std::string trim(const std::string& input)
4{
5 if(input.length() == 0) {
6 return "";
7 }
8
9 std::string final = input;
10
11 int i = 0;
12 while(i < (int)input.length() && input[i] <= ' ') {
13 i++;
14 }
15
16 if(i >= (int)input.length()) {
17 return "";
18 }
19
20 if(i > 0) {
21 final = input.substr(i, input.length() - i);
22 }
23
24 i = (int)final.length() - 1;
25 while(i >= 0 && final[i] <= ' ') {
26 i--;
27 }
28
29 return final.substr(0, i + 1);
30}
31
32int main()
33{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected