cmText.h/c : Added cmTextTrimBegin(),cmTextTrimEnd() and cmTextTime().
This commit is contained in:
parent
5c36dfcf9a
commit
84782a1fa8
43
cmText.c
43
cmText.c
@ -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); }
|
||||
|
5
cmText.h
5
cmText.h
@ -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 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user