static bool test_replace_driver(const char *strVal, const char *matchVal, const char *newVal, const char *finalVal) { nsCStringContainer a; NS_CStringContainerInit(a); NS_CStringSetData(a, strVal); nsCStringContainer b; NS_CStringContainerInit(b); NS_CStringSetData(b, matchVal); nsCStringContainer c; NS_CStringContainerInit(c); NS_CStringSetData(c, newVal); ReplaceSubstring(a, b, c); const char *data; NS_CStringGetData(a, &data); if (strcmp(data, finalVal) != 0) return false; NS_CStringContainerFinish(c); NS_CStringContainerFinish(b); NS_CStringContainerFinish(a); return true; }
static bool test_basic_1() { nsCStringContainer s; NS_CStringContainerInit(s); const char *ptr; uint32_t len; char *clone; NS_CStringGetData(s, &ptr); if (ptr == nullptr || *ptr != '\0') { NS_ERROR("unexpected result"); return false; } NS_CStringSetData(s, kAsciiData, PR_UINT32_MAX); len = NS_CStringGetData(s, &ptr); if (ptr == nullptr || strcmp(ptr, kAsciiData) != 0) { NS_ERROR("unexpected result"); return false; } if (len != sizeof(kAsciiData)-1) { NS_ERROR("unexpected result"); return false; } clone = NS_CStringCloneData(s); if (ptr == nullptr || strcmp(ptr, kAsciiData) != 0) { NS_ERROR("unexpected result"); return false; } NS_Free(clone); nsCStringContainer temp; NS_CStringContainerInit(temp); NS_CStringCopy(temp, s); len = NS_CStringGetData(temp, &ptr); if (ptr == nullptr || strcmp(ptr, kAsciiData) != 0) { NS_ERROR("unexpected result"); return false; } if (len != sizeof(kAsciiData)-1) { NS_ERROR("unexpected result"); return false; } NS_CStringContainerFinish(temp); NS_CStringContainerFinish(s); return true; }
static bool test_append() { nsCStringContainer s; NS_CStringContainerInit(s); NS_CStringSetData(s, "foo"); NS_CStringAppendData(s, "bar"); NS_CStringContainerFinish(s); return true; }
static bool test_compress_ws() { nsCStringContainer s; NS_CStringContainerInit(s); NS_CStringSetData(s, " \thello world\r \n"); CompressWhitespace(s); const char *d; NS_CStringGetData(s, &d); bool rv = !strcmp(d, "hello world"); if (!rv) printf("=> \"%s\"\n", d); NS_CStringContainerFinish(s); return rv; }
static void GetStringValue(nsACString& aValue) { NS_CStringSetData(aValue, "GetValue"); }
void nsACString_Init(nsACString *str, const char *data) { NS_CStringContainerInit(str); if(data) NS_CStringSetData(str, data, PR_UINT32_MAX); }
gluezilla_CStringSetData (nsACString &aStr, const char *aBuf, PRUint32 aCount) { return NS_CStringSetData (aStr, aBuf, aCount); }