MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / Trim

Function Trim

Bcore/src/main/cpp/android-base/strings.cpp:49–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49std::string Trim(const std::string& s) {
50 std::string result;
51
52 if (s.size() == 0) {
53 return result;
54 }
55
56 size_t start_index = 0;
57 size_t end_index = s.size() - 1;
58
59 // Skip initial whitespace.
60 while (start_index < s.size()) {
61 if (!isspace(s[start_index])) {
62 break;
63 }
64 start_index++;
65 }
66
67 // Skip terminating whitespace.
68 while (end_index >= start_index) {
69 if (!isspace(s[end_index])) {
70 break;
71 }
72 end_index--;
73 }
74
75 // All spaces, no beef.
76 if (end_index < start_index) {
77 return "";
78 }
79 // Start_index is the first non-space, end_index is the last one.
80 return s.substr(start_index, end_index - start_index + 1);
81}
82
83// These cases are probably the norm, so we mark them extern in the header to
84// aid compile time and binary size.

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected