This commit is contained in:
Adam Ierymenko 2019-08-19 20:35:16 -07:00
parent e73b220104
commit 6e771607c0
No known key found for this signature in database
GPG key ID: 1657198823E52A61
2 changed files with 24 additions and 23 deletions

View file

@ -264,6 +264,28 @@ public:
*/
static std::vector<std::string> split(const char *s,const char *const sep,const char *esc,const char *quot);
/**
* Trim whitespace from beginning and end of string
*/
static inline std::string trimString(const std::string &s)
{
unsigned long end = (unsigned long)s.length();
while (end) {
char c = s[end - 1];
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
--end;
else break;
}
unsigned long start = 0;
while (start < end) {
char c = s[start];
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
++start;
else break;
}
return s.substr(start,end - start);
}
/**
* Write a block of data to disk, replacing any current file contents
*