• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ NS_CStringGetData函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中NS_CStringGetData函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_CStringGetData函数的具体用法?C++ NS_CStringGetData怎么用?C++ NS_CStringGetData使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NS_CStringGetData函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
          }
      }
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:26,代码来源:TestMinStringAPI.cpp


示例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;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:26,代码来源:TestMinStringAPI.cpp


示例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);
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:31,代码来源:TestMinStringAPI.cpp


示例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;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:32,代码来源:TestMinStringAPI.cpp


示例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;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:58,代码来源:TestMinStringAPI.cpp


示例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;
}
开发者ID:mikeaich,项目名称:releases-mozilla-central,代码行数:13,代码来源:nsStringAPI.cpp


示例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;
}
开发者ID:fortunto2,项目名称:celtx,代码行数:13,代码来源:nsStringAPI.cpp


示例8: CopyUTF16toUTF8

const char *nsStringToUTF8(const nsAString &str) {
  const char *cStr;
  nsCString tmpStr;
  CopyUTF16toUTF8(str, tmpStr);
  NS_CStringGetData(tmpStr, &cStr);
  return strdup(cStr);
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:7,代码来源:componentTools.cpp


示例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;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:29,代码来源:TestMinStringAPI.cpp


示例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;
}
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:27,代码来源:GStreamerFormatHelper.cpp


示例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;
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:19,代码来源:cluceneAccessor.cpp


示例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;
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:10,代码来源:nsStringAPI.cpp


示例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;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:12,代码来源:nsStringAPI.cpp


示例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);
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:13,代码来源:componentTools.cpp


示例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
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:23,代码来源:nsVoidArray.cpp


示例16: test_compress_ws

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;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:14,代码来源:TestMinStringAPI.cpp


示例17: NS_CStringGetData

bool MediaPluginHost::FindDecoder(const nsACString& aMimeType, const char* const** aCodecs)
{
  const char *chars;
  size_t len = NS_CStringGetData(aMimeType, &chars, nullptr);
  for (size_t n = 0; n < mPlugins.Length(); ++n) {
    Manifest *plugin = mPlugins[n];
    const char* const *codecs;
    if (plugin->CanDecode(chars, len, &codecs)) {
      if (aCodecs)
        *aCodecs = codecs;
      return true;
    }
  }
  return false;
}
开发者ID:alessandrod,项目名称:mozilla-central,代码行数:15,代码来源:MediaPluginHost.cpp


示例18: test_depend

static bool test_depend()
  {
    static const char kData[] = "hello world";

    nsCStringContainer s;
    NS_ENSURE_SUCCESS(
        NS_CStringContainerInit2(s, kData, sizeof(kData)-1,
                                 NS_CSTRING_CONTAINER_INIT_DEPEND),
        false);

    const char *sd;
    NS_CStringGetData(s, &sd);

    bool rv = (sd == kData);
    NS_CStringContainerFinish(s);
    return rv;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:17,代码来源:TestMinStringAPI.cpp


示例19: test_depend_sub

static bool test_depend_sub()
  {
    static const char kData[] = "hello world";

    nsCStringContainer s;
    NS_ENSURE_SUCCESS(
        NS_CStringContainerInit2(s, kData, sizeof(kData)-1,
                                 NS_CSTRING_CONTAINER_INIT_DEPEND |
                                 NS_CSTRING_CONTAINER_INIT_SUBSTRING),
        false);

    bool terminated;
    const char *sd;
    uint32_t len = NS_CStringGetData(s, &sd, &terminated);

    bool rv = (sd == kData && len == sizeof(kData)-1 && !terminated);
    NS_CStringContainerFinish(s);
    return rv;
  }
开发者ID:Lynart,项目名称:mozilla-central,代码行数:19,代码来源:TestMinStringAPI.cpp



注:本文中的NS_CStringGetData函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NS_ConvertASCIItoUTF16函数代码示例发布时间:2022-05-30
下一篇:
C++ NS_Alloc函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap