From 2945b1ac795d54767b1dfbc0a09bfb6581192ca1 Mon Sep 17 00:00:00 2001 From: Kevin Larke Date: Sun, 17 Apr 2016 17:28:38 -0400 Subject: [PATCH] cmText.h/c : Added cmTextLineCount(). --- cmText.c | 28 ++++++++++++++++++++++++++++ cmText.h | 3 +++ 2 files changed, 31 insertions(+) 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 );