Browse Source

cmText.h/c : Added cmTextLineCount().

master
Kevin Larke 8 years ago
parent
commit
2945b1ac79
2 changed files with 31 additions and 0 deletions
  1. 28
    0
      cmText.c
  2. 3
    0
      cmText.h

+ 28
- 0
cmText.c View File

@@ -798,6 +798,34 @@ cmChar_t* cmTextLine( cmChar_t* s, unsigned line )
798 798
 const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line )
799 799
 { return cmTextLine((cmChar_t*)s,line); }
800 800
 
801
+unsigned cmTextLineCount( const cmChar_t* s )
802
+{
803
+  unsigned n = *s ? 1 : 0;
804
+  
805
+  while( *s )
806
+  {
807
+    s = cmTextEndOfLineC(s);
808
+
809
+    switch( *s )
810
+    {
811
+      case 0:
812
+        break;
813
+        
814
+      case '\n':
815
+        s += 1;
816
+        n += 1;
817
+        break;
818
+        
819
+      default:
820
+        { assert(0); }
821
+    }
822
+    
823
+  }
824
+
825
+  return n;
826
+  
827
+}
828
+
801 829
 
802 830
 cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s )
803 831
 {

+ 3
- 0
cmText.h View File

@@ -234,6 +234,9 @@ extern "C" {
234 234
   cmChar_t* cmTextLine( cmChar_t* s, unsigned line );
235 235
   const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line );
236 236
 
237
+  // Return the count of lines begining with s.
238
+  unsigned cmTextLineCount( const cmChar_t* s );
239
+  
237 240
   // Reduce all consecutive white spaces to a single space.
238 241
   cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s );
239 242
 

Loading…
Cancel
Save