Sfoglia il codice sorgente

cmText.h/c : Added cmTextSysIsStored() and cmTsIsStored().

master
kpl 11 anni fa
parent
commit
f9f9873eaf
2 ha cambiato i file con 29 aggiunte e 0 eliminazioni
  1. 22
    0
      cmText.c
  2. 7
    0
      cmText.h

+ 22
- 0
cmText.c Vedi File

@@ -148,6 +148,12 @@ void                cmTextSysFreeStr( cmTextSysH_t h, const cmChar_t* s )
148 148
   cmLhFree(p->lhH,(cmChar_t*)s);
149 149
 }
150 150
 
151
+bool  cmTextSysIsStored(cmTextSysH_t h, const cmChar_t* s )
152
+{ 
153
+  cmTextSys_t* p = _cmTextSysHandleToPtr(h);  
154
+  return cmLHeapIsPtrInHeap(p->lhH,s);
155
+}
156
+
151 157
 
152 158
   //
153 159
   // Global interface
@@ -203,6 +209,8 @@ cmChar_t*     cmTsPrintf(  const cmChar_t* fmt, ... )
203 209
 void                cmTsFreeStr( const cmChar_t* s )
204 210
 { cmTextSysFreeStr(_cmTextSysGlobalH,s); }
205 211
 
212
+bool           cmTsIsStored( const cmChar_t* s )
213
+{ return cmTextSysIsStored(_cmTextSysGlobalH,s); }
206 214
 
207 215
 cmChar_t* cmTsVPrintfP( cmChar_t* s, const cmChar_t* fmt, va_list vl )
208 216
 {
@@ -615,6 +623,20 @@ bool cmTextIsEmpty( const cmChar_t* s )
615 623
 bool cmTextIsNotEmpty( const cmChar_t* s )
616 624
 { return !cmTextIsEmpty(s); }
617 625
 
626
+int cmTextCmp( const cmChar_t* s0, const cmChar_t* s1 )
627
+{
628
+  if( s0 == NULL && s1 == NULL )
629
+    return 0;
630
+
631
+  if( s0 == NULL || s1 == NULL )
632
+  {
633
+    if( s0 == NULL )
634
+      return -1;
635
+    return 1;
636
+  }
637
+
638
+  return strcmp(s0,s1);
639
+}
618 640
 
619 641
 cmChar_t* cmTextLine( cmChar_t* s, unsigned line )
620 642
 {

+ 7
- 0
cmText.h Vedi File

@@ -52,6 +52,8 @@ extern "C" {
52 52
   cmChar_t*     cmTextSysVPrintf( cmTextSysH_t h, const cmChar_t* fmt, va_list vl );
53 53
   cmChar_t*     cmTextSysPrintf(  cmTextSysH_t h, const cmChar_t* fmt, ... );
54 54
   void          cmTextSysFreeStr( cmTextSysH_t h, const cmChar_t* s );
55
+  // Return true if 's' is stored in the text systems internal heap,
56
+  bool          cmTextSysIsStored(cmTextSysH_t h, const cmChar_t* s );
55 57
 
56 58
   //
57 59
   // Global interface:
@@ -71,6 +73,7 @@ extern "C" {
71 73
   cmChar_t*     cmTsVPrintf( const cmChar_t* fmt, va_list vl );
72 74
   cmChar_t*     cmTsPrintf(  const cmChar_t* fmt, ... );
73 75
   void          cmTsFreeStr( const cmChar_t* s );
76
+  bool          cmTsIsStored(const cmChar_t* s );
74 77
 
75 78
   // Print a formatted string into s[].  s[] is reallocated as necessary to
76 79
   // hold the string.  s must be freed by the caller via cmMemFree().
@@ -196,6 +199,10 @@ extern "C" {
196 199
   bool cmTextIsEmpty( const cmChar_t* s );
197 200
   bool cmTextIsNotEmpty( const cmChar_t* s );
198 201
 
202
+  // Same as strcmp() but handles NULL.  Note that if both s0 and s1 are NULL
203
+  // then return is 0.
204
+  int cmTextCmp( const cmChar_t* s0, const cmChar_t* s1 );
205
+
199 206
   // Returns NULL if string contains fewer than lineIdx lines.
200 207
   // Note: first line == 1.
201 208
   cmChar_t* cmTextLine( cmChar_t* s, unsigned line );

Loading…
Annulla
Salva