本文整理汇总了C++中NS_CStringGetData函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_CStringGetData函数的具体用法?C++ NS_CStringGetData怎么用?C++ NS_CStringGetData使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_CStringGetData函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReplaceSubstring
// Replace all occurrences of |matchVal| with |newVal|
static void ReplaceSubstring( nsACString& str,
const nsACString& matchVal,
const nsACString& newVal )
{
const char* sp, *mp, *np;
uint32_t sl, ml, nl;
sl = NS_CStringGetData(str, &sp);
ml = NS_CStringGetData(matchVal, &mp);
nl = NS_CStringGetData(newVal, &np);
for (const char* iter = sp; iter <= sp + sl - ml; ++iter)
{
if (memcmp(iter, mp, ml) == 0)
{
uint32_t offset = iter - sp;
NS_CStringSetDataRange(str, offset, ml, np, nl);
sl = NS_CStringGetData(str, &sp);
iter = sp + offset + nl - 1;
}
}
}
示例2: test_convert
static bool test_convert()
{
nsStringContainer s;
NS_StringContainerInit(s);
NS_StringSetData(s, kUnicodeData, sizeof(kUnicodeData)/2 - 1);
nsCStringContainer temp;
NS_CStringContainerInit(temp);
const char *data;
NS_UTF16ToCString(s, NS_CSTRING_ENCODING_ASCII, temp);
NS_CStringGetData(temp, &data);
if (strcmp(data, kAsciiData) != 0)
return false;
NS_UTF16ToCString(s, NS_CSTRING_ENCODING_UTF8, temp);
NS_CStringGetData(temp, &data);
if (strcmp(data, kAsciiData) != 0)
return false;
NS_CStringContainerFinish(temp);
NS_StringContainerFinish(s);
return true;
}
示例3: CompressWhitespace
static void
CompressWhitespace(nsACString &str)
{
const char *p;
int32_t i, len = (int32_t) NS_CStringGetData(str, &p);
// trim leading whitespace
for (i=0; i<len; ++i)
{
if (!strchr(kWhitespace, (char) p[i]))
break;
}
if (i>0)
{
NS_CStringCutData(str, 0, i);
len = (int32_t) NS_CStringGetData(str, &p);
}
// trim trailing whitespace
for (i=len-1; i>=0; --i)
{
if (!strchr(kWhitespace, (char) p[i]))
break;
}
if (++i < len)
NS_CStringCutData(str, i, len - i);
}
示例4: test_mutation
static bool test_mutation()
{
nsCStringContainer s;
NS_CStringContainerInit(s);
const char kText[] = "Every good boy does fine.";
char *buf;
uint32_t len = NS_CStringGetMutableData(s, sizeof(kText) - 1, &buf);
if (!buf || len != sizeof(kText) - 1)
return false;
memcpy(buf, kText, sizeof(kText));
const char *data;
NS_CStringGetData(s, &data);
if (strcmp(data, kText) != 0)
return false;
uint32_t newLen = len + 1;
len = NS_CStringGetMutableData(s, newLen, &buf);
if (!buf || len != newLen)
return false;
buf[len - 1] = '.';
NS_CStringGetData(s, &data);
if (strncmp(data, kText, len - 1) != 0 || data[len - 1] != '.')
return false;
NS_CStringContainerFinish(s);
return true;
}
示例5: test_basic_1
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;
}
示例6: NS_CStringGetData
bool
nsACString::Equals(const self_type &other, ComparatorFunc c) const
{
const char_type *cself;
const char_type *cother;
uint32_t selflen = NS_CStringGetData(*this, &cself);
uint32_t otherlen = NS_CStringGetData(other, &cother);
if (selflen != otherlen)
return false;
return c(cself, cother, selflen) == 0;
}
示例7: NS_CStringGetData
PRBool
nsACString::Equals(const self_type &other, ComparatorFunc c) const
{
const char_type *cself;
const char_type *cother;
PRUint32 selflen = NS_CStringGetData(*this, &cself);
PRUint32 otherlen = NS_CStringGetData(other, &cother);
if (selflen != otherlen)
return PR_FALSE;
return c(cself, cother, selflen) == 0;
}
示例8: CopyUTF16toUTF8
const char *nsStringToUTF8(const nsAString &str) {
const char *cStr;
nsCString tmpStr;
CopyUTF16toUTF8(str, tmpStr);
NS_CStringGetData(tmpStr, &cStr);
return strdup(cStr);
}
示例9: test_replace_driver
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;
}
示例10: NS_CStringGetData
bool GStreamerFormatHelper::CanHandleMediaType(const nsACString& aMIMEType,
const nsAString* aCodecs) {
if (!sLoadOK) {
return false;
}
const char *type;
NS_CStringGetData(aMIMEType, &type, nullptr);
GstCaps *caps;
if (aCodecs && !aCodecs->IsEmpty()) {
caps = ConvertFormatsToCaps(type, aCodecs);
} else {
// Get a minimal set of codec caps for this MIME type we should support so
// that we don't overreport MIME types we are able to play.
caps = GetDefaultCapsFromMIMEType(type);
}
if (!caps) {
return false;
}
bool ret = HaveElementsToProcessCaps(caps);
gst_caps_unref(caps);
return ret;
}
示例11: NS_CStringGetData
/* Open Clucene readable database */
NS_IMETHODIMP CluceneAccessor::OpenReadableDatabase(const nsACString &unixDirectory, const nsACString &winDirectory, mozbool *retVal) {
*retVal = PR_TRUE;
const char *directoryPath;
#ifdef _WIN32
NS_CStringGetData(winDirectory, &directoryPath);
#else
NS_CStringGetData(unixDirectory, &directoryPath);
#endif
try {
this->searcher = new kiwix::CluceneSearcher(directoryPath);
} catch (...) {
*retVal = PR_FALSE;
}
return NS_OK;
}
示例12: NS_CStringGetData
uint32_t
nsACString::BeginReading(const char_type** aBegin, const char_type** aEnd) const
{
uint32_t len = NS_CStringGetData(*this, aBegin);
if (aEnd) {
*aEnd = *aBegin + len;
}
return len;
}
示例13: NS_CStringGetData
bool
nsACString::Equals(const char_type *other, ComparatorFunc c) const
{
const char_type *cself;
PRUint32 selflen = NS_CStringGetData(*this, &cself);
PRUint32 otherlen = strlen(other);
if (selflen != otherlen)
return false;
return c(cself, other, selflen) == 0;
}
示例14: LossyCopyUTF16toASCII
const char *nsStringToCString(const nsAString &str) {
const char *cStr;
nsCString tmpStr;
#ifdef _WIN32
LossyCopyUTF16toASCII(str, tmpStr);
#else
CopyUTF16toUTF8(str, tmpStr);
#endif
NS_CStringGetData(tmpStr, &cStr);
return strdup(cStr);
}
示例15: CompareCString
static int
CompareCString(const nsCString* aCString1, const nsCString* aCString2, void*)
{
#ifdef MOZILLA_INTERNAL_API
return Compare(*aCString1, *aCString2);
#else
const char* s1;
const char* s2;
PRUint32 len1 = NS_CStringGetData(*aCString1, &s1);
PRUint32 len2 = NS_CStringGetData(*aCString2, &s2);
int r = memcmp(s1, s2, PR_MIN(len1, len2));
if (r)
return r;
if (len1 < len2)
return -1;
if (len1 > len2)
return 1;
return 0;
#endif
}