cmText.h/c : Added cmTextNextRow(),cmTextMinIndent(),cmTextOutdent().
This commit is contained in:
parent
99ad71cddd
commit
e1a6257d74
88
cmText.c
88
cmText.c
@ -875,3 +875,91 @@ cmChar_t* cmTextEatLeadingSpace( cmChar_t* s )
|
||||
return s;
|
||||
}
|
||||
|
||||
cmChar_t* cmTextNextRow( cmChar_t* s )
|
||||
{
|
||||
if( s == NULL)
|
||||
return NULL;
|
||||
|
||||
for(; *s; ++s)
|
||||
if( *s == '\n' )
|
||||
{
|
||||
++s;
|
||||
return *s==0 ? NULL : s;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const cmChar_t* cmTextNextRowC( const cmChar_t* s )
|
||||
{ return cmTextNextRow((cmChar_t*)s); }
|
||||
|
||||
unsigned cmTextMinIndent( const cmChar_t* s )
|
||||
{
|
||||
// leadFl=true if at beginning of row
|
||||
bool leadFl = true;
|
||||
unsigned min_indent = INT_MAX;
|
||||
unsigned indent = 0;
|
||||
for(; *s; ++s)
|
||||
{
|
||||
if( leadFl )
|
||||
{
|
||||
if( isspace(*s) && *s!='\n' )
|
||||
indent += 1;
|
||||
else
|
||||
{
|
||||
if( indent < min_indent )
|
||||
min_indent = indent;
|
||||
|
||||
indent = 0;
|
||||
leadFl = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( *s == '\n' )
|
||||
leadFl = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return min_indent==INT_MAX ? 0 : min_indent;
|
||||
}
|
||||
|
||||
cmChar_t* cmTextOutdent( cmChar_t* s, unsigned outdent )
|
||||
{
|
||||
// leadFl=true if at beginning of row
|
||||
bool leadFl = true;
|
||||
unsigned indent = 0;
|
||||
cmChar_t* cs = s;
|
||||
cmChar_t* s0 = s;
|
||||
|
||||
for(; *cs; ++cs)
|
||||
{
|
||||
if( leadFl )
|
||||
{
|
||||
if( isspace(*cs) && *cs!='\n' )
|
||||
indent += 1;
|
||||
else
|
||||
{
|
||||
unsigned n = cmMin(outdent,indent);
|
||||
cmTextShrinkS(s,s0,n);
|
||||
cs -= n;
|
||||
|
||||
indent = 0;
|
||||
leadFl = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( *cs == '\n' )
|
||||
{
|
||||
leadFl = true;
|
||||
s0 = cs + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
14
cmText.h
14
cmText.h
@ -249,6 +249,20 @@ extern "C" {
|
||||
// character.
|
||||
cmChar_t* cmTextEatLeadingSpace( cmChar_t* s );
|
||||
|
||||
|
||||
// Return a pointer to the beginning of the next row
|
||||
// or NULL if there is no next row.
|
||||
cmChar_t* cmTextNextRow( cmChar_t* s );
|
||||
const cmChar_t* cmTextNextRowC( const cmChar_t* s );
|
||||
|
||||
// Return the minimum indent of all rows in s[].
|
||||
unsigned cmTextMinIndent( const cmChar_t* s );
|
||||
|
||||
// Outdent s[] by 'n'.
|
||||
// If a row is indented by less than 'n' then it is
|
||||
// then all leading white space is removed.
|
||||
cmChar_t* cmTextOutdent( cmChar_t* s, unsigned n );
|
||||
|
||||
//)
|
||||
//}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user