cmText.h/c : Added cmTextTrimBegin(),cmTextTrimEnd() and cmTextTime().

This commit is contained in:
kevin 2014-01-17 16:54:24 -05:00
parent 5c36dfcf9a
commit 84782a1fa8
2 changed files with 48 additions and 0 deletions

View File

@ -519,6 +519,49 @@ void cmTextClip( cmChar_t* s, unsigned n )
}
cmChar_t* cmTextTrimBegin( cmChar_t* s )
{
if( s==NULL || strlen(s) == 0 )
return s;
cmChar_t* s0 = cmTextNextNonWhite(s);
// no non-white char's exist
if( s0 == NULL )
{
s[0] = 0;
return s;
}
if( s0 != s )
cmTextShrinkS(s,s,s0-s);
return s;
}
cmChar_t* cmTextTrimEnd( cmChar_t* s )
{
unsigned sn;
if( s==NULL || (sn = strlen(s))==0)
return s;
cmChar_t* s0 = cmTextLastNonWhiteChar(s);
if(s0-s+1 < sn )
s[s0-s+1] = 0;
return s;
}
cmChar_t* cmTextTrim( cmChar_t* s)
{
cmTextTrimBegin(s);
cmTextTrimEnd(s);
return s;
}
cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn )
{ return cmVOC_Expand(s,strlen(s)+1,t,tn); }

View File

@ -161,6 +161,11 @@ extern "C" {
// Remove the last n characters from s by inserting a '\0' at s[ strlen(s)-n ].
void cmTextClip( cmChar_t* s, unsigned n );
// Trim white space from the begining/end/both of a string
cmChar_t* cmTextTrimBegin( cmChar_t* s );
cmChar_t* cmTextTrimEnd( cmChar_t* s );
cmChar_t* cmTextTrim( cmChar_t* );
// Expand s by copying all bytes past t to t+tn.
cmChar_t* cmTextExpandS( cmChar_t* s, const cmChar_t* t, unsigned tn );