NS_CStringGetMutableData 编辑

« XPCOM API Reference

Summary

The NS_CStringGetMutableData function gives the caller write access to the string's internal buffer.

#include "nsStringAPI.h"

PRUint32 NS_CStringGetMutableData(
  nsACString& aString,
  PRUint32 aDataLength,
  char** aData
);

Parameters

aString
[in] A nsACString instance to modify.
aDataLength
[in] The number of characters to resize the string's internal buffer to or PR_UINT32_MAX to return the buffer as-is.
aData
[out] Upon return, if the function was successful, then *aData references the string's internal buffer.

Return Values

This function returns the number of characters contained in the string's internal buffer (excluding any null-terminator). This value will be zero if the function failed to resize its internal buffer to the size requested.

Remarks

This function provides mutable access to a string's internal buffer. It returns a pointer to the first element of an array of characters that may be modified in-place. The returned pointer remains valid until the string object is passed to some other string function.

This function does not necessarily null-terminate aString's internal buffer after resizing it. That behavior depends on the implementation of aString. If aString is a reference to a nsCStringContainer, then its data will be null-terminated by this function. The caller is not responsible for writing a null-terminator.

Example

// Convert any uppercase ASCII letters to lowercase
void ToLowerCase(nsCString &str)
{
  char *iter;
  PRUint32 len = NS_CStringGetMutableData(str, PR_UINT32_MAX, &iter);

  char *end = iter + len;
  while (iter != end) {
    char c = *iter;
    if (c >= 'A' && c <= 'Z')
      *iter = c + ('a' - 'A');
    ++iter;
  }
}

History

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

See Also

NS_CStringGetData

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

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

发布评论

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

词条统计

浏览:102 次

字数:3167

最后编辑:7 年前

编辑次数:0 次

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