|
@@ -875,3 +875,91 @@ cmChar_t* cmTextEatLeadingSpace( cmChar_t* s )
|
875
|
875
|
return s;
|
876
|
876
|
}
|
877
|
877
|
|
|
878
|
+cmChar_t* cmTextNextRow( cmChar_t* s )
|
|
879
|
+{
|
|
880
|
+ if( s == NULL)
|
|
881
|
+ return NULL;
|
|
882
|
+
|
|
883
|
+ for(; *s; ++s)
|
|
884
|
+ if( *s == '\n' )
|
|
885
|
+ {
|
|
886
|
+ ++s;
|
|
887
|
+ return *s==0 ? NULL : s;
|
|
888
|
+ }
|
|
889
|
+
|
|
890
|
+ return NULL;
|
|
891
|
+}
|
|
892
|
+
|
|
893
|
+const cmChar_t* cmTextNextRowC( const cmChar_t* s )
|
|
894
|
+{ return cmTextNextRow((cmChar_t*)s); }
|
|
895
|
+
|
|
896
|
+unsigned cmTextMinIndent( const cmChar_t* s )
|
|
897
|
+{
|
|
898
|
+ // leadFl=true if at beginning of row
|
|
899
|
+ bool leadFl = true;
|
|
900
|
+ unsigned min_indent = INT_MAX;
|
|
901
|
+ unsigned indent = 0;
|
|
902
|
+ for(; *s; ++s)
|
|
903
|
+ {
|
|
904
|
+ if( leadFl )
|
|
905
|
+ {
|
|
906
|
+ if( isspace(*s) && *s!='\n' )
|
|
907
|
+ indent += 1;
|
|
908
|
+ else
|
|
909
|
+ {
|
|
910
|
+ if( indent < min_indent )
|
|
911
|
+ min_indent = indent;
|
|
912
|
+
|
|
913
|
+ indent = 0;
|
|
914
|
+ leadFl = false;
|
|
915
|
+ }
|
|
916
|
+ }
|
|
917
|
+ else
|
|
918
|
+ {
|
|
919
|
+ if( *s == '\n' )
|
|
920
|
+ leadFl = true;
|
|
921
|
+ }
|
|
922
|
+
|
|
923
|
+ }
|
|
924
|
+
|
|
925
|
+ return min_indent==INT_MAX ? 0 : min_indent;
|
|
926
|
+}
|
|
927
|
+
|
|
928
|
+cmChar_t* cmTextOutdent( cmChar_t* s, unsigned outdent )
|
|
929
|
+{
|
|
930
|
+ // leadFl=true if at beginning of row
|
|
931
|
+ bool leadFl = true;
|
|
932
|
+ unsigned indent = 0;
|
|
933
|
+ cmChar_t* cs = s;
|
|
934
|
+ cmChar_t* s0 = s;
|
|
935
|
+
|
|
936
|
+ for(; *cs; ++cs)
|
|
937
|
+ {
|
|
938
|
+ if( leadFl )
|
|
939
|
+ {
|
|
940
|
+ if( isspace(*cs) && *cs!='\n' )
|
|
941
|
+ indent += 1;
|
|
942
|
+ else
|
|
943
|
+ {
|
|
944
|
+ unsigned n = cmMin(outdent,indent);
|
|
945
|
+ cmTextShrinkS(s,s0,n);
|
|
946
|
+ cs -= n;
|
|
947
|
+
|
|
948
|
+ indent = 0;
|
|
949
|
+ leadFl = false;
|
|
950
|
+ }
|
|
951
|
+ }
|
|
952
|
+ else
|
|
953
|
+ {
|
|
954
|
+ if( *cs == '\n' )
|
|
955
|
+ {
|
|
956
|
+ leadFl = true;
|
|
957
|
+ s0 = cs + 1;
|
|
958
|
+ }
|
|
959
|
+ }
|
|
960
|
+
|
|
961
|
+ }
|
|
962
|
+
|
|
963
|
+ return s;
|
|
964
|
+
|
|
965
|
+}
|