StrBuf* _NewConstStrBuf(const char* StringConstant, size_t SizeOfStrConstant);
#define NewConstStrBuf(a) _NewConstStrBuf(a, sizeof(a))
void FreeStrBuf (StrBuf **FreeMe);
+char *SmashStrBuf (StrBuf **SmashMe);
void HFreeStrBuf (void *VFreeMe);
int FlushStrBuf(StrBuf *buf);
int FLUSHStrBuf(StrBuf *buf); /* expensive but doesn't leave content behind for others to find in case of errors */
*FreeMe = NULL;
}
+/**
+ * \brief flatten a Buffer to the Char * we return
+ * Its a double pointer, so it can NULL your pointer
+ * so fancy SIG11 appear instead of random results
+ * The Calle then owns the buffer and is responsible for freeing it.
+ * \param SmashMe Pointer Pointer to the buffer to release Buf from and free
+ * \return the pointer of the buffer; Callee owns the memory thereafter.
+ */
+char *SmashStrBuf (StrBuf **SmashMe)
+{
+ char *Ret;
+
+ if (*SmashMe == NULL)
+ return NULL;
+#ifdef SIZE_DEBUG
+ if (hFreeDbglog == -1){
+ pid_t pid = getpid();
+ char path [SIZ];
+ snprintf(path, SIZ, "/tmp/libcitadel_strbuf_realloc.log.%d", pid);
+ hFreeDbglog = open(path, O_APPEND|O_CREAT|O_WRONLY);
+ }
+ if ((*SmashMe)->nIncreases > 0)
+ {
+ char buf[SIZ * 3];
+ long n;
+ n = snprintf(buf, SIZ * 3, "S+|%ld|%ld|%ld|%s|%s|\n",
+ (*SmashMe)->nIncreases,
+ (*SmashMe)->BufUsed,
+ (*SmashMe)->BufSize,
+ (*SmashMe)->bt,
+ (*SmashMe)->bt_lastinc);
+ n = write(hFreeDbglog, buf, n);
+ }
+ else
+ {
+ char buf[128];
+ long n;
+ n = snprintf(buf, 128, "S_|0|%ld%ld|\n",
+ (*SmashMe)->BufUsed,
+ (*SmashMe)->BufSize);
+ n = write(hFreeDbglog, buf, n);
+ }
+#endif
+ Ret = (*SmashMe)->buf;
+ free(*SmashMe);
+ *SmashMe = NULL;
+ return Ret;
+}
+
/**
* \brief Release the buffer
* If you want put your StrBuf into a Hash, use this as Destructor.
FreeStrBuf(&Buf);
}
+static void TestNextTokenizer_Sequence(void)
+{
+ StrBuf *Buf;
+ char *teststring = "40:24524,24662,24673,27869:27935,28393,28426,31247:31258,31731,31749,31761,31778,31782,31801:31803,31813,31904,31915,33708,33935,34619,34672,34720:34723,34766,34835,37594,38854,39235,39942,40030,40142,40520,40815,40907,41201,41578,41781,41954,42292,43110,43565,43801,43998,44180,44241,44295,44401,44561,44635,44798,44861,44946,45022,45137:45148,45166,45179,45707,47114,47141:47157,47194,47314,47349,47386,47489,47496,47534:47543,54460,54601,54637:54652";
+ Buf = NewStrBufPlain(teststring, -1);
+ NextTokenizerIterateBuf(Buf, 8);
+ FreeStrBuf(&Buf);
+}
/*
pTest = CU_add_test(pGroup, "testNextTokenizer_Empty", TestNextTokenizer_Empty);
pTest = CU_add_test(pGroup, "testNextTokenizer_TwoEmpty", TestNextTokenizer_TwoEmpty);
pTest = CU_add_test(pGroup, "testNextTokenizer_One", TestNextTokenizer_One);
+ pTest = CU_add_test(pGroup, "testNextTokenizer_Sequence", TestNextTokenizer_Sequence);
/*