diff --git a/goldlib/gall/gstrall.h b/goldlib/gall/gstrall.h index 43c4751..ef317d3 100644 --- a/goldlib/gall/gstrall.h +++ b/goldlib/gall/gstrall.h @@ -25,17 +25,14 @@ // String manipulation functions. // ------------------------------------------------------------------ - -// ------------------------------------------------------------------ -// Only include once! - -#ifndef __GSTRALL_H -#define __GSTRALL_H +#ifndef __gstrall_h +#define __gstrall_h // ------------------------------------------------------------------ // Required headers +#include #include #include #include @@ -73,6 +70,7 @@ char* strshr(char* str, int count); char* strsrep(char* str, const char* search, const char* replace); char* strltrim(char* str); char* strtrim(char* str); +string& strtrim(string& p); char* struplow(char* str); char* longdotstr(long num); // Convert a long to a dotted string: xxx.xxx.xxx.xxx diff --git a/goldlib/gall/gstrutil.cpp b/goldlib/gall/gstrutil.cpp index c75ad32..fb52934 100644 --- a/goldlib/gall/gstrutil.cpp +++ b/goldlib/gall/gstrutil.cpp @@ -451,6 +451,18 @@ char* strtrim(char* p) { } +string& strtrim(string& p) { + + if(not p.empty()) { + string::iterator trail = p.end(); + while(trail != p.begin() and *(--trail) < '!') {} + if(*trail > ' ') trail++; + p.erase(trail, p.end()); + } + return p; +} + + // ------------------------------------------------------------------ // Trims leading spaces off of a string