NS_CStringContainerInit2 编辑

« XPCOM API Reference

Summary

The NS_CStringContainerInit2 function initializes a nsCStringContainer instance for use as a nsACString.

#include "nsStringAPI.h"

nsresult NS_CStringContainerInit2(
  nsCStringContainer& aContainer,
  const char* aData = nsnull,
  PRUint32 aDataLength = PR_UINT32_MAX,
  PRUint32 aFlags = 0
);

Parameters

aContainer
[in] The nsCStringContainer instance to initialize.
aData
[in] An array of characters used to initialize the string object. This parameter may be null.
aDataLength
[in] An optional parameter that specifies the length of the array pointed to by aData. Pass PR_UINT32_MAX to indicate that aData's length may be determined by scanning the string for a terminating null. If aData is null, then this parameter is ignored.
aFlags
[in] A bit-field that modifies how the string object is initialized. If this value is zero, then the array referenced by aData (if any) will be copied. Flag values are defined below.

Flag Values

The aFlags parameter is a bit-wise combination of the following values:

NS_CSTRING_CONTAINER_INIT_DEPEND
Data passed into NS_CStringContainerInit2 is not copied. Instead, the string references the passed in data pointer directly. The caller must ensure that the data is valid for the lifetime of the string container. This flag should not be combined with NS_CSTRING_CONTAINER_INIT_ADOPT.
NS_CSTRING_CONTAINER_INIT_ADOPT
Data passed into NS_CStringContainerInit2 is not copied. Instead, the string takes ownership over the data pointer. The caller must have allocated the data array using the XPCOM memory allocator. This flag should not be combined with NS_CSTRING_CONTAINER_INIT_DEPEND.
NS_CSTRING_CONTAINER_INIT_SUBSTRING
Data passed into NS_CStringContainerInit2 is a substring that is not null-terminated.

Return Values

The NS_CStringContainerInit function returns NS_OK if successful. Otherwise, it returns an error code.

Remarks

After a nsCStringContainer object has been initialized via NS_CStringContainerInit2, it may be used as an ordinary nsACString object. When the string object is no longer needed, it should be passed to NS_CStringContainerFinish to free any extra memory that the string object may have allocated.

It is generally better to use one of the helper classes, such as nsCString, instead of coding directly to NS_CStringContainerInit2 because those classes take care of cleaning up the string object when it goes out of scope.

When NS_CStringContainerInit2 is told to copy aData, the copy it creates is null-terminated. This is significant as it allows the programmer to be certain that NS_CStringGetData will return a null-terminated character array.

The NS_CStringContainerInit function is equivalent to calling NS_CStringContainerInit with aData=nsnull and aFlags=0.

History

This function was finalized for Mozilla 1.8. See bug 264274 for details.

See Also

NS_CStringContainerInit, NS_CStringContainerFinish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:55 次

字数:5528

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文