diff --git a/cmText.c b/cmText.c index 2448d98..d9e9106 100644 --- a/cmText.c +++ b/cmText.c @@ -798,6 +798,34 @@ cmChar_t* cmTextLine( cmChar_t* s, unsigned line ) const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line ) { return cmTextLine((cmChar_t*)s,line); } +unsigned cmTextLineCount( const cmChar_t* s ) +{ + unsigned n = *s ? 1 : 0; + + while( *s ) + { + s = cmTextEndOfLineC(s); + + switch( *s ) + { + case 0: + break; + + case '\n': + s += 1; + n += 1; + break; + + default: + { assert(0); } + } + + } + + return n; + +} + cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s ) { diff --git a/cmText.h b/cmText.h index 58b3be0..aaa52cd 100644 --- a/cmText.h +++ b/cmText.h @@ -234,6 +234,9 @@ extern "C" { cmChar_t* cmTextLine( cmChar_t* s, unsigned line ); const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line ); + // Return the count of lines begining with s. + unsigned cmTextLineCount( const cmChar_t* s ); + // Reduce all consecutive white spaces to a single space. cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s );