MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CleanupStr

Function CleanupStr

misc/pstring.cpp:48–79  ·  view source on GitHub ↗

CleanupStr This function strips all leading and trailing spaces, keeping internal spaces. This goes for tabs too.

Source from the content-addressed store, hash-verified

46// CleanupStr
47// This function strips all leading and trailing spaces, keeping internal spaces. This goes for tabs too.
48std::size_t CleanupStr(char *dest, const char *src, std::size_t destlen) {
49 if (destlen == 0)
50 return 0;
51
52 const char *end;
53 std::size_t out_size;
54
55 // Trim leading space
56 while (std::isspace((uint8_t)*src))
57 src++;
58
59 // All spaces?
60 if (*src == '\0') {
61 *dest = '\0';
62 return 1;
63 }
64
65 // Trim trailing space
66 end = src + std::strlen(src) - 1;
67 while (end > src && std::isspace((uint8_t)*end))
68 end--;
69 end++;
70
71 // Set output size to minimum of trimmed string length and buffer size minus 1
72 out_size = (end - src) < destlen - 1 ? (end - src) : destlen - 1;
73
74 // Copy trimmed string and add null terminator
75 std::memcpy(dest, src, out_size);
76 dest[out_size] = '\0';
77
78 return out_size;
79}

Callers 6

TESTFunction · 0.85
ParseLineMethod · 0.85
LoadHUDConfigFunction · 0.85
ParseLineFunction · 0.85
LoadMissionFunction · 0.85
GetMissionInfoFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68