Просмотр исходного кода

cmText.h/c : Added cmTextLineCount().

master
Kevin Larke 8 лет назад
Родитель
Сommit
2945b1ac79
2 измененных файлов: 31 добавлений и 0 удалений
  1. 28
    0
      cmText.c
  2. 3
    0
      cmText.h

+ 28
- 0
cmText.c Просмотреть файл

798
 const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line )
798
 const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line )
799
 { return cmTextLine((cmChar_t*)s,line); }
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
 cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s )
830
 cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s )
803
 {
831
 {

+ 3
- 0
cmText.h Просмотреть файл

234
   cmChar_t* cmTextLine( cmChar_t* s, unsigned line );
234
   cmChar_t* cmTextLine( cmChar_t* s, unsigned line );
235
   const cmChar_t* cmTextLineC( const cmChar_t* s, unsigned line );
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
   // Reduce all consecutive white spaces to a single space.
240
   // Reduce all consecutive white spaces to a single space.
238
   cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s );
241
   cmChar_t* cmTextRemoveConsecutiveSpaces( cmChar_t* s );
239
 
242
 

Загрузка…
Отмена
Сохранить